From 917dc1171b9c9f25392145acbed2d50f2eb5ab22 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Fri, 19 Apr 2024 13:38:54 +0400 Subject: [PATCH] GramJS: Fix showing file connection disconnect in UI (#4483) --- src/lib/gramjs/network/MTProtoSender.js | 32 ++++++++++++------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/lib/gramjs/network/MTProtoSender.js b/src/lib/gramjs/network/MTProtoSender.js index 934363ac4..13372f7b7 100644 --- a/src/lib/gramjs/network/MTProtoSender.js +++ b/src/lib/gramjs/network/MTProtoSender.js @@ -233,13 +233,13 @@ class MTProtoSender { this.logWithIndex.warn('Connecting...'); await this._connect(this.getConnection()); this.logWithIndex.warn('Connected!'); - if (this._updateCallback) { - this._updateCallback(new UpdateConnectionState(UpdateConnectionState.connected)); + if (!this._isExported) { + this._updateCallback?.(new UpdateConnectionState(UpdateConnectionState.connected)); } break; } catch (err) { - if (this._updateCallback && attempt === 0) { - this._updateCallback(new UpdateConnectionState(UpdateConnectionState.disconnected)); + if (!this._isExported && attempt === 0) { + this._updateCallback?.(new UpdateConnectionState(UpdateConnectionState.disconnected)); } this._log.error(`${this._isFallback ? 'HTTP' : 'WebSocket'} connection failed attempt: ${attempt + 1}`); // eslint-disable-next-line no-console @@ -382,8 +382,8 @@ class MTProtoSender { this._state.timeOffset = res.timeOffset; - if (this._updateCallback) { - this._updateCallback(new UpdateServerTimeOffset(this._state.timeOffset)); + if (!this._isExported) { + this._updateCallback?.(new UpdateServerTimeOffset(this._state.timeOffset)); } /** @@ -425,8 +425,8 @@ class MTProtoSender { } async _disconnect(connection) { - if (this._updateCallback) { - this._updateCallback(new UpdateConnectionState(UpdateConnectionState.disconnected)); + if (!this._isExported) { + this._updateCallback?.(new UpdateConnectionState(UpdateConnectionState.disconnected)); } if (connection === undefined) { @@ -692,8 +692,8 @@ class MTProtoSender { this._log.warn(`Broken authorization key for dc ${this._dcId}, resetting...`); - if (this._isMainSender && this._updateCallback) { - this._updateCallback(new UpdateConnectionState(UpdateConnectionState.broken)); + if (this._isMainSender && !this._isExported) { + this._updateCallback?.(new UpdateConnectionState(UpdateConnectionState.broken)); } else if (!this._isMainSender && this._onConnectionBreak) { this._onConnectionBreak(this._dcId); } @@ -858,8 +858,8 @@ class MTProtoSender { return; } this._log.debug(`Handling update ${message.obj.className}`); - if (this._updateCallback) { - this._updateCallback(message.obj); + if (!this._isExported) { + this._updateCallback?.(message.obj); } } @@ -875,8 +875,8 @@ class MTProtoSender { const pong = message.obj; const newTimeOffset = this._state.updateTimeOffset(message.msgId); - if (this._updateCallback) { - this._updateCallback(new UpdateServerTimeOffset(newTimeOffset)); + if (!this._isExported) { + this._updateCallback?.(new UpdateServerTimeOffset(newTimeOffset)); } this._log.debug(`Handling pong for message ${pong.msgId}`); @@ -924,8 +924,8 @@ class MTProtoSender { // Use the current msg_id to determine the right time offset. const newTimeOffset = this._state.updateTimeOffset(message.msgId); - if (this._updateCallback) { - this._updateCallback(new UpdateServerTimeOffset(newTimeOffset)); + if (!this._isExported) { + this._updateCallback?.(new UpdateServerTimeOffset(newTimeOffset)); } this._log.info(`System clock is wrong, set time offset to ${newTimeOffset}s`);