import { Logger } from '../../utils/index.js'; import { BaseTelegramClient } from '../base.js'; import { PendingUpdate, PendingUpdateContainer, UpdatesManagerParams } from './types.js'; import { AsyncLock, ConditionVariable, Deque, LruSet, timers } from '@fuman/utils'; import { tl } from '../../tl/index.js'; import { EarlyTimer } from '../../utils/early-timer.js'; import { SortedArray } from '../../utils/sorted-array.js'; import { PeersIndex } from '../types/peers/peers-index.js'; export declare class UpdatesManager { readonly client: BaseTelegramClient; readonly params: UpdatesManagerParams; updatesLoopActive: boolean; updatesLoopCv: ConditionVariable; postponedTimer: EarlyTimer; hasTimedoutPostponed: boolean; pendingUpdateContainers: SortedArray; pendingPtsUpdates: SortedArray; pendingPtsUpdatesPostponed: SortedArray; pendingQtsUpdates: SortedArray; pendingQtsUpdatesPostponed: SortedArray; pendingUnorderedUpdates: Deque; noDispatchEnabled: boolean; noDispatchMsg: Map>; noDispatchPts: Map>; noDispatchQts: Set; _recentlyDispatchedCommonMsgs: LruSet; lock: AsyncLock; pts?: number; qts?: number; date?: number; seq?: number; oldPts?: number; oldQts?: number; oldDate?: number; oldSeq?: number; catchingUp: boolean; catchUpOnStart: boolean; cpts: Map; cptsMod: Map; channelDiffTimeouts: Map; channelsOpened: Map; log: Logger; private _onCatchingUp; private _channelPtsLimit; keepAliveInterval?: timers.Interval; constructor(client: BaseTelegramClient, params?: UpdatesManagerParams); onCatchingUp(handler: (catchingUp: boolean) => void): void; destroy(): void; notifyLoggedIn(): void; notifyLoggedOut(): void; prepare(): Promise; private _onKeepAlive; /** * Start updates loop. * * You must first call {@link enableUpdatesProcessing} to use this method. * * It is recommended to use this method in callback to {@link start}, * or otherwise make sure the user is logged in. * * > **Note**: If you are using {@link UpdatesManagerParams.catchUp} option, * > catching up will be done in background, you can't await it. * > Instead, listen for the `updating` and `connected` connection state events. */ startLoop(): Promise; /** * **ADVANCED** * * Manually stop updates loop. * Usually done automatically when stopping the client with {@link close} */ stopLoop(): void; /** * Catch up with the server by loading missed updates. *. * > **Note**: In case the storage was not properly * > closed the last time, "catching up" might * > result in duplicate updates. */ catchUp(): void; handleClientUpdate(update: tl.TypeUpdates, noDispatch?: boolean): void; handleUpdate(update: tl.TypeUpdates): void; /** * **ADVANCED** * * Notify the updates manager that some channel was "opened". * Channel difference for "opened" channels will be fetched on a regular basis. * This is a low-level method, prefer using {@link openChat} instead. * * Channel must be resolve-able with `resolvePeer` method (i.e. be in cache); * base chat PTS must either be passed (e.g. from {@link Dialog}), or cached in storage. * * @param channelId Bare ID of the channel * @param pts PTS of the channel, if known (e.g. from {@link Dialog}) * @returns `true` if the channel was opened for the first time, `false` if it is already opened */ notifyChannelOpened(channelId: number, pts?: number): boolean; /** * **ADVANCED** * * Notify the updates manager that some channel was "closed". * Basically the opposite of {@link notifyChannelOpened}. * This is a low-level method, prefer using {@link closeChat} instead. * * @param channelId Bare channel ID * @returns `true` if the chat was closed for the last time, `false` otherwise */ notifyChannelClosed(channelId: number): boolean; _fetchUpdatesState(): Promise; _loadUpdatesStorage(): Promise; _saveUpdatesStorage(save?: boolean): Promise; _addToNoDispatchIndex(updates?: tl.TypeUpdates): void; _fetchMissingPeers(upd: tl.TypeUpdate, peers: PeersIndex, fromDifference?: boolean): Promise>; _storeMessageReferences(msg: tl.TypeMessage): Promise; _fetchChannelDifference(channelId: number, fallbackPts?: number): Promise; _fetchChannelDifferenceLater(requestedDiff: Map>, channelId: number, fallbackPts?: number): void; _fetchChannelDifferenceViaUpdate(channelId: number, pts?: number): void; _fetchDifference(requestedDiff: Map>): Promise; _fetchDifferenceLater(requestedDiff: Map>): void; _onUpdate(pending: PendingUpdate, requestedDiff: Map>, postponed?: boolean, unordered?: boolean): Promise; _loop(): Promise; }