fix(client): disable catch up by default, also save storage after catching up
This commit is contained in:
parent
a4f6c42bf5
commit
b4a26c6f5b
2 changed files with 22 additions and 12 deletions
|
@ -111,29 +111,40 @@ export async function start(
|
|||
|
||||
/**
|
||||
* Whether to "catch up" (load missed updates).
|
||||
* Note: you should register your handlers
|
||||
* before calling `start()`
|
||||
* Only applicable if the saved session already
|
||||
* contained authorization and updates state.
|
||||
*
|
||||
* Defaults to true.
|
||||
* Note: you should register your handlers
|
||||
* before calling `start()`, otherwise they will
|
||||
* not be called.
|
||||
*
|
||||
* Note: In case the storage was not properly
|
||||
* closed the last time, "catching up" might
|
||||
* result in duplicate updates.
|
||||
*
|
||||
* Defaults to `false`.
|
||||
*/
|
||||
catchUp?: boolean
|
||||
}
|
||||
): Promise<User> {
|
||||
if (!params.phone && !params.botToken)
|
||||
throw new MtCuteArgumentError(
|
||||
'Neither phone nor bot token were provided'
|
||||
)
|
||||
|
||||
try {
|
||||
const me = await this.getMe()
|
||||
|
||||
// user is already authorized
|
||||
if (params.catchUp !== false && !this._disableUpdates)
|
||||
|
||||
if (!this._disableUpdates && params.catchUp)
|
||||
await this.catchUp()
|
||||
|
||||
return me
|
||||
} catch (e) {
|
||||
if (!(e instanceof AuthKeyUnregisteredError)) throw e
|
||||
}
|
||||
|
||||
if (!params.phone && !params.botToken)
|
||||
throw new MtCuteArgumentError(
|
||||
'Neither phone nor bot token were provided'
|
||||
)
|
||||
|
||||
let phone = params.phone ? await resolveMaybeDynamic(params.phone) : null
|
||||
if (phone) {
|
||||
phone = normalizePhoneNumber(phone)
|
||||
|
@ -149,9 +160,7 @@ export async function start(
|
|||
'Either bot token or phone number must be provided'
|
||||
)
|
||||
|
||||
if (params.catchUp !== false) await this.catchUp()
|
||||
|
||||
return this.signInBot(botToken)
|
||||
return await this.signInBot(botToken)
|
||||
}
|
||||
|
||||
let sentCode = await this.sendCode(phone)
|
||||
|
|
|
@ -767,4 +767,5 @@ export function catchUp(this: TelegramClient): Promise<void> {
|
|||
.then(() => _loadDifference.call(this))
|
||||
.catch((err) => this._emitError(err))
|
||||
.then(() => this._updLock.release())
|
||||
.then(() => this._saveStorage())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue