UNPKG

stream-chat

Version:

JS SDK for the Stream Chat API

81 lines (80 loc) 3.27 kB
import type { StreamChat } from '../client'; import { Channel } from '../channel'; import { Thread } from '../thread'; import type { EventAPIResponse, MarkDeliveredOptions, MarkReadOptions } from '../types'; type MessageId = string; type ChannelThreadCompositeId = string; export type AnnounceDeliveryOptions = Omit<MarkDeliveredOptions, 'latest_delivered_messages'>; export type MessageDeliveryReporterOptions = { client: StreamChat; }; export declare class MessageDeliveryReporter { protected client: StreamChat; protected deliveryReportCandidates: Map<ChannelThreadCompositeId, MessageId>; protected nextDeliveryReportCandidates: Map<ChannelThreadCompositeId, MessageId>; protected markDeliveredRequestPromise: Promise<EventAPIResponse | void> | null; protected markDeliveredTimeout: ReturnType<typeof setTimeout> | null; protected requestTimeoutMs: number; protected requestRetryCount: number; constructor({ client }: MessageDeliveryReporterOptions); private get markDeliveredRequestInFlight(); private get hasTimer(); private get hasDeliveryCandidates(); private get canExecuteRequest(); private static hasPermissionToReportDeliveryFor; private increaseBackOff; private resetBackOff; /** * Build latest_delivered_messages payload from an arbitrary buffer (deliveryReportCandidates / nextDeliveryReportCandidates) */ private confirmationsFrom; private confirmationsFromDeliveryReportCandidates; /** * Generate candidate key for storing in the candidates buffer * @param collection * @private */ private candidateKeyFor; /** * Retrieve the reference to the latest message in the state that is nor read neither reported as delivered * @param collection */ private getNextDeliveryReportCandidate; /** * Updates the delivery candidates buffer with the latest delivery candidates * @param collection */ private trackDeliveredCandidate; /** * Removes candidate from the delivery report buffer * @param collection * @private */ private removeCandidateFor; /** * Records the latest message delivered for Channel or Thread instances and schedules the next report * if not already scheduled and candidates exist. * Should be used for WS handling (message.new) as well as for ingesting HTTP channel query results. * @param collections */ syncDeliveredCandidates(collections: (Channel | Thread)[]): void; /** * Fires delivery announcement request followed by immediate delivery candidate buffer reset. * @param options */ announceDelivery: (options?: AnnounceDeliveryOptions) => void; announceDeliveryBuffered: (options?: AnnounceDeliveryOptions) => void; /** * Delegates the mark-read call to the Channel or Thread instance * @param collection * @param options */ markRead: (collection: Channel | Thread, options?: MarkReadOptions) => Promise<EventAPIResponse | null>; /** * Throttles the MessageDeliveryReporter.markRead call * @param collection * @param options */ throttledMarkRead: (collection: Channel | Thread, options?: MarkReadOptions | undefined) => void; } export {};