@mtcute/core 0.20.1 → 0.20.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -133,6 +133,11 @@ class BaseTelegramClient {
133
133
  this.mt.network.notifyLoggedOut();
134
134
  this.log.prefix = "[USER n/a] ";
135
135
  await this.storage.self.store(null);
136
+ const primaryDc = this.mt.network.getPrimaryDcId();
137
+ for (const dc of this.mt.network.config.getCached()?.dcOptions ?? []) {
138
+ if (dc.id === primaryDc) continue;
139
+ await this.mt.storage.provider.authKeys.deleteByDc(dc.id);
140
+ }
136
141
  }
137
142
  async notifyChannelOpened(channelId, pts) {
138
143
  return this.updates?.notifyChannelOpened(channelId, pts) ?? false;
package/highlevel/base.js CHANGED
@@ -126,6 +126,11 @@ class BaseTelegramClient {
126
126
  this.mt.network.notifyLoggedOut();
127
127
  this.log.prefix = "[USER n/a] ";
128
128
  await this.storage.self.store(null);
129
+ const primaryDc = this.mt.network.getPrimaryDcId();
130
+ for (const dc of this.mt.network.config.getCached()?.dcOptions ?? []) {
131
+ if (dc.id === primaryDc) continue;
132
+ await this.mt.storage.provider.authKeys.deleteByDc(dc.id);
133
+ }
129
134
  }
130
135
  async notifyChannelOpened(channelId, pts) {
131
136
  return this.updates?.notifyChannelOpened(channelId, pts) ?? false;
@@ -220,7 +220,7 @@ class NetworkManager {
220
220
  _: "initConnection",
221
221
  deviceModel,
222
222
  systemVersion: "1.0",
223
- appVersion: "0.20.1",
223
+ appVersion: "0.20.2",
224
224
  systemLangCode: "en",
225
225
  langPack: "",
226
226
  // "langPacks are for official apps only"
@@ -213,7 +213,7 @@ class NetworkManager {
213
213
  _: "initConnection",
214
214
  deviceModel,
215
215
  systemVersion: "1.0",
216
- appVersion: "0.20.1",
216
+ appVersion: "0.20.2",
217
217
  systemLangCode: "en",
218
218
  langPack: "",
219
219
  // "langPacks are for official apps only"
@@ -94,16 +94,18 @@ class PersistentConnection {
94
94
  }
95
95
  }
96
96
  }
97
- async _onClose() {
97
+ _onClose() {
98
98
  this.log.debug("connection closed");
99
99
  this._updateLogPrefix();
100
100
  this._writer = void 0;
101
101
  this._codec.reset();
102
102
  this.onClosed();
103
103
  }
104
- async _onError(err) {
104
+ _onError(err) {
105
105
  this._updateLogPrefix();
106
- this.handleError(err);
106
+ if (!(err instanceof net.ConnectionClosedError)) {
107
+ this.handleError(err);
108
+ }
107
109
  return "reconnect";
108
110
  }
109
111
  async changeTransport(transport) {
@@ -167,7 +169,13 @@ class PersistentConnection {
167
169
  }
168
170
  if (this._writer) {
169
171
  this._rescheduleInactivity();
170
- await this._writer.write(data);
172
+ try {
173
+ await this._writer.write(data);
174
+ } catch (e) {
175
+ this.log.warn("encountered an error closed while sending, reconnecting: %e", e);
176
+ this._fuman.reconnect(true);
177
+ this._sendOnceConnected.push(data);
178
+ }
171
179
  } else {
172
180
  this._sendOnceConnected.push(data);
173
181
  }
@@ -1,5 +1,5 @@
1
1
  import { FramedReader, FramedWriter } from "@fuman/io";
2
- import { PersistentConnection as PersistentConnection$1 } from "@fuman/net";
2
+ import { PersistentConnection as PersistentConnection$1, ConnectionClosedError } from "@fuman/net";
3
3
  import { Emitter, timers } from "@fuman/utils";
4
4
  let nextConnectionUid = 0;
5
5
  class PersistentConnection {
@@ -87,16 +87,18 @@ class PersistentConnection {
87
87
  }
88
88
  }
89
89
  }
90
- async _onClose() {
90
+ _onClose() {
91
91
  this.log.debug("connection closed");
92
92
  this._updateLogPrefix();
93
93
  this._writer = void 0;
94
94
  this._codec.reset();
95
95
  this.onClosed();
96
96
  }
97
- async _onError(err) {
97
+ _onError(err) {
98
98
  this._updateLogPrefix();
99
- this.handleError(err);
99
+ if (!(err instanceof ConnectionClosedError)) {
100
+ this.handleError(err);
101
+ }
100
102
  return "reconnect";
101
103
  }
102
104
  async changeTransport(transport) {
@@ -160,7 +162,13 @@ class PersistentConnection {
160
162
  }
161
163
  if (this._writer) {
162
164
  this._rescheduleInactivity();
163
- await this._writer.write(data);
165
+ try {
166
+ await this._writer.write(data);
167
+ } catch (e) {
168
+ this.log.warn("encountered an error closed while sending, reconnecting: %e", e);
169
+ this._fuman.reconnect(true);
170
+ this._sendOnceConnected.push(data);
171
+ }
164
172
  } else {
165
173
  this._sendOnceConnected.push(data);
166
174
  }
@@ -1428,16 +1428,7 @@ class SessionConnection extends persistentConnection.PersistentConnection {
1428
1428
  rootMsgId
1429
1429
  );
1430
1430
  const enc = this._session.encryptMessage(result);
1431
- const promise = this.send(enc).catch((err) => {
1432
- if (this._destroyed) return;
1433
- this.log.error("error while sending pending messages (root msg_id = %l): %e", rootMsgId, err);
1434
- if (ackMsgIds) {
1435
- this._session.queuedAcks.splice(0, 0, ...ackMsgIds);
1436
- }
1437
- if (rootMsgId) {
1438
- this._onMessageFailed(rootMsgId, "unknown error");
1439
- }
1440
- });
1431
+ const promise = this.send(enc);
1441
1432
  if (this._inactivityPendingFlush && !this._session.hasPendingMessages) {
1442
1433
  void promise.then(() => {
1443
1434
  this.log.debug("pending messages sent, closing connection");
@@ -1421,16 +1421,7 @@ class SessionConnection extends PersistentConnection {
1421
1421
  rootMsgId
1422
1422
  );
1423
1423
  const enc = this._session.encryptMessage(result);
1424
- const promise = this.send(enc).catch((err) => {
1425
- if (this._destroyed) return;
1426
- this.log.error("error while sending pending messages (root msg_id = %l): %e", rootMsgId, err);
1427
- if (ackMsgIds) {
1428
- this._session.queuedAcks.splice(0, 0, ...ackMsgIds);
1429
- }
1430
- if (rootMsgId) {
1431
- this._onMessageFailed(rootMsgId, "unknown error");
1432
- }
1433
- });
1424
+ const promise = this.send(enc);
1434
1425
  if (this._inactivityPendingFlush && !this._session.hasPendingMessages) {
1435
1426
  void promise.then(() => {
1436
1427
  this.log.debug("pending messages sent, closing connection");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mtcute/core",
3
3
  "type": "module",
4
- "version": "0.20.1",
4
+ "version": "0.20.2",
5
5
  "description": "Type-safe library for MTProto (Telegram API)",
6
6
  "license": "MIT",
7
7
  "scripts": {},