fix(core): only switch dc for primary connection

This commit is contained in:
teidesu 2021-05-05 18:24:16 +03:00
parent 00c308dca7
commit d841188149
2 changed files with 11 additions and 11 deletions

View file

@ -177,7 +177,7 @@ export class CallbackQuery {
* Answer this query
*/
async answer(
params: Parameters<TelegramClient['answerCallbackQuery']>[1]
params?: Parameters<TelegramClient['answerCallbackQuery']>[1]
): Promise<void> {
return this.client.answerCallbackQuery(this.raw.queryId, params)
}

View file

@ -487,15 +487,14 @@ export class BaseTelegramClient {
this._lastRequestTime = Date.now()
const connection = params?.connection ?? this.primaryConnection
let lastError: Error | null = null
const stack = this._niceStacks ? new Error().stack : undefined
for (let i = 0; i < this._rpcRetryCount; i++) {
try {
const res = await (params?.connection ?? this.primaryConnection).sendForResult(
message,
stack
)
const res = await connection.sendForResult(message, stack)
await this._cachePeersFrom(res)
return res
@ -538,9 +537,10 @@ export class BaseTelegramClient {
}
}
if (
e instanceof PhoneMigrateError ||
e instanceof UserMigrateError ||
e instanceof NetworkMigrateError
connection === this.primaryConnection &&
(e instanceof PhoneMigrateError ||
e instanceof UserMigrateError ||
e instanceof NetworkMigrateError)
) {
debug('Migrate error, new dc = %d', e.newDc)
await this.changeDc(e.newDc)
@ -660,7 +660,7 @@ export class BaseTelegramClient {
phone: peer.phone ?? null,
type: peer.bot ? 'bot' : 'user',
updated: 0,
fromMessage: peer.fromMessage
fromMessage: peer.fromMessage,
})
} else if (peer._ === 'chat' || peer._ === 'chatForbidden') {
parsedPeers.push({
@ -670,7 +670,7 @@ export class BaseTelegramClient {
phone: null,
type: 'group',
updated: 0,
fromMessage: peer.fromMessage
fromMessage: peer.fromMessage,
})
} else if (peer._ === 'channel' || peer._ === 'channelForbidden') {
parsedPeers.push({
@ -683,7 +683,7 @@ export class BaseTelegramClient {
phone: null,
type: peer.broadcast ? 'channel' : 'supergroup',
updated: 0,
fromMessage: peer.fromMessage
fromMessage: peer.fromMessage,
})
}
}