diff --git a/packages/client/src/client.ts b/packages/client/src/client.ts index 2e01bc0e..7ee579d5 100644 --- a/packages/client/src/client.ts +++ b/packages/client/src/client.ts @@ -2986,6 +2986,7 @@ export class TelegramClient extends BaseTelegramClient { protected _oldDate: number protected _oldSeq: number protected _selfChanged: boolean + protected _catchUpChannels: boolean protected _cpts: Record protected _cptsMod: Record constructor(opts: BaseTelegramClient.Options) { diff --git a/packages/client/src/methods/auth/start.ts b/packages/client/src/methods/auth/start.ts index 0c5a503e..fed1f0fd 100644 --- a/packages/client/src/methods/auth/start.ts +++ b/packages/client/src/methods/auth/start.ts @@ -133,6 +133,8 @@ export async function start( // user is already authorized if (!this._disableUpdates) { + this._catchUpChannels = !!params.catchUp + if (params.catchUp) { await this.catchUp() } else { diff --git a/packages/client/src/methods/updates.ts b/packages/client/src/methods/updates.ts index bdcb27cb..b34fd9ec 100644 --- a/packages/client/src/methods/updates.ts +++ b/packages/client/src/methods/updates.ts @@ -37,6 +37,10 @@ interface UpdatesState { _oldSeq: number _selfChanged: boolean + // whether to catch up channels from the locally stored pts + // usually set in start() method based on `catchUp` param + _catchUpChannels: boolean + _cpts: Record _cptsMod: Record } @@ -655,20 +659,24 @@ export function _handleUpdate( 'ptsCount' in upd ? upd.ptsCount : undefined if (pts !== undefined && ptsCount !== undefined) { - let nextLocalPts + let nextLocalPts: number | null = null if (channelId === undefined) nextLocalPts = this._pts + ptsCount else if (channelId in this._cpts) nextLocalPts = this._cpts[channelId] + ptsCount - else { + else if (this._catchUpChannels) { + // only load stored channel pts in case + // the user has enabled catching up. + // not loading stored pts effectively disables + // catching up, but doesn't interfere with further + // update gaps + const saved = await this.storage.getChannelPts( channelId ) if (saved) { this._cpts[channelId] = saved nextLocalPts = saved + ptsCount - } else { - nextLocalPts = null } }