fix(client): do not catch up channels if disabled
This commit is contained in:
parent
78bdc5fb01
commit
4599272c7c
3 changed files with 15 additions and 4 deletions
|
@ -2986,6 +2986,7 @@ export class TelegramClient extends BaseTelegramClient {
|
||||||
protected _oldDate: number
|
protected _oldDate: number
|
||||||
protected _oldSeq: number
|
protected _oldSeq: number
|
||||||
protected _selfChanged: boolean
|
protected _selfChanged: boolean
|
||||||
|
protected _catchUpChannels: boolean
|
||||||
protected _cpts: Record<number, number>
|
protected _cpts: Record<number, number>
|
||||||
protected _cptsMod: Record<number, number>
|
protected _cptsMod: Record<number, number>
|
||||||
constructor(opts: BaseTelegramClient.Options) {
|
constructor(opts: BaseTelegramClient.Options) {
|
||||||
|
|
|
@ -133,6 +133,8 @@ export async function start(
|
||||||
// user is already authorized
|
// user is already authorized
|
||||||
|
|
||||||
if (!this._disableUpdates) {
|
if (!this._disableUpdates) {
|
||||||
|
this._catchUpChannels = !!params.catchUp
|
||||||
|
|
||||||
if (params.catchUp) {
|
if (params.catchUp) {
|
||||||
await this.catchUp()
|
await this.catchUp()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -37,6 +37,10 @@ interface UpdatesState {
|
||||||
_oldSeq: number
|
_oldSeq: number
|
||||||
_selfChanged: boolean
|
_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<number, number>
|
_cpts: Record<number, number>
|
||||||
_cptsMod: Record<number, number>
|
_cptsMod: Record<number, number>
|
||||||
}
|
}
|
||||||
|
@ -655,20 +659,24 @@ export function _handleUpdate(
|
||||||
'ptsCount' in upd ? upd.ptsCount : undefined
|
'ptsCount' in upd ? upd.ptsCount : undefined
|
||||||
|
|
||||||
if (pts !== undefined && ptsCount !== undefined) {
|
if (pts !== undefined && ptsCount !== undefined) {
|
||||||
let nextLocalPts
|
let nextLocalPts: number | null = null
|
||||||
if (channelId === undefined)
|
if (channelId === undefined)
|
||||||
nextLocalPts = this._pts + ptsCount
|
nextLocalPts = this._pts + ptsCount
|
||||||
else if (channelId in this._cpts)
|
else if (channelId in this._cpts)
|
||||||
nextLocalPts = this._cpts[channelId] + ptsCount
|
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(
|
const saved = await this.storage.getChannelPts(
|
||||||
channelId
|
channelId
|
||||||
)
|
)
|
||||||
if (saved) {
|
if (saved) {
|
||||||
this._cpts[channelId] = saved
|
this._cpts[channelId] = saved
|
||||||
nextLocalPts = saved + ptsCount
|
nextLocalPts = saved + ptsCount
|
||||||
} else {
|
|
||||||
nextLocalPts = null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue