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 * Answer this query
*/ */
async answer( async answer(
params: Parameters<TelegramClient['answerCallbackQuery']>[1] params?: Parameters<TelegramClient['answerCallbackQuery']>[1]
): Promise<void> { ): Promise<void> {
return this.client.answerCallbackQuery(this.raw.queryId, params) return this.client.answerCallbackQuery(this.raw.queryId, params)
} }

View file

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