@mtkruto/node 0.1.107 → 0.1.109
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.
- package/esm/0_deps.d.ts +1 -1
- package/esm/0_deps.js +1 -1
- package/esm/4_constants.d.ts +2 -2
- package/esm/4_constants.js +3 -3
- package/esm/5_client.d.ts +1 -0
- package/esm/5_client.js +1 -0
- package/esm/client/0_html.js +26 -14
- package/esm/client/0_utilities.d.ts +1 -1
- package/esm/client/0_utilities.js +1 -2
- package/esm/client/1_client_abstract.d.ts +1 -1
- package/esm/client/1_client_abstract.js +16 -8
- package/esm/client/2_client_plain.d.ts +1 -2
- package/esm/client/2_client_plain.js +20 -15
- package/esm/client/3_types.d.ts +1 -1
- package/esm/client/4_client.d.ts +6 -57
- package/esm/client/4_client.js +619 -716
- package/esm/connection/1_connection_web_socket.d.ts +1 -9
- package/esm/connection/1_connection_web_socket.js +81 -108
- package/esm/storage/0_storage.d.ts +3 -2
- package/esm/storage/0_storage.js +35 -26
- package/esm/storage/0_utilities.d.ts +1 -1
- package/esm/storage/0_utilities.js +56 -26
- package/esm/storage/1_storage_local_storage.d.ts +1 -1
- package/esm/storage/1_storage_session_storage.d.ts +1 -1
- package/esm/tl/2_types.d.ts +441 -58
- package/esm/tl/2_types.js +1584 -118
- package/esm/tl/3_functions.d.ts +113 -16
- package/esm/tl/3_functions.js +364 -39
- package/esm/transport/1_transport_abridged.d.ts +1 -2
- package/esm/transport/1_transport_abridged.js +24 -19
- package/esm/transport/1_transport_intermediate.d.ts +1 -2
- package/esm/transport/1_transport_intermediate.js +23 -18
- package/esm/types/0_color.d.ts +2 -1
- package/esm/types/0_color.js +21 -1
- package/esm/types/0_message_entity.d.ts +1 -1
- package/esm/types/1_chat.js +5 -5
- package/esm/types/1_user.js +2 -2
- package/esm/types/3_message.js +1 -1
- package/esm/utilities/0_base64.js +3 -3
- package/esm/utilities/0_queue.d.ts +2 -4
- package/esm/utilities/0_queue.js +39 -36
- package/package.json +1 -1
- package/script/0_deps.d.ts +1 -1
- package/script/0_deps.js +3 -3
- package/script/4_constants.d.ts +2 -2
- package/script/4_constants.js +3 -3
- package/script/5_client.d.ts +1 -0
- package/script/5_client.js +1 -0
- package/script/client/0_html.js +26 -14
- package/script/client/0_utilities.d.ts +1 -1
- package/script/client/0_utilities.js +1 -2
- package/script/client/1_client_abstract.d.ts +1 -1
- package/script/client/1_client_abstract.js +16 -8
- package/script/client/2_client_plain.d.ts +1 -2
- package/script/client/2_client_plain.js +20 -15
- package/script/client/3_types.d.ts +1 -1
- package/script/client/4_client.d.ts +6 -57
- package/script/client/4_client.js +619 -716
- package/script/connection/1_connection_web_socket.d.ts +1 -9
- package/script/connection/1_connection_web_socket.js +81 -108
- package/script/storage/0_storage.d.ts +3 -2
- package/script/storage/0_storage.js +35 -26
- package/script/storage/0_utilities.d.ts +1 -1
- package/script/storage/0_utilities.js +55 -25
- package/script/storage/1_storage_local_storage.d.ts +1 -1
- package/script/storage/1_storage_session_storage.d.ts +1 -1
- package/script/tl/2_types.d.ts +441 -58
- package/script/tl/2_types.js +1646 -158
- package/script/tl/3_functions.d.ts +113 -16
- package/script/tl/3_functions.js +386 -53
- package/script/transport/1_transport_abridged.d.ts +1 -2
- package/script/transport/1_transport_abridged.js +24 -19
- package/script/transport/1_transport_intermediate.d.ts +1 -2
- package/script/transport/1_transport_intermediate.js +23 -18
- package/script/types/0_color.d.ts +2 -1
- package/script/types/0_color.js +24 -3
- package/script/types/0_message_entity.d.ts +1 -1
- package/script/types/1_chat.js +4 -4
- package/script/types/1_user.js +1 -1
- package/script/types/3_message.js +1 -1
- package/script/utilities/0_base64.js +2 -2
- package/script/utilities/0_queue.d.ts +2 -4
- package/script/utilities/0_queue.js +39 -36
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _Client_instances, _a, _Client_auth, _Client_sessionId, _Client_state, _Client_promises, _Client_toAcknowledge, _Client_updateState, _Client_errorHandler, _Client_publicKeys, _Client_autoStart, _Client_propagateConnectionState, _Client_lastPropagatedConnectionState, _Client_storageInited, _Client_setAuth, _Client_authKeyWasCreated, _Client_connectMutex, _Client_assertUser, _Client_assertBot, _Client_fetchState, _Client_connectionInited, _Client_initConnection, _Client_lastPropagatedAuthorizationState, _Client_propagateAuthorizationState, _Client_selfId, _Client_getSelfId, _Client_receiveLoop, _Client_pingLoop, _Client_lastOutgoing, _Client_pingLoopStarted, _Client_autoStarted, _Client_lastMsgId, _Client_processChats, _Client_processUsers, _Client_handleUpdateQueue, _Client_processUpdatesQueue, _Client_checkChannelGap, _Client_processUpdates, _Client_setUpdateStateDate, _Client_getLocalState, _Client_recoverUpdateGap, _Client_recoverChannelUpdateGap, _Client_getChannelAccessHash, _Client_getInputPeerInner, _Client_updatesToMessages, _Client_resolveSendAs, _Client_parseText, _Client_getMessagesInner, _Client_downloadInner, _Client_handleUpdate, _Client_usernameResolver, _Client_constructReplyMarkup, _Client_assertMsgHas, _Client_handle, _Client_setMyInfo, _Client_getMyInfo;
|
|
2
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
15
|
exports.Client = exports.ConnectionError = exports.restartAuth = exports.handleMigrationError = void 0;
|
|
4
16
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
@@ -39,6 +51,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
39
51
|
*/
|
|
40
52
|
constructor(storage, apiId = 0, apiHash = "", params) {
|
|
41
53
|
super(params);
|
|
54
|
+
_Client_instances.add(this);
|
|
42
55
|
Object.defineProperty(this, "apiId", {
|
|
43
56
|
enumerable: true,
|
|
44
57
|
configurable: true,
|
|
@@ -51,48 +64,13 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
51
64
|
writable: true,
|
|
52
65
|
value: apiHash
|
|
53
66
|
});
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
enumerable: true,
|
|
62
|
-
configurable: true,
|
|
63
|
-
writable: true,
|
|
64
|
-
value: (0, _1_utilities_js_1.getRandomBigInt)(8, true, false)
|
|
65
|
-
});
|
|
66
|
-
Object.defineProperty(this, "state", {
|
|
67
|
-
enumerable: true,
|
|
68
|
-
configurable: true,
|
|
69
|
-
writable: true,
|
|
70
|
-
value: { salt: 0n, seqNo: 0 }
|
|
71
|
-
});
|
|
72
|
-
Object.defineProperty(this, "promises", {
|
|
73
|
-
enumerable: true,
|
|
74
|
-
configurable: true,
|
|
75
|
-
writable: true,
|
|
76
|
-
value: new Map()
|
|
77
|
-
});
|
|
78
|
-
Object.defineProperty(this, "toAcknowledge", {
|
|
79
|
-
enumerable: true,
|
|
80
|
-
configurable: true,
|
|
81
|
-
writable: true,
|
|
82
|
-
value: new Set()
|
|
83
|
-
});
|
|
84
|
-
Object.defineProperty(this, "updateState", {
|
|
85
|
-
enumerable: true,
|
|
86
|
-
configurable: true,
|
|
87
|
-
writable: true,
|
|
88
|
-
value: void 0
|
|
89
|
-
});
|
|
90
|
-
Object.defineProperty(this, "errorHandler", {
|
|
91
|
-
enumerable: true,
|
|
92
|
-
configurable: true,
|
|
93
|
-
writable: true,
|
|
94
|
-
value: void 0
|
|
95
|
-
});
|
|
67
|
+
_Client_auth.set(this, null);
|
|
68
|
+
_Client_sessionId.set(this, (0, _1_utilities_js_1.getRandomBigInt)(8, true, false));
|
|
69
|
+
_Client_state.set(this, { salt: 0n, seqNo: 0 });
|
|
70
|
+
_Client_promises.set(this, new Map());
|
|
71
|
+
_Client_toAcknowledge.set(this, new Set());
|
|
72
|
+
_Client_updateState.set(this, void 0);
|
|
73
|
+
_Client_errorHandler.set(this, void 0);
|
|
96
74
|
Object.defineProperty(this, "storage", {
|
|
97
75
|
enumerable: true,
|
|
98
76
|
configurable: true,
|
|
@@ -141,35 +119,20 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
141
119
|
writable: true,
|
|
142
120
|
value: void 0
|
|
143
121
|
});
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
writable: true,
|
|
148
|
-
value: void 0
|
|
149
|
-
});
|
|
150
|
-
Object.defineProperty(this, "autoStart", {
|
|
151
|
-
enumerable: true,
|
|
152
|
-
configurable: true,
|
|
153
|
-
writable: true,
|
|
154
|
-
value: void 0
|
|
155
|
-
});
|
|
156
|
-
Object.defineProperty(this, "lastPropagatedConnectionState", {
|
|
157
|
-
enumerable: true,
|
|
158
|
-
configurable: true,
|
|
159
|
-
writable: true,
|
|
160
|
-
value: null
|
|
161
|
-
});
|
|
122
|
+
_Client_publicKeys.set(this, void 0);
|
|
123
|
+
_Client_autoStart.set(this, void 0);
|
|
124
|
+
_Client_lastPropagatedConnectionState.set(this, null);
|
|
162
125
|
Object.defineProperty(this, "stateChangeHandler", {
|
|
163
126
|
enumerable: true,
|
|
164
127
|
configurable: true,
|
|
165
128
|
writable: true,
|
|
166
129
|
value: ((connected) => {
|
|
167
|
-
this.
|
|
130
|
+
__classPrivateFieldGet(this, _Client_connectMutex, "f").acquire().then(async (release) => {
|
|
168
131
|
try {
|
|
169
132
|
const connectionState = connected ? "ready" : "notConnected";
|
|
170
|
-
if (this.connected == connected && this
|
|
171
|
-
await this.
|
|
172
|
-
this
|
|
133
|
+
if (this.connected == connected && __classPrivateFieldGet(this, _Client_lastPropagatedConnectionState, "f") != connectionState) {
|
|
134
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateConnectionState).call(this, connectionState);
|
|
135
|
+
__classPrivateFieldSet(this, _Client_lastPropagatedConnectionState, connectionState, "f");
|
|
173
136
|
}
|
|
174
137
|
}
|
|
175
138
|
finally {
|
|
@@ -178,81 +141,23 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
178
141
|
});
|
|
179
142
|
}).bind(this)
|
|
180
143
|
});
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
writable: true,
|
|
197
|
-
value: false
|
|
198
|
-
});
|
|
199
|
-
Object.defineProperty(this, "lastPropagatedAuthorizationState", {
|
|
200
|
-
enumerable: true,
|
|
201
|
-
configurable: true,
|
|
202
|
-
writable: true,
|
|
203
|
-
value: null
|
|
204
|
-
});
|
|
205
|
-
Object.defineProperty(this, "selfId", {
|
|
206
|
-
enumerable: true,
|
|
207
|
-
configurable: true,
|
|
208
|
-
writable: true,
|
|
209
|
-
value: null
|
|
210
|
-
});
|
|
211
|
-
Object.defineProperty(this, "pingLoopStarted", {
|
|
212
|
-
enumerable: true,
|
|
213
|
-
configurable: true,
|
|
214
|
-
writable: true,
|
|
215
|
-
value: false
|
|
216
|
-
});
|
|
217
|
-
Object.defineProperty(this, "autoStarted", {
|
|
218
|
-
enumerable: true,
|
|
219
|
-
configurable: true,
|
|
220
|
-
writable: true,
|
|
221
|
-
value: false
|
|
222
|
-
});
|
|
223
|
-
Object.defineProperty(this, "lastMsgId", {
|
|
224
|
-
enumerable: true,
|
|
225
|
-
configurable: true,
|
|
226
|
-
writable: true,
|
|
227
|
-
value: 0n
|
|
228
|
-
});
|
|
229
|
-
Object.defineProperty(this, "handleUpdateQueue", {
|
|
230
|
-
enumerable: true,
|
|
231
|
-
configurable: true,
|
|
232
|
-
writable: true,
|
|
233
|
-
value: new _1_utilities_js_1.Queue("handleUpdate")
|
|
234
|
-
});
|
|
235
|
-
Object.defineProperty(this, "processUpdatesQueue", {
|
|
236
|
-
enumerable: true,
|
|
237
|
-
configurable: true,
|
|
238
|
-
writable: true,
|
|
239
|
-
value: new _1_utilities_js_1.Queue("processUpdates")
|
|
240
|
-
});
|
|
241
|
-
Object.defineProperty(this, "usernameResolver", {
|
|
242
|
-
enumerable: true,
|
|
243
|
-
configurable: true,
|
|
244
|
-
writable: true,
|
|
245
|
-
value: async (v) => {
|
|
246
|
-
const inputPeer = await this.getInputPeer(v).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.InputPeerUser));
|
|
247
|
-
return new _2_tl_js_1.types.InputUser({ userId: inputPeer.userId, accessHash: inputPeer.accessHash });
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
Object.defineProperty(this, "handle", {
|
|
251
|
-
enumerable: true,
|
|
252
|
-
configurable: true,
|
|
253
|
-
writable: true,
|
|
254
|
-
value: _3_types_js_2.skip
|
|
144
|
+
_Client_storageInited.set(this, false);
|
|
145
|
+
_Client_authKeyWasCreated.set(this, true);
|
|
146
|
+
_Client_connectMutex.set(this, new _0_deps_js_1.Mutex());
|
|
147
|
+
_Client_connectionInited.set(this, false);
|
|
148
|
+
_Client_lastPropagatedAuthorizationState.set(this, null);
|
|
149
|
+
_Client_selfId.set(this, null);
|
|
150
|
+
_Client_lastOutgoing.set(this, null);
|
|
151
|
+
_Client_pingLoopStarted.set(this, false);
|
|
152
|
+
_Client_autoStarted.set(this, false);
|
|
153
|
+
_Client_lastMsgId.set(this, 0n);
|
|
154
|
+
_Client_handleUpdateQueue.set(this, new _1_utilities_js_1.Queue("handleUpdate"));
|
|
155
|
+
_Client_processUpdatesQueue.set(this, new _1_utilities_js_1.Queue("processUpdates"));
|
|
156
|
+
_Client_usernameResolver.set(this, async (v) => {
|
|
157
|
+
const inputPeer = await this.getInputPeer(v).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.InputPeerUser));
|
|
158
|
+
return new _2_tl_js_1.types.InputUser({ userId: inputPeer.userId, accessHash: inputPeer.accessHash });
|
|
255
159
|
});
|
|
160
|
+
_Client_handle.set(this, _3_types_js_2.skip);
|
|
256
161
|
this.storage = storage ?? new _3_storage_js_1.StorageMemory();
|
|
257
162
|
this.parseMode = params?.parseMode ?? null;
|
|
258
163
|
this.appVersion = params?.appVersion ?? _4_constants_js_1.APP_VERSION;
|
|
@@ -261,12 +166,9 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
261
166
|
this.langPack = params?.langPack ?? _4_constants_js_1.LANG_PACK;
|
|
262
167
|
this.systemLangCode = params?.systemLangCode ?? _4_constants_js_1.SYSTEM_LANG_CODE;
|
|
263
168
|
this.systemVersion = params?.systemVersion ?? _4_constants_js_1.SYSTEM_VERSION;
|
|
264
|
-
this
|
|
265
|
-
this
|
|
266
|
-
this
|
|
267
|
-
}
|
|
268
|
-
propagateConnectionState(connectionState) {
|
|
269
|
-
return this.handle({ connectionState }, _0_utilities_js_1.resolve);
|
|
169
|
+
__classPrivateFieldSet(this, _Client_publicKeys, params?.publicKeys, "f");
|
|
170
|
+
__classPrivateFieldSet(this, _Client_autoStart, params?.autoStart ?? true, "f");
|
|
171
|
+
__classPrivateFieldSet(this, _Client_errorHandler, params?.errorHandler, "f");
|
|
270
172
|
}
|
|
271
173
|
/**
|
|
272
174
|
* Sets the DC and resets the auth key stored in the session provider
|
|
@@ -275,9 +177,9 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
275
177
|
* @param dc The DC to change to.
|
|
276
178
|
*/
|
|
277
179
|
async setDc(dc) {
|
|
278
|
-
if (!this
|
|
180
|
+
if (!__classPrivateFieldGet(this, _Client_storageInited, "f")) {
|
|
279
181
|
await this.storage.init();
|
|
280
|
-
this
|
|
182
|
+
__classPrivateFieldSet(this, _Client_storageInited, true, "f");
|
|
281
183
|
}
|
|
282
184
|
if (await this.storage.getDc() != dc) {
|
|
283
185
|
await this.storage.setDc(dc);
|
|
@@ -286,11 +188,6 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
286
188
|
}
|
|
287
189
|
super.setDc(dc);
|
|
288
190
|
}
|
|
289
|
-
async setAuth(key) {
|
|
290
|
-
const hash = await (0, _1_utilities_js_1.sha1)(key);
|
|
291
|
-
const id = (0, _1_utilities_js_1.bigIntFromBuffer)(hash.slice(-8), true, false);
|
|
292
|
-
this.auth = { key, id };
|
|
293
|
-
}
|
|
294
191
|
/**
|
|
295
192
|
* Loads the session if `setDc` was not called, initializes and connnects
|
|
296
193
|
* a `ClientPlain` to generate auth key if there was none, and connects the client.
|
|
@@ -300,15 +197,15 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
300
197
|
if (this.connected) {
|
|
301
198
|
return;
|
|
302
199
|
}
|
|
303
|
-
const release = await this.
|
|
200
|
+
const release = await __classPrivateFieldGet(this, _Client_connectMutex, "f").acquire();
|
|
304
201
|
try {
|
|
305
|
-
if (!this
|
|
202
|
+
if (!__classPrivateFieldGet(this, _Client_storageInited, "f")) {
|
|
306
203
|
await this.storage.init();
|
|
307
|
-
this
|
|
204
|
+
__classPrivateFieldSet(this, _Client_storageInited, true, "f");
|
|
308
205
|
}
|
|
309
206
|
const authKey = await this.storage.getAuthKey();
|
|
310
207
|
if (authKey == null) {
|
|
311
|
-
const plain = new _2_client_plain_js_1.ClientPlain({ initialDc: this.initialDc, transportProvider: this.transportProvider, cdn: this.cdn, publicKeys: this
|
|
208
|
+
const plain = new _2_client_plain_js_1.ClientPlain({ initialDc: this.initialDc, transportProvider: this.transportProvider, cdn: this.cdn, publicKeys: __classPrivateFieldGet(this, _Client_publicKeys, "f") });
|
|
312
209
|
const dc = await this.storage.getDc();
|
|
313
210
|
if (dc != null) {
|
|
314
211
|
plain.setDc(dc);
|
|
@@ -317,11 +214,16 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
317
214
|
const { authKey, salt } = await plain.createAuthKey();
|
|
318
215
|
await plain.disconnect();
|
|
319
216
|
await this.storage.setAuthKey(authKey);
|
|
320
|
-
await this.
|
|
321
|
-
this.
|
|
217
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setAuth).call(this, authKey);
|
|
218
|
+
__classPrivateFieldGet(this, _Client_state, "f").salt = salt;
|
|
219
|
+
await this.storage.setServerSalt(salt);
|
|
322
220
|
}
|
|
323
221
|
else {
|
|
324
|
-
|
|
222
|
+
if (__classPrivateFieldGet(this, _Client_state, "f").salt == 0n) {
|
|
223
|
+
__classPrivateFieldGet(this, _Client_state, "f").salt = await this.storage.getServerSalt() ?? 0n;
|
|
224
|
+
}
|
|
225
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setAuth).call(this, authKey);
|
|
226
|
+
__classPrivateFieldSet(this, _Client_authKeyWasCreated, false, "f");
|
|
325
227
|
}
|
|
326
228
|
const dc = await this.storage.getDc();
|
|
327
229
|
if (dc != null) {
|
|
@@ -332,28 +234,31 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
332
234
|
await this.storage.setDc(this.initialDc);
|
|
333
235
|
}
|
|
334
236
|
d("encrypted client connected");
|
|
335
|
-
(0, _1_utilities_js_1.drop)(this.
|
|
237
|
+
(0, _1_utilities_js_1.drop)(__classPrivateFieldGet(this, _Client_instances, "m", _Client_receiveLoop).call(this));
|
|
336
238
|
}
|
|
337
239
|
finally {
|
|
338
240
|
release();
|
|
339
241
|
}
|
|
340
242
|
}
|
|
341
|
-
async
|
|
243
|
+
async [(_Client_auth = new WeakMap(), _Client_sessionId = new WeakMap(), _Client_state = new WeakMap(), _Client_promises = new WeakMap(), _Client_toAcknowledge = new WeakMap(), _Client_updateState = new WeakMap(), _Client_errorHandler = new WeakMap(), _Client_publicKeys = new WeakMap(), _Client_autoStart = new WeakMap(), _Client_lastPropagatedConnectionState = new WeakMap(), _Client_storageInited = new WeakMap(), _Client_authKeyWasCreated = new WeakMap(), _Client_connectMutex = new WeakMap(), _Client_connectionInited = new WeakMap(), _Client_lastPropagatedAuthorizationState = new WeakMap(), _Client_selfId = new WeakMap(), _Client_lastOutgoing = new WeakMap(), _Client_pingLoopStarted = new WeakMap(), _Client_autoStarted = new WeakMap(), _Client_lastMsgId = new WeakMap(), _Client_handleUpdateQueue = new WeakMap(), _Client_processUpdatesQueue = new WeakMap(), _Client_usernameResolver = new WeakMap(), _Client_handle = new WeakMap(), _Client_instances = new WeakSet(), _Client_propagateConnectionState = function _Client_propagateConnectionState(connectionState) {
|
|
244
|
+
return __classPrivateFieldGet(this, _Client_handle, "f").call(this, { connectionState }, _0_utilities_js_1.resolve);
|
|
245
|
+
}, _Client_setAuth = async function _Client_setAuth(key) {
|
|
246
|
+
const hash = await (0, _1_utilities_js_1.sha1)(key);
|
|
247
|
+
const id = (0, _1_utilities_js_1.bigIntFromBuffer)(hash.slice(-8), true, false);
|
|
248
|
+
__classPrivateFieldSet(this, _Client_auth, { key, id }, "f");
|
|
249
|
+
}, _Client_assertUser = async function _Client_assertUser(source) {
|
|
342
250
|
if (await this.storage.getAccountType() != "user") {
|
|
343
251
|
throw new Error(`${source}: not user a client`);
|
|
344
252
|
}
|
|
345
|
-
}
|
|
346
|
-
async assertBot(source) {
|
|
253
|
+
}, _Client_assertBot = async function _Client_assertBot(source) {
|
|
347
254
|
if (await this.storage.getAccountType() != "bot") {
|
|
348
255
|
throw new Error(`${source}: not a bot client`);
|
|
349
256
|
}
|
|
350
|
-
}
|
|
351
|
-
async fetchState(source) {
|
|
257
|
+
}, _Client_fetchState = async function _Client_fetchState(source) {
|
|
352
258
|
const state = await this.invoke(new _2_tl_js_1.functions.UpdatesGetState());
|
|
353
|
-
this
|
|
259
|
+
__classPrivateFieldSet(this, _Client_updateState, state, "f");
|
|
354
260
|
d("state fetched [%s]", source);
|
|
355
|
-
}
|
|
356
|
-
async [exports.handleMigrationError](err) {
|
|
261
|
+
}, exports.handleMigrationError)](err) {
|
|
357
262
|
let newDc = String(err.dc);
|
|
358
263
|
if (Math.abs(this.dcId) >= 10000) {
|
|
359
264
|
newDc += "-test";
|
|
@@ -362,40 +267,9 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
362
267
|
d("migrated to DC%s", newDc);
|
|
363
268
|
}
|
|
364
269
|
disconnect() {
|
|
365
|
-
this
|
|
270
|
+
__classPrivateFieldSet(this, _Client_connectionInited, false, "f");
|
|
366
271
|
return super.disconnect();
|
|
367
272
|
}
|
|
368
|
-
async initConnection() {
|
|
369
|
-
if (!this.connectionInited) {
|
|
370
|
-
await this.invoke(new _2_tl_js_1.functions.InitConnection({
|
|
371
|
-
apiId: this.apiId,
|
|
372
|
-
appVersion: this.appVersion,
|
|
373
|
-
deviceModel: this.deviceModel,
|
|
374
|
-
langCode: this.langCode,
|
|
375
|
-
langPack: this.langPack,
|
|
376
|
-
query: new _2_tl_js_1.functions.InvokeWithLayer({
|
|
377
|
-
layer: _4_constants_js_1.LAYER,
|
|
378
|
-
query: new _2_tl_js_1.functions.HelpGetConfig(),
|
|
379
|
-
}),
|
|
380
|
-
systemLangCode: this.systemLangCode,
|
|
381
|
-
systemVersion: this.systemVersion,
|
|
382
|
-
}));
|
|
383
|
-
this.connectionInited = true;
|
|
384
|
-
d("connection inited");
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
async propagateAuthorizationState(authorized) {
|
|
388
|
-
if (this.lastPropagatedAuthorizationState != authorized) {
|
|
389
|
-
await this.handle({ authorizationState: { authorized } }, _0_utilities_js_1.resolve);
|
|
390
|
-
this.lastPropagatedAuthorizationState = authorized;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
async getSelfId() {
|
|
394
|
-
if (this.selfId == null) {
|
|
395
|
-
this.selfId = await this.getMe().then((v) => v.id);
|
|
396
|
-
}
|
|
397
|
-
return this.selfId;
|
|
398
|
-
}
|
|
399
273
|
/**
|
|
400
274
|
* Calls [initConnection](1) and authorizes the client with one of the following:
|
|
401
275
|
*
|
|
@@ -430,10 +304,10 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
430
304
|
}
|
|
431
305
|
}
|
|
432
306
|
dAuth("authorizing with %s", typeof params === "string" ? "bot token" : params instanceof _2_tl_js_1.types.AuthExportedAuthorization ? "exported authorization" : "AuthorizeUserParams");
|
|
433
|
-
await this.
|
|
307
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_initConnection).call(this);
|
|
434
308
|
try {
|
|
435
|
-
await this.
|
|
436
|
-
await this.
|
|
309
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchState).call(this, "authorize");
|
|
310
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateAuthorizationState).call(this, true);
|
|
437
311
|
d("already authorized");
|
|
438
312
|
return;
|
|
439
313
|
}
|
|
@@ -446,14 +320,14 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
446
320
|
while (true) {
|
|
447
321
|
try {
|
|
448
322
|
const auth = await this.invoke(new _2_tl_js_1.functions.AuthImportBotAuthorization({ apiId: this.apiId, apiHash: this.apiHash, botAuthToken: params, flags: 0 }));
|
|
449
|
-
this
|
|
323
|
+
__classPrivateFieldSet(this, _Client_selfId, Number(auth[_2_tl_js_1.as](_2_tl_js_1.types.AuthAuthorization).user.id), "f");
|
|
450
324
|
await this.storage.setAccountType("bot");
|
|
451
325
|
break;
|
|
452
326
|
}
|
|
453
327
|
catch (err) {
|
|
454
328
|
if (err instanceof _4_errors_js_1.Migrate) {
|
|
455
329
|
await this[exports.handleMigrationError](err);
|
|
456
|
-
await this.
|
|
330
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_initConnection).call(this);
|
|
457
331
|
continue;
|
|
458
332
|
}
|
|
459
333
|
else {
|
|
@@ -462,8 +336,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
462
336
|
}
|
|
463
337
|
}
|
|
464
338
|
dAuth("authorized as bot");
|
|
465
|
-
await this.
|
|
466
|
-
await this.
|
|
339
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateAuthorizationState).call(this, true);
|
|
340
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchState).call(this, "authorize");
|
|
467
341
|
return;
|
|
468
342
|
}
|
|
469
343
|
if (params instanceof _2_tl_js_1.types.AuthExportedAuthorization) {
|
|
@@ -471,89 +345,187 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
471
345
|
dAuth("authorization imported");
|
|
472
346
|
return;
|
|
473
347
|
}
|
|
474
|
-
|
|
475
|
-
let sentCode;
|
|
476
|
-
while (true) {
|
|
348
|
+
auth: while (true) {
|
|
477
349
|
try {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
350
|
+
let phone;
|
|
351
|
+
let sentCode;
|
|
352
|
+
while (true) {
|
|
353
|
+
try {
|
|
354
|
+
phone = typeof params.phone === "string" ? params.phone : await params.phone();
|
|
355
|
+
const sendCode = () => this.invoke(new _2_tl_js_1.functions.AuthSendCode({
|
|
356
|
+
phoneNumber: phone,
|
|
357
|
+
apiId: this.apiId,
|
|
358
|
+
apiHash: this.apiHash,
|
|
359
|
+
settings: new _2_tl_js_1.types.CodeSettings(),
|
|
360
|
+
})).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.AuthSentCode));
|
|
361
|
+
try {
|
|
362
|
+
sentCode = await sendCode();
|
|
363
|
+
}
|
|
364
|
+
catch (err) {
|
|
365
|
+
if (err instanceof _4_errors_js_1.Migrate) {
|
|
366
|
+
await this[exports.handleMigrationError](err);
|
|
367
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_initConnection).call(this);
|
|
368
|
+
sentCode = await sendCode();
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
throw err;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
catch (err) {
|
|
377
|
+
if (err instanceof _4_errors_js_1.PhoneNumberInvalid) {
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
throw err;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
487
384
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
385
|
+
dAuth("verification code sent");
|
|
386
|
+
let err;
|
|
387
|
+
code: while (true) {
|
|
388
|
+
const code = typeof params.code === "string" ? params.code : await params.code();
|
|
389
|
+
try {
|
|
390
|
+
const auth = await this.invoke(new _2_tl_js_1.functions.AuthSignIn({
|
|
391
|
+
phoneNumber: phone,
|
|
392
|
+
phoneCode: code,
|
|
393
|
+
phoneCodeHash: sentCode.phoneCodeHash,
|
|
394
|
+
}));
|
|
395
|
+
__classPrivateFieldSet(this, _Client_selfId, Number(auth[_2_tl_js_1.as](_2_tl_js_1.types.AuthAuthorization).user.id), "f");
|
|
396
|
+
await this.storage.setAccountType("user");
|
|
397
|
+
dAuth("authorized as user");
|
|
398
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateAuthorizationState).call(this, true);
|
|
399
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchState).call(this, "authorize");
|
|
400
|
+
return;
|
|
493
401
|
}
|
|
494
|
-
|
|
495
|
-
|
|
402
|
+
catch (err_) {
|
|
403
|
+
if (err_ instanceof _2_tl_js_1.types.RPCError && err_.errorMessage == "PHONE_CODE_INVALID") {
|
|
404
|
+
continue code;
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
err = err_;
|
|
408
|
+
break code;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
if (!(err instanceof _4_errors_js_1.SessionPasswordNeeded)) {
|
|
413
|
+
throw err;
|
|
414
|
+
}
|
|
415
|
+
password: while (true) {
|
|
416
|
+
const ap = await this.invoke(new _2_tl_js_1.functions.AccountGetPassword());
|
|
417
|
+
if (!(ap.currentAlgo instanceof _2_tl_js_1.types.PasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow)) {
|
|
418
|
+
throw new Error(`Handling ${ap.currentAlgo?.constructor.name} not implemented`);
|
|
419
|
+
}
|
|
420
|
+
try {
|
|
421
|
+
const password = typeof params.password === "string" ? params.password : await params.password(ap.hint ?? null);
|
|
422
|
+
const input = await (0, _0_password_js_1.checkPassword)(password, ap);
|
|
423
|
+
const auth = await this.invoke(new _2_tl_js_1.functions.AuthCheckPassword({ password: input }));
|
|
424
|
+
__classPrivateFieldSet(this, _Client_selfId, Number(auth[_2_tl_js_1.as](_2_tl_js_1.types.AuthAuthorization).user.id), "f");
|
|
425
|
+
await this.storage.setAccountType("user");
|
|
426
|
+
dAuth("authorized as user");
|
|
427
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateAuthorizationState).call(this, true);
|
|
428
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchState).call(this, "authorize");
|
|
429
|
+
break password;
|
|
430
|
+
}
|
|
431
|
+
catch (err) {
|
|
432
|
+
if (err instanceof _4_errors_js_1.PasswordHashInvalid) {
|
|
433
|
+
continue password;
|
|
434
|
+
}
|
|
435
|
+
else {
|
|
436
|
+
throw err;
|
|
437
|
+
}
|
|
496
438
|
}
|
|
497
439
|
}
|
|
498
|
-
break;
|
|
499
440
|
}
|
|
500
441
|
catch (err) {
|
|
501
|
-
if (err
|
|
502
|
-
continue;
|
|
442
|
+
if (err == exports.restartAuth) {
|
|
443
|
+
continue auth;
|
|
503
444
|
}
|
|
504
445
|
else {
|
|
505
446
|
throw err;
|
|
506
447
|
}
|
|
507
448
|
}
|
|
508
449
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Same as calling `.connect()` followed by `.authorize(params)` if the session didn't have an auth key.
|
|
453
|
+
*/
|
|
454
|
+
async start(params) {
|
|
455
|
+
await this.connect();
|
|
456
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_initConnection).call(this);
|
|
457
|
+
if (!__classPrivateFieldGet(this, _Client_authKeyWasCreated, "f")) {
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
try {
|
|
461
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchState).call(this, "authorize");
|
|
462
|
+
d("already authorized");
|
|
463
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateAuthorizationState).call(this, true);
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
catch (err) {
|
|
467
|
+
if (!(err instanceof _4_errors_js_1.AuthKeyUnregistered)) {
|
|
468
|
+
throw err;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
await this.authorize(params);
|
|
472
|
+
}
|
|
473
|
+
async invoke(function_, noWait) {
|
|
474
|
+
if (!__classPrivateFieldGet(this, _Client_auth, "f") || !this.transport) {
|
|
475
|
+
if (__classPrivateFieldGet(this, _Client_autoStart, "f") && !__classPrivateFieldGet(this, _Client_autoStarted, "f")) {
|
|
476
|
+
await this.start();
|
|
477
|
+
}
|
|
478
|
+
else {
|
|
479
|
+
throw new ConnectionError("Not connected");
|
|
534
480
|
}
|
|
535
481
|
}
|
|
536
|
-
if (!(
|
|
537
|
-
|
|
482
|
+
if (!__classPrivateFieldGet(this, _Client_auth, "f") || !this.transport) {
|
|
483
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
538
484
|
}
|
|
485
|
+
let n = 1;
|
|
539
486
|
while (true) {
|
|
540
|
-
const ap = await this.invoke(new _2_tl_js_1.functions.AccountGetPassword());
|
|
541
|
-
if (!(ap.currentAlgo instanceof _2_tl_js_1.types.PasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow)) {
|
|
542
|
-
throw new Error(`Handling ${ap.currentAlgo?.constructor.name} not implemented`);
|
|
543
|
-
}
|
|
544
487
|
try {
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
await this.
|
|
553
|
-
|
|
488
|
+
let seqNo = __classPrivateFieldGet(this, _Client_state, "f").seqNo * 2;
|
|
489
|
+
if (!(function_ instanceof _2_tl_js_1.functions.Ping) && !(function_ instanceof _2_tl_js_1.types.MsgsAck)) {
|
|
490
|
+
seqNo++;
|
|
491
|
+
__classPrivateFieldGet(this, _Client_state, "f").seqNo++;
|
|
492
|
+
}
|
|
493
|
+
const messageId = __classPrivateFieldSet(this, _Client_lastMsgId, (0, _0_message_js_1.getMessageId)(__classPrivateFieldGet(this, _Client_lastMsgId, "f")), "f");
|
|
494
|
+
const message = new _2_tl_js_1.Message_(messageId, seqNo, function_);
|
|
495
|
+
await this.transport.transport.send(await (0, _0_message_js_1.encryptMessage)(message, __classPrivateFieldGet(this, _Client_auth, "f").key, __classPrivateFieldGet(this, _Client_auth, "f").id, __classPrivateFieldGet(this, _Client_state, "f").salt, __classPrivateFieldGet(this, _Client_sessionId, "f")));
|
|
496
|
+
__classPrivateFieldSet(this, _Client_lastOutgoing, new Date(), "f");
|
|
497
|
+
d("invoked %s", function_.constructor.name);
|
|
498
|
+
if (noWait) {
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
let result;
|
|
502
|
+
try {
|
|
503
|
+
result = await new Promise((resolve, reject) => {
|
|
504
|
+
__classPrivateFieldGet(this, _Client_promises, "f").set(message.id, { resolve, reject });
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
catch (err) {
|
|
508
|
+
if (err instanceof _4_errors_js_1.AuthKeyUnregistered) {
|
|
509
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateAuthorizationState).call(this, false);
|
|
510
|
+
}
|
|
511
|
+
throw err;
|
|
512
|
+
}
|
|
513
|
+
if (result instanceof _2_tl_js_1.types.BadServerSalt) {
|
|
514
|
+
return await this.invoke(function_);
|
|
515
|
+
}
|
|
516
|
+
else {
|
|
517
|
+
if (!__classPrivateFieldGet(this, _Client_pingLoopStarted, "f")) {
|
|
518
|
+
(0, _1_utilities_js_1.drop)(__classPrivateFieldGet(this, _Client_instances, "m", _Client_pingLoop).call(this));
|
|
519
|
+
__classPrivateFieldSet(this, _Client_pingLoopStarted, true, "f");
|
|
520
|
+
}
|
|
521
|
+
return result;
|
|
522
|
+
}
|
|
554
523
|
}
|
|
555
524
|
catch (err) {
|
|
556
|
-
if (
|
|
525
|
+
if (__classPrivateFieldGet(this, _Client_errorHandler, "f") === undefined) {
|
|
526
|
+
throw err;
|
|
527
|
+
}
|
|
528
|
+
if (__classPrivateFieldGet(this, _Client_errorHandler, "f") !== undefined && await __classPrivateFieldGet(this, _Client_errorHandler, "f").call(this, err, function_, n++)) {
|
|
557
529
|
continue;
|
|
558
530
|
}
|
|
559
531
|
else {
|
|
@@ -563,42 +535,85 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
563
535
|
}
|
|
564
536
|
}
|
|
565
537
|
/**
|
|
566
|
-
*
|
|
538
|
+
* Alias for `invoke` with its second parameter being `true`.
|
|
567
539
|
*/
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
540
|
+
send(function_) {
|
|
541
|
+
return this.invoke(function_, true);
|
|
542
|
+
}
|
|
543
|
+
async checkGap(pts, ptsCount, assertNoGap) {
|
|
544
|
+
const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
|
|
545
|
+
if (localState.pts + ptsCount < pts) {
|
|
546
|
+
if (assertNoGap) {
|
|
547
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
548
|
+
}
|
|
549
|
+
else {
|
|
550
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverUpdateGap).call(this, "processUpdates");
|
|
551
|
+
}
|
|
576
552
|
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
553
|
+
}
|
|
554
|
+
async getUserAccessHash(userId) {
|
|
555
|
+
const users = await this.invoke(new _2_tl_js_1.functions.UsersGetUsers({ id: [new _2_tl_js_1.types.InputUser({ userId, accessHash: 0n })] }));
|
|
556
|
+
return users[0][_2_tl_js_1.as](_2_tl_js_1.types.User).accessHash ?? 0n;
|
|
557
|
+
}
|
|
558
|
+
async getInputPeer(id) {
|
|
559
|
+
const inputPeer = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getInputPeerInner).call(this, id);
|
|
560
|
+
if (inputPeer instanceof _2_tl_js_1.types.InputPeerUser || inputPeer instanceof _2_tl_js_1.types.InputPeerChannel && inputPeer.accessHash == 0n && await this.storage.getAccountType() == "bot") {
|
|
561
|
+
if ("channelId" in inputPeer) {
|
|
562
|
+
inputPeer.accessHash = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChannelAccessHash).call(this, inputPeer.channelId);
|
|
563
|
+
}
|
|
564
|
+
else {
|
|
565
|
+
inputPeer.accessHash = await this.getUserAccessHash(inputPeer.userId);
|
|
566
|
+
await this.storage.setUserAccessHash(inputPeer.userId, inputPeer.accessHash);
|
|
580
567
|
}
|
|
581
568
|
}
|
|
582
|
-
|
|
569
|
+
return inputPeer;
|
|
583
570
|
}
|
|
584
|
-
async
|
|
585
|
-
if (!this
|
|
571
|
+
[(_Client_initConnection = async function _Client_initConnection() {
|
|
572
|
+
if (!__classPrivateFieldGet(this, _Client_connectionInited, "f")) {
|
|
573
|
+
await this.invoke(new _2_tl_js_1.functions.InitConnection({
|
|
574
|
+
apiId: this.apiId,
|
|
575
|
+
appVersion: this.appVersion,
|
|
576
|
+
deviceModel: this.deviceModel,
|
|
577
|
+
langCode: this.langCode,
|
|
578
|
+
langPack: this.langPack,
|
|
579
|
+
query: new _2_tl_js_1.functions.InvokeWithLayer({
|
|
580
|
+
layer: _4_constants_js_1.LAYER,
|
|
581
|
+
query: new _2_tl_js_1.functions.HelpGetConfig(),
|
|
582
|
+
}),
|
|
583
|
+
systemLangCode: this.systemLangCode,
|
|
584
|
+
systemVersion: this.systemVersion,
|
|
585
|
+
}));
|
|
586
|
+
__classPrivateFieldSet(this, _Client_connectionInited, true, "f");
|
|
587
|
+
d("connection inited");
|
|
588
|
+
}
|
|
589
|
+
}, _Client_propagateAuthorizationState = async function _Client_propagateAuthorizationState(authorized) {
|
|
590
|
+
if (__classPrivateFieldGet(this, _Client_lastPropagatedAuthorizationState, "f") != authorized) {
|
|
591
|
+
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, { authorizationState: { authorized } }, _0_utilities_js_1.resolve);
|
|
592
|
+
__classPrivateFieldSet(this, _Client_lastPropagatedAuthorizationState, authorized, "f");
|
|
593
|
+
}
|
|
594
|
+
}, _Client_getSelfId = async function _Client_getSelfId() {
|
|
595
|
+
if (__classPrivateFieldGet(this, _Client_selfId, "f") == null) {
|
|
596
|
+
__classPrivateFieldSet(this, _Client_selfId, await this.getMe().then((v) => v.id), "f");
|
|
597
|
+
}
|
|
598
|
+
return __classPrivateFieldGet(this, _Client_selfId, "f");
|
|
599
|
+
}, _Client_receiveLoop = async function _Client_receiveLoop() {
|
|
600
|
+
if (!__classPrivateFieldGet(this, _Client_auth, "f") || !this.transport) {
|
|
586
601
|
throw new ConnectionError("Not connected");
|
|
587
602
|
}
|
|
588
603
|
while (this.connected) {
|
|
589
604
|
try {
|
|
590
|
-
if (this.
|
|
591
|
-
await this.send(new _2_tl_js_1.types.MsgsAck({ msgIds: [...this
|
|
592
|
-
this.
|
|
605
|
+
if (__classPrivateFieldGet(this, _Client_toAcknowledge, "f").size >= _4_constants_js_1.ACK_THRESHOLD) {
|
|
606
|
+
await this.send(new _2_tl_js_1.types.MsgsAck({ msgIds: [...__classPrivateFieldGet(this, _Client_toAcknowledge, "f")] }));
|
|
607
|
+
__classPrivateFieldGet(this, _Client_toAcknowledge, "f").clear();
|
|
593
608
|
}
|
|
594
609
|
const buffer = await this.transport.transport.receive();
|
|
595
610
|
let decrypted;
|
|
596
611
|
try {
|
|
597
|
-
decrypted = await ((0, _0_message_js_1.decryptMessage)(buffer, this.
|
|
612
|
+
decrypted = await ((0, _0_message_js_1.decryptMessage)(buffer, __classPrivateFieldGet(this, _Client_auth, "f").key, __classPrivateFieldGet(this, _Client_auth, "f").id, __classPrivateFieldGet(this, _Client_sessionId, "f")));
|
|
598
613
|
}
|
|
599
614
|
catch (err) {
|
|
600
615
|
dRecv("failed to decrypt message: %o", err);
|
|
601
|
-
(0, _1_utilities_js_1.drop)(this.
|
|
616
|
+
(0, _1_utilities_js_1.drop)(__classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverUpdateGap).call(this, "decryption"));
|
|
602
617
|
continue;
|
|
603
618
|
}
|
|
604
619
|
const messages = decrypted instanceof _2_tl_js_1.MessageContainer ? decrypted.messages : [decrypted];
|
|
@@ -609,10 +624,11 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
609
624
|
}
|
|
610
625
|
dRecv("received %s", body.constructor.name);
|
|
611
626
|
if (body instanceof _2_tl_js_1.types._TypeUpdates || body instanceof _2_tl_js_1.types._TypeUpdate) {
|
|
612
|
-
this.
|
|
627
|
+
__classPrivateFieldGet(this, _Client_processUpdatesQueue, "f").add(() => __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, body));
|
|
613
628
|
}
|
|
614
629
|
else if (body instanceof _2_tl_js_1.types.NewSessionCreated) {
|
|
615
|
-
this.
|
|
630
|
+
__classPrivateFieldGet(this, _Client_state, "f").salt = body.serverSalt;
|
|
631
|
+
await this.storage.setServerSalt(__classPrivateFieldGet(this, _Client_state, "f").salt);
|
|
616
632
|
}
|
|
617
633
|
else if (message.body instanceof _2_tl_js_1.RPCResult) {
|
|
618
634
|
let result = message.body.result;
|
|
@@ -627,7 +643,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
627
643
|
}
|
|
628
644
|
const messageId = message.body.messageId;
|
|
629
645
|
const resolvePromise = () => {
|
|
630
|
-
const promise = this.
|
|
646
|
+
const promise = __classPrivateFieldGet(this, _Client_promises, "f").get(messageId);
|
|
631
647
|
if (promise) {
|
|
632
648
|
if (result instanceof _2_tl_js_1.types.RPCError) {
|
|
633
649
|
promise.reject((0, _4_errors_js_1.upgradeInstance)(result));
|
|
@@ -635,12 +651,12 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
635
651
|
else {
|
|
636
652
|
promise.resolve(result);
|
|
637
653
|
}
|
|
638
|
-
this.
|
|
654
|
+
__classPrivateFieldGet(this, _Client_promises, "f").delete(messageId);
|
|
639
655
|
}
|
|
640
656
|
};
|
|
641
657
|
if (result instanceof _2_tl_js_1.types._TypeUpdates || result instanceof _2_tl_js_1.types._TypeUpdate) {
|
|
642
|
-
this.
|
|
643
|
-
await this.
|
|
658
|
+
__classPrivateFieldGet(this, _Client_processUpdatesQueue, "f").add(async () => {
|
|
659
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, result);
|
|
644
660
|
resolvePromise();
|
|
645
661
|
});
|
|
646
662
|
}
|
|
@@ -650,22 +666,23 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
650
666
|
}
|
|
651
667
|
}
|
|
652
668
|
else if (message.body instanceof _2_tl_js_1.types.Pong) {
|
|
653
|
-
const promise = this.
|
|
669
|
+
const promise = __classPrivateFieldGet(this, _Client_promises, "f").get(message.body.msgId);
|
|
654
670
|
if (promise) {
|
|
655
671
|
promise.resolve(message.body);
|
|
656
|
-
this.
|
|
672
|
+
__classPrivateFieldGet(this, _Client_promises, "f").delete(message.body.msgId);
|
|
657
673
|
}
|
|
658
674
|
}
|
|
659
675
|
else if (message.body instanceof _2_tl_js_1.types.BadServerSalt) {
|
|
660
676
|
d("server salt reassigned");
|
|
661
|
-
this.
|
|
662
|
-
|
|
677
|
+
__classPrivateFieldGet(this, _Client_state, "f").salt = message.body.newServerSalt;
|
|
678
|
+
await this.storage.setServerSalt(__classPrivateFieldGet(this, _Client_state, "f").salt);
|
|
679
|
+
const promise = __classPrivateFieldGet(this, _Client_promises, "f").get(message.body.badMsgId);
|
|
663
680
|
if (promise) {
|
|
664
681
|
promise.resolve(message.body);
|
|
665
|
-
this.
|
|
682
|
+
__classPrivateFieldGet(this, _Client_promises, "f").delete(message.body.badMsgId);
|
|
666
683
|
}
|
|
667
684
|
}
|
|
668
|
-
this.
|
|
685
|
+
__classPrivateFieldGet(this, _Client_toAcknowledge, "f").add(message.id);
|
|
669
686
|
}
|
|
670
687
|
}
|
|
671
688
|
catch (err) {
|
|
@@ -674,7 +691,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
674
691
|
}
|
|
675
692
|
else if (err instanceof _2_tl_js_1.TLError) {
|
|
676
693
|
dRecv("failed to deserialize: %o", err);
|
|
677
|
-
(0, _1_utilities_js_1.drop)(this.
|
|
694
|
+
(0, _1_utilities_js_1.drop)(__classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverUpdateGap).call(this, "deserialize"));
|
|
678
695
|
}
|
|
679
696
|
else {
|
|
680
697
|
dRecv("uncaught error: %o", err);
|
|
@@ -682,95 +699,27 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
682
699
|
}
|
|
683
700
|
}
|
|
684
701
|
if (!this.connected) {
|
|
685
|
-
for (const { reject } of this.
|
|
702
|
+
for (const { reject } of __classPrivateFieldGet(this, _Client_promises, "f").values()) {
|
|
686
703
|
reject(new ConnectionError("Connection was closed"));
|
|
687
704
|
}
|
|
688
705
|
}
|
|
689
706
|
else {
|
|
690
707
|
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
691
708
|
}
|
|
692
|
-
}
|
|
693
|
-
async pingLoop() {
|
|
709
|
+
}, _Client_pingLoop = async function _Client_pingLoop() {
|
|
694
710
|
while (this.connected) {
|
|
695
|
-
try {
|
|
696
|
-
await this.invoke(new _2_tl_js_1.functions.Ping({ pingId: (0, _1_utilities_js_1.getRandomBigInt)(8, true, false) }));
|
|
697
|
-
}
|
|
698
|
-
catch (err) {
|
|
699
|
-
d("ping loop error: %o", err);
|
|
700
|
-
}
|
|
701
711
|
await new Promise((r) => setTimeout(r, 60 * 1000));
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
async invoke(function_, noWait) {
|
|
705
|
-
if (!this.auth || !this.transport) {
|
|
706
|
-
if (this.autoStart && !this.autoStarted) {
|
|
707
|
-
await this.start();
|
|
708
|
-
}
|
|
709
|
-
else {
|
|
710
|
-
throw new ConnectionError("Not connected");
|
|
712
|
+
if (!__classPrivateFieldGet(this, _Client_lastOutgoing, "f") || (Date.now() - __classPrivateFieldGet(this, _Client_lastOutgoing, "f").getTime() < 60 * 1000)) {
|
|
713
|
+
continue;
|
|
711
714
|
}
|
|
712
|
-
}
|
|
713
|
-
if (!this.auth || !this.transport) {
|
|
714
|
-
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
715
|
-
}
|
|
716
|
-
let n = 1;
|
|
717
|
-
while (true) {
|
|
718
715
|
try {
|
|
719
|
-
|
|
720
|
-
if (!(function_ instanceof _2_tl_js_1.functions.Ping) && !(function_ instanceof _2_tl_js_1.types.MsgsAck)) {
|
|
721
|
-
seqNo++;
|
|
722
|
-
this.state.seqNo++;
|
|
723
|
-
}
|
|
724
|
-
const messageId = this.lastMsgId = (0, _0_message_js_1.getMessageId)(this.lastMsgId);
|
|
725
|
-
const message = new _2_tl_js_1.Message_(messageId, seqNo, function_);
|
|
726
|
-
await this.transport.transport.send(await (0, _0_message_js_1.encryptMessage)(message, this.auth.key, this.auth.id, this.state.salt, this.sessionId));
|
|
727
|
-
d("invoked %s", function_.constructor.name);
|
|
728
|
-
if (noWait) {
|
|
729
|
-
return;
|
|
730
|
-
}
|
|
731
|
-
let result;
|
|
732
|
-
try {
|
|
733
|
-
result = await new Promise((resolve, reject) => {
|
|
734
|
-
this.promises.set(message.id, { resolve, reject });
|
|
735
|
-
});
|
|
736
|
-
}
|
|
737
|
-
catch (err) {
|
|
738
|
-
if (err instanceof _4_errors_js_1.AuthKeyUnregistered) {
|
|
739
|
-
await this.propagateAuthorizationState(false);
|
|
740
|
-
}
|
|
741
|
-
throw err;
|
|
742
|
-
}
|
|
743
|
-
if (result instanceof _2_tl_js_1.types.BadServerSalt) {
|
|
744
|
-
return await this.invoke(function_);
|
|
745
|
-
}
|
|
746
|
-
else {
|
|
747
|
-
if (!this.pingLoopStarted) {
|
|
748
|
-
(0, _1_utilities_js_1.drop)(this.pingLoop());
|
|
749
|
-
this.pingLoopStarted = true;
|
|
750
|
-
}
|
|
751
|
-
return result;
|
|
752
|
-
}
|
|
716
|
+
await this.invoke(new _2_tl_js_1.functions.Ping({ pingId: (0, _1_utilities_js_1.getRandomBigInt)(8, true, false) }));
|
|
753
717
|
}
|
|
754
718
|
catch (err) {
|
|
755
|
-
|
|
756
|
-
throw err;
|
|
757
|
-
}
|
|
758
|
-
if (this.errorHandler !== undefined && await this.errorHandler(err, function_, n++)) {
|
|
759
|
-
continue;
|
|
760
|
-
}
|
|
761
|
-
else {
|
|
762
|
-
throw err;
|
|
763
|
-
}
|
|
719
|
+
d("ping loop error: %o", err);
|
|
764
720
|
}
|
|
765
721
|
}
|
|
766
|
-
}
|
|
767
|
-
/**
|
|
768
|
-
* Alias for `invoke` with its second parameter being `true`.
|
|
769
|
-
*/
|
|
770
|
-
send(function_) {
|
|
771
|
-
return this.invoke(function_, true);
|
|
772
|
-
}
|
|
773
|
-
async processChats(chats) {
|
|
722
|
+
}, _Client_processChats = async function _Client_processChats(chats) {
|
|
774
723
|
for (const chat of chats) {
|
|
775
724
|
if (chat instanceof _2_tl_js_1.types.Channel && chat.accessHash) {
|
|
776
725
|
await this.storage.setEntity(chat);
|
|
@@ -786,8 +735,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
786
735
|
await this.storage.setEntity(chat);
|
|
787
736
|
}
|
|
788
737
|
}
|
|
789
|
-
}
|
|
790
|
-
async processUsers(users) {
|
|
738
|
+
}, _Client_processUsers = async function _Client_processUsers(users) {
|
|
791
739
|
for (const user of users) {
|
|
792
740
|
if (user instanceof _2_tl_js_1.types.User && user.accessHash) {
|
|
793
741
|
await this.storage.setEntity(user);
|
|
@@ -800,19 +748,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
800
748
|
}
|
|
801
749
|
}
|
|
802
750
|
}
|
|
803
|
-
}
|
|
804
|
-
async checkGap(pts, ptsCount, assertNoGap) {
|
|
805
|
-
const localState = await this.getLocalState();
|
|
806
|
-
if (localState.pts + ptsCount < pts) {
|
|
807
|
-
if (assertNoGap) {
|
|
808
|
-
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
809
|
-
}
|
|
810
|
-
else {
|
|
811
|
-
await this.recoverUpdateGap("processUpdates");
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
async checkChannelGap(channelId, pts, ptsCount, assertNoGap) {
|
|
751
|
+
}, _Client_checkChannelGap = async function _Client_checkChannelGap(channelId, pts, ptsCount, assertNoGap) {
|
|
816
752
|
let localPts = await this.storage.getChannelPts(channelId);
|
|
817
753
|
if (!localPts) {
|
|
818
754
|
localPts = pts - ptsCount;
|
|
@@ -822,11 +758,10 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
822
758
|
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
823
759
|
}
|
|
824
760
|
else {
|
|
825
|
-
await this.
|
|
761
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverChannelUpdateGap).call(this, channelId, "processUpdates");
|
|
826
762
|
}
|
|
827
763
|
}
|
|
828
|
-
}
|
|
829
|
-
async processUpdates(updates_, assertNoGap = false) {
|
|
764
|
+
}, _Client_processUpdates = async function _Client_processUpdates(updates_, assertNoGap = false) {
|
|
830
765
|
/// First, individual updates (Update[1]) and updateShort* are extracted from Updates.[2]
|
|
831
766
|
///
|
|
832
767
|
/// If an updatesTooLong[3] was received, an update gap recovery is initiated and no further action will be taken.
|
|
@@ -847,7 +782,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
847
782
|
updates = [updates_];
|
|
848
783
|
}
|
|
849
784
|
else if (updates_ instanceof _2_tl_js_1.types.UpdatesTooLong) {
|
|
850
|
-
await this.
|
|
785
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverUpdateGap).call(this, "updatesTooLong");
|
|
851
786
|
return;
|
|
852
787
|
}
|
|
853
788
|
else if (updates_ instanceof _2_tl_js_1.types._TypeUpdate) {
|
|
@@ -869,7 +804,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
869
804
|
continue;
|
|
870
805
|
}
|
|
871
806
|
await this.checkGap(update.pts, update.ptsCount, assertNoGap);
|
|
872
|
-
localState ??= await this.
|
|
807
|
+
localState ??= await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
|
|
873
808
|
originalPts ??= localState.pts;
|
|
874
809
|
if (localState.pts + update.ptsCount > update.pts) {
|
|
875
810
|
updates = updates.filter((v) => v != update);
|
|
@@ -882,9 +817,9 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
882
817
|
if (update.pts == 0) {
|
|
883
818
|
continue;
|
|
884
819
|
}
|
|
885
|
-
const ptsCount =
|
|
820
|
+
const ptsCount = update.ptsCount;
|
|
886
821
|
const channelId = update instanceof _2_tl_js_1.types.UpdateNewChannelMessage || update instanceof _2_tl_js_1.types.UpdateEditChannelMessage ? update.message.peerId[_2_tl_js_1.as](_2_tl_js_1.types.PeerChannel).channelId : update.channelId;
|
|
887
|
-
await this.
|
|
822
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_checkChannelGap).call(this, channelId, update.pts, ptsCount, assertNoGap);
|
|
888
823
|
let currentPts = channelPtsMap.get(channelId);
|
|
889
824
|
if (currentPts === undefined) {
|
|
890
825
|
currentPts = await this.storage.getChannelPts(channelId);
|
|
@@ -908,33 +843,33 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
908
843
|
}
|
|
909
844
|
/// We process the updates when we are sure there is no gap.
|
|
910
845
|
if (updates_ instanceof _2_tl_js_1.types.Updates || updates_ instanceof _2_tl_js_1.types.UpdatesCombined) {
|
|
911
|
-
await this.
|
|
912
|
-
await this.
|
|
913
|
-
await this.
|
|
846
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, updates_.chats);
|
|
847
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, updates_.users);
|
|
848
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdateStateDate).call(this, updates_.date);
|
|
914
849
|
}
|
|
915
850
|
else if (updates_ instanceof _2_tl_js_1.types.UpdateShort) {
|
|
916
|
-
await this.
|
|
851
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdateStateDate).call(this, updates_.date);
|
|
917
852
|
}
|
|
918
853
|
const updatesToHandle = new Array();
|
|
919
854
|
for (const update of updates) {
|
|
920
855
|
if (update instanceof _2_tl_js_1.types.UpdateShortMessage ||
|
|
921
856
|
update instanceof _2_tl_js_1.types.UpdateShortChatMessage ||
|
|
922
857
|
update instanceof _2_tl_js_1.types.UpdateShortSentMessage) {
|
|
923
|
-
await this.
|
|
858
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdateStateDate).call(this, update.date);
|
|
924
859
|
}
|
|
925
860
|
else if (update instanceof _2_tl_js_1.types.UpdateChannelTooLong) {
|
|
926
861
|
if (update.pts != undefined) {
|
|
927
862
|
await this.storage.setChannelPts(update.channelId, update.pts);
|
|
928
863
|
}
|
|
929
|
-
await this.
|
|
864
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverChannelUpdateGap).call(this, update.channelId, "updateChannelTooLong");
|
|
930
865
|
}
|
|
931
866
|
else if (update instanceof _2_tl_js_1.types.UpdateUserName) {
|
|
932
867
|
await this.storage.updateUsernames("user", update.userId, update.usernames.map((v) => v.username));
|
|
933
868
|
}
|
|
934
869
|
else if (update instanceof _2_tl_js_1.types.UpdatePtsChanged) {
|
|
935
|
-
await this.
|
|
936
|
-
if (this
|
|
937
|
-
await this.storage.setState(this
|
|
870
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchState).call(this, "updatePtsChanged");
|
|
871
|
+
if (__classPrivateFieldGet(this, _Client_updateState, "f")) {
|
|
872
|
+
await this.storage.setState(__classPrivateFieldGet(this, _Client_updateState, "f"));
|
|
938
873
|
}
|
|
939
874
|
else {
|
|
940
875
|
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
@@ -945,28 +880,26 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
945
880
|
updatesToHandle.push(update);
|
|
946
881
|
}
|
|
947
882
|
}
|
|
948
|
-
this.
|
|
883
|
+
__classPrivateFieldGet(this, _Client_handleUpdateQueue, "f").add(async () => {
|
|
949
884
|
for (const update of updatesToHandle) {
|
|
950
|
-
await this.
|
|
885
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleUpdate).call(this, update);
|
|
951
886
|
}
|
|
952
887
|
});
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
const localState = await this.getLocalState();
|
|
888
|
+
}, _Client_setUpdateStateDate = async function _Client_setUpdateStateDate(date) {
|
|
889
|
+
const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
|
|
956
890
|
localState.date = date;
|
|
957
891
|
await this.storage.setState(localState);
|
|
958
|
-
}
|
|
959
|
-
async getLocalState() {
|
|
892
|
+
}, _Client_getLocalState = async function _Client_getLocalState() {
|
|
960
893
|
let localState = await this.storage.getState();
|
|
961
894
|
if (!localState) {
|
|
962
|
-
if (this
|
|
963
|
-
localState = this
|
|
895
|
+
if (__classPrivateFieldGet(this, _Client_updateState, "f")) {
|
|
896
|
+
localState = __classPrivateFieldGet(this, _Client_updateState, "f");
|
|
964
897
|
await this.storage.setState(localState);
|
|
965
898
|
}
|
|
966
899
|
else {
|
|
967
|
-
await this.
|
|
968
|
-
if (this
|
|
969
|
-
localState = this
|
|
900
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchState).call(this, "getLocalState");
|
|
901
|
+
if (__classPrivateFieldGet(this, _Client_updateState, "f")) {
|
|
902
|
+
localState = __classPrivateFieldGet(this, _Client_updateState, "f");
|
|
970
903
|
await this.storage.setState(localState);
|
|
971
904
|
}
|
|
972
905
|
else {
|
|
@@ -975,22 +908,21 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
975
908
|
}
|
|
976
909
|
}
|
|
977
910
|
return localState;
|
|
978
|
-
}
|
|
979
|
-
async recoverUpdateGap(source) {
|
|
911
|
+
}, _Client_recoverUpdateGap = async function _Client_recoverUpdateGap(source) {
|
|
980
912
|
dGap("recovering from update gap [%s]", source);
|
|
981
|
-
await this.
|
|
913
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateConnectionState).call(this, "updating");
|
|
982
914
|
try {
|
|
983
|
-
let state = await this.
|
|
915
|
+
let state = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
|
|
984
916
|
while (true) {
|
|
985
917
|
const difference = await this.invoke(new _2_tl_js_1.functions.UpdatesGetDifference({ pts: state.pts, date: state.date, qts: state.qts ?? 0 }));
|
|
986
918
|
if (difference instanceof _2_tl_js_1.types.UpdatesDifference || difference instanceof _2_tl_js_1.types.UpdatesDifferenceSlice) {
|
|
987
|
-
await this.
|
|
988
|
-
await this.
|
|
919
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, difference.chats);
|
|
920
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, difference.users);
|
|
989
921
|
for (const message of difference.newMessages) {
|
|
990
|
-
await this.
|
|
922
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, new _2_tl_js_1.types.UpdateNewMessage({ message, pts: 0, ptsCount: 0 }), true);
|
|
991
923
|
}
|
|
992
924
|
for (const update of difference.otherUpdates) {
|
|
993
|
-
await this.
|
|
925
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, update, true);
|
|
994
926
|
}
|
|
995
927
|
if (difference instanceof _2_tl_js_1.types.UpdatesDifference) {
|
|
996
928
|
await this.storage.setState(difference.state);
|
|
@@ -1010,7 +942,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1010
942
|
dGap("received differenceTooLong");
|
|
1011
943
|
}
|
|
1012
944
|
else if (difference instanceof _2_tl_js_1.types.UpdatesDifferenceEmpty) {
|
|
1013
|
-
await this.
|
|
945
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdateStateDate).call(this, difference.date);
|
|
1014
946
|
dGap("there was no update gap");
|
|
1015
947
|
break;
|
|
1016
948
|
}
|
|
@@ -1022,8 +954,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1022
954
|
finally {
|
|
1023
955
|
this.stateChangeHandler(this.connected);
|
|
1024
956
|
}
|
|
1025
|
-
}
|
|
1026
|
-
async recoverChannelUpdateGap(channelId, source) {
|
|
957
|
+
}, _Client_recoverChannelUpdateGap = async function _Client_recoverChannelUpdateGap(channelId, source) {
|
|
1027
958
|
dGapC("recovering channel update gap [%o, %s]", channelId, source);
|
|
1028
959
|
const pts_ = await this.storage.getChannelPts(channelId);
|
|
1029
960
|
let pts = pts_ == null ? 1 : pts_;
|
|
@@ -1036,13 +967,13 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1036
967
|
limit: await this.storage.getAccountType() == "user" ? _4_constants_js_1.CHANNEL_DIFFERENCE_LIMIT_USER : _4_constants_js_1.CHANNEL_DIFFERENCE_LIMIT_BOT,
|
|
1037
968
|
}));
|
|
1038
969
|
if (difference instanceof _2_tl_js_1.types.UpdatesChannelDifference) {
|
|
1039
|
-
await this.
|
|
1040
|
-
await this.
|
|
970
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, difference.chats);
|
|
971
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, difference.users);
|
|
1041
972
|
for (const message of difference.newMessages) {
|
|
1042
|
-
await this.
|
|
973
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, new _2_tl_js_1.types.UpdateNewChannelMessage({ message, pts: 0, ptsCount: 0 }), true);
|
|
1043
974
|
}
|
|
1044
975
|
for (const update of difference.otherUpdates) {
|
|
1045
|
-
await this.
|
|
976
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, update, true);
|
|
1046
977
|
}
|
|
1047
978
|
await this.storage.setChannelPts(channelId, difference.pts);
|
|
1048
979
|
dGapC("recovered from update gap [%o, %s]", channelId, source);
|
|
@@ -1051,10 +982,10 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1051
982
|
else if (difference instanceof _2_tl_js_1.types.UpdatesChannelDifferenceTooLong) {
|
|
1052
983
|
// invalidate messages
|
|
1053
984
|
dGapC("received channelDifferenceTooLong");
|
|
1054
|
-
await this.
|
|
1055
|
-
await this.
|
|
985
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, difference.chats);
|
|
986
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, difference.users);
|
|
1056
987
|
for (const message of difference.messages) {
|
|
1057
|
-
await this.
|
|
988
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, new _2_tl_js_1.types.UpdateNewChannelMessage({ message, pts: 0, ptsCount: 0 }), true);
|
|
1058
989
|
}
|
|
1059
990
|
const pts_ = difference.dialog[_2_tl_js_1.as](_2_tl_js_1.types.Dialog).pts;
|
|
1060
991
|
if (pts_ != undefined) {
|
|
@@ -1070,29 +1001,10 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1070
1001
|
break;
|
|
1071
1002
|
}
|
|
1072
1003
|
}
|
|
1073
|
-
}
|
|
1074
|
-
async getUserAccessHash(userId) {
|
|
1075
|
-
const users = await this.invoke(new _2_tl_js_1.functions.UsersGetUsers({ id: [new _2_tl_js_1.types.InputUser({ userId, accessHash: 0n })] }));
|
|
1076
|
-
return users[0][_2_tl_js_1.as](_2_tl_js_1.types.User).accessHash ?? 0n;
|
|
1077
|
-
}
|
|
1078
|
-
async getChannelAccessHash(channelId) {
|
|
1004
|
+
}, _Client_getChannelAccessHash = async function _Client_getChannelAccessHash(channelId) {
|
|
1079
1005
|
const channels = await this.invoke(new _2_tl_js_1.functions.ChannelsGetChannels({ id: [new _2_tl_js_1.types.InputChannel({ channelId, accessHash: 0n })] }));
|
|
1080
1006
|
return channels.chats[0][_2_tl_js_1.as](_2_tl_js_1.types.Channel).accessHash ?? 0n;
|
|
1081
|
-
}
|
|
1082
|
-
async getInputPeer(id) {
|
|
1083
|
-
const inputPeer = await this.getInputPeerInner(id);
|
|
1084
|
-
if (inputPeer instanceof _2_tl_js_1.types.InputPeerUser || inputPeer instanceof _2_tl_js_1.types.InputPeerChannel && inputPeer.accessHash == 0n && await this.storage.getAccountType() == "bot") {
|
|
1085
|
-
if ("channelId" in inputPeer) {
|
|
1086
|
-
inputPeer.accessHash = await this.getChannelAccessHash(inputPeer.channelId);
|
|
1087
|
-
}
|
|
1088
|
-
else {
|
|
1089
|
-
inputPeer.accessHash = await this.getUserAccessHash(inputPeer.userId);
|
|
1090
|
-
await this.storage.setUserAccessHash(inputPeer.userId, inputPeer.accessHash);
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
return inputPeer;
|
|
1094
|
-
}
|
|
1095
|
-
async getInputPeerInner(id) {
|
|
1007
|
+
}, _Client_getInputPeerInner = async function _Client_getInputPeerInner(id) {
|
|
1096
1008
|
if (typeof id === "string") {
|
|
1097
1009
|
if (!id.startsWith("@")) {
|
|
1098
1010
|
throw new Error("Expected username to start with @");
|
|
@@ -1116,8 +1028,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1116
1028
|
}
|
|
1117
1029
|
else {
|
|
1118
1030
|
const resolved = await this.invoke(new _2_tl_js_1.functions.ContactsResolveUsername({ username: id }));
|
|
1119
|
-
await this.
|
|
1120
|
-
await this.
|
|
1031
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, resolved.chats);
|
|
1032
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, resolved.users);
|
|
1121
1033
|
if (resolved.peer instanceof _2_tl_js_1.types.PeerUser) {
|
|
1122
1034
|
userId = resolved.peer.userId;
|
|
1123
1035
|
}
|
|
@@ -1157,8 +1069,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1157
1069
|
else {
|
|
1158
1070
|
throw new Error("ID format unknown or not implemented");
|
|
1159
1071
|
}
|
|
1160
|
-
}
|
|
1161
|
-
[getEntity](peer) {
|
|
1072
|
+
}, getEntity)](peer) {
|
|
1162
1073
|
const type = peer instanceof _2_tl_js_1.types.PeerUser ? "user" : peer instanceof _2_tl_js_1.types.PeerChat ? "chat" : peer instanceof _2_tl_js_1.types.PeerChannel ? "channel" : (0, _1_utilities_js_1.UNREACHABLE)();
|
|
1163
1074
|
const id = peer instanceof _2_tl_js_1.types.PeerUser ? peer.userId : peer instanceof _2_tl_js_1.types.PeerChat ? peer.chatId : peer instanceof _2_tl_js_1.types.PeerChannel ? peer.channelId : (0, _1_utilities_js_1.UNREACHABLE)();
|
|
1164
1075
|
return this.storage.getEntity(type, id);
|
|
@@ -1200,9 +1111,9 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1200
1111
|
result instanceof _2_tl_js_1.types.ChatlistsChatlistUpdates ||
|
|
1201
1112
|
result instanceof _2_tl_js_1.types.MessagesChats ||
|
|
1202
1113
|
result instanceof _2_tl_js_1.types.MessagesChatsSlice) {
|
|
1203
|
-
await this.
|
|
1114
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, result.chats);
|
|
1204
1115
|
if ("users" in result) {
|
|
1205
|
-
await this.
|
|
1116
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, result.users);
|
|
1206
1117
|
}
|
|
1207
1118
|
}
|
|
1208
1119
|
if (result instanceof _2_tl_js_1.types.MessagesMessages) {
|
|
@@ -1213,33 +1124,6 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1213
1124
|
}
|
|
1214
1125
|
}
|
|
1215
1126
|
}
|
|
1216
|
-
async updatesToMessages(chatId, updates) {
|
|
1217
|
-
const messages = new Array();
|
|
1218
|
-
if (updates instanceof _2_tl_js_1.types.Updates) {
|
|
1219
|
-
for (const update of updates.updates) {
|
|
1220
|
-
if (update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateEditMessage) {
|
|
1221
|
-
messages.push(await (0, _3_types_js_1.constructMessage)(update.message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this)));
|
|
1222
|
-
}
|
|
1223
|
-
else if (update instanceof _2_tl_js_1.types.UpdateNewChannelMessage || update instanceof _2_tl_js_1.types.UpdateEditChannelMessage) {
|
|
1224
|
-
messages.push(await (0, _3_types_js_1.constructMessage)(update.message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this)));
|
|
1225
|
-
}
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
else if (updates instanceof _2_tl_js_1.types.UpdateShortSentMessage || updates instanceof _2_tl_js_1.types.UpdateShortSentMessage) {
|
|
1229
|
-
const message = await this.getMessage(chatId, updates.id);
|
|
1230
|
-
if (message != null) {
|
|
1231
|
-
messages.push(message);
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
1234
|
-
return messages;
|
|
1235
|
-
}
|
|
1236
|
-
async resolveSendAs(params) {
|
|
1237
|
-
const sendAs = params?.sendAs;
|
|
1238
|
-
if (sendAs !== undefined) {
|
|
1239
|
-
await this.assertUser("sendAs");
|
|
1240
|
-
return sendAs ? await this.getInputPeer(sendAs) : undefined;
|
|
1241
|
-
}
|
|
1242
|
-
}
|
|
1243
1127
|
/**
|
|
1244
1128
|
* Send a text message.
|
|
1245
1129
|
*
|
|
@@ -1249,8 +1133,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1249
1133
|
* @returns The sent text message.
|
|
1250
1134
|
*/
|
|
1251
1135
|
async sendMessage(chatId, text, params) {
|
|
1252
|
-
const [message, entities] = this.
|
|
1253
|
-
const replyMarkup = await this.
|
|
1136
|
+
const [message, entities] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_parseText).call(this, text, params);
|
|
1137
|
+
const replyMarkup = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params);
|
|
1254
1138
|
const peer = await this.getInputPeer(chatId);
|
|
1255
1139
|
const randomId = (0, _1_utilities_js_1.getRandomId)();
|
|
1256
1140
|
const noWebpage = params?.disableWebPagePreview ? true : undefined;
|
|
@@ -1258,7 +1142,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1258
1142
|
const noforwards = params?.protectContent ? true : undefined;
|
|
1259
1143
|
const replyToMsgId = params?.replyToMessageId;
|
|
1260
1144
|
const topMsgId = params?.messageThreadId;
|
|
1261
|
-
const sendAs = await this.
|
|
1145
|
+
const sendAs = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_resolveSendAs).call(this, params);
|
|
1262
1146
|
const result = await this.invoke(new _2_tl_js_1.functions.MessagesSendMessage({
|
|
1263
1147
|
peer,
|
|
1264
1148
|
randomId,
|
|
@@ -1271,28 +1155,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1271
1155
|
entities,
|
|
1272
1156
|
replyMarkup,
|
|
1273
1157
|
}));
|
|
1274
|
-
const message_ = await this.
|
|
1275
|
-
return Client.
|
|
1276
|
-
}
|
|
1277
|
-
parseText(text, params) {
|
|
1278
|
-
const entities_ = params?.entities ?? [];
|
|
1279
|
-
const parseMode = params?.parseMode ?? this.parseMode;
|
|
1280
|
-
switch (parseMode) {
|
|
1281
|
-
case null:
|
|
1282
|
-
break;
|
|
1283
|
-
case "HTML": {
|
|
1284
|
-
const [newText, entitiesToPush] = (0, _0_html_js_1.parseHtml)(text);
|
|
1285
|
-
text = newText;
|
|
1286
|
-
for (const entity of entitiesToPush) {
|
|
1287
|
-
entities_.push(entity);
|
|
1288
|
-
}
|
|
1289
|
-
break;
|
|
1290
|
-
}
|
|
1291
|
-
default:
|
|
1292
|
-
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
1293
|
-
}
|
|
1294
|
-
const entities = entities_?.length > 0 ? entities_.map((v) => (0, _3_types_js_1.messageEntityToTlObject)(v)) : undefined;
|
|
1295
|
-
return [text, entities];
|
|
1158
|
+
const message_ = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
|
|
1159
|
+
return __classPrivateFieldGet(Client, _a, "m", _Client_assertMsgHas).call(Client, message_, "text");
|
|
1296
1160
|
}
|
|
1297
1161
|
/**
|
|
1298
1162
|
* Edit a message's text.
|
|
@@ -1304,19 +1168,77 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1304
1168
|
* @returns The edited text message.
|
|
1305
1169
|
*/
|
|
1306
1170
|
async editMessageText(chatId, messageId, text, params) {
|
|
1307
|
-
const [message, entities] = this.
|
|
1171
|
+
const [message, entities] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_parseText).call(this, text, params);
|
|
1308
1172
|
const result = await this.invoke(new _2_tl_js_1.functions.MessagesEditMessage({
|
|
1309
1173
|
id: messageId,
|
|
1310
1174
|
peer: await this.getInputPeer(chatId),
|
|
1311
1175
|
entities,
|
|
1312
1176
|
message,
|
|
1313
1177
|
noWebpage: params?.disableWebPagePreview ? true : undefined,
|
|
1314
|
-
replyMarkup: await this.
|
|
1178
|
+
replyMarkup: await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params),
|
|
1315
1179
|
}));
|
|
1316
|
-
const message_ = await this.
|
|
1317
|
-
return Client.
|
|
1180
|
+
const message_ = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
|
|
1181
|
+
return __classPrivateFieldGet(Client, _a, "m", _Client_assertMsgHas).call(Client, message_, "text");
|
|
1182
|
+
}
|
|
1183
|
+
/**
|
|
1184
|
+
* Retrieve multiple messages.
|
|
1185
|
+
*
|
|
1186
|
+
* @method
|
|
1187
|
+
* @param chatId The identifier of the chat to retrieve the messages from.
|
|
1188
|
+
* @param messageIds The identifiers of the messages to retrieve.
|
|
1189
|
+
* @example ```ts
|
|
1190
|
+
* const message = await client.getMessages("@MTKruto", [210, 212]);
|
|
1191
|
+
* ```
|
|
1192
|
+
* @returns The retrieved messages.
|
|
1193
|
+
*/
|
|
1194
|
+
async getMessages(chatId, messageIds) {
|
|
1195
|
+
return await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getMessagesInner).call(this, chatId, messageIds).then((v) => v.map((v) => v.message));
|
|
1318
1196
|
}
|
|
1319
|
-
async
|
|
1197
|
+
async [(_Client_updatesToMessages = async function _Client_updatesToMessages(chatId, updates) {
|
|
1198
|
+
const messages = new Array();
|
|
1199
|
+
if (updates instanceof _2_tl_js_1.types.Updates) {
|
|
1200
|
+
for (const update of updates.updates) {
|
|
1201
|
+
if (update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateEditMessage) {
|
|
1202
|
+
messages.push(await (0, _3_types_js_1.constructMessage)(update.message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this)));
|
|
1203
|
+
}
|
|
1204
|
+
else if (update instanceof _2_tl_js_1.types.UpdateNewChannelMessage || update instanceof _2_tl_js_1.types.UpdateEditChannelMessage) {
|
|
1205
|
+
messages.push(await (0, _3_types_js_1.constructMessage)(update.message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this)));
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
else if (updates instanceof _2_tl_js_1.types.UpdateShortSentMessage || updates instanceof _2_tl_js_1.types.UpdateShortSentMessage) {
|
|
1210
|
+
const message = await this.getMessage(chatId, updates.id);
|
|
1211
|
+
if (message != null) {
|
|
1212
|
+
messages.push(message);
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
return messages;
|
|
1216
|
+
}, _Client_resolveSendAs = async function _Client_resolveSendAs(params) {
|
|
1217
|
+
const sendAs = params?.sendAs;
|
|
1218
|
+
if (sendAs !== undefined) {
|
|
1219
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertUser).call(this, "sendAs");
|
|
1220
|
+
return sendAs ? await this.getInputPeer(sendAs) : undefined;
|
|
1221
|
+
}
|
|
1222
|
+
}, _Client_parseText = function _Client_parseText(text, params) {
|
|
1223
|
+
const entities_ = params?.entities ?? [];
|
|
1224
|
+
const parseMode = params?.parseMode ?? this.parseMode;
|
|
1225
|
+
switch (parseMode) {
|
|
1226
|
+
case null:
|
|
1227
|
+
break;
|
|
1228
|
+
case "HTML": {
|
|
1229
|
+
const [newText, entitiesToPush] = (0, _0_html_js_1.parseHtml)(text);
|
|
1230
|
+
text = newText;
|
|
1231
|
+
for (const entity of entitiesToPush) {
|
|
1232
|
+
entities_.push(entity);
|
|
1233
|
+
}
|
|
1234
|
+
break;
|
|
1235
|
+
}
|
|
1236
|
+
default:
|
|
1237
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
1238
|
+
}
|
|
1239
|
+
const entities = entities_?.length > 0 ? entities_.map((v) => (0, _3_types_js_1.messageEntityToTlObject)(v)) : undefined;
|
|
1240
|
+
return [text, entities];
|
|
1241
|
+
}, _Client_getMessagesInner = async function _Client_getMessagesInner(chatId_, messageIds) {
|
|
1320
1242
|
const peer = await this.getInputPeer(chatId_);
|
|
1321
1243
|
let messages_ = new Array();
|
|
1322
1244
|
const chatId = (0, _2_tl_js_1.peerToChatId)(peer);
|
|
@@ -1352,23 +1274,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1352
1274
|
messages.push({ message, isReplyToMessage });
|
|
1353
1275
|
}
|
|
1354
1276
|
return messages;
|
|
1355
|
-
}
|
|
1356
|
-
|
|
1357
|
-
* Retrieve multiple messages.
|
|
1358
|
-
*
|
|
1359
|
-
* @method
|
|
1360
|
-
* @param chatId The identifier of the chat to retrieve the messages from.
|
|
1361
|
-
* @param messageIds The identifiers of the messages to retrieve.
|
|
1362
|
-
* @example ```ts
|
|
1363
|
-
* const message = await client.getMessages("@MTKruto", [210, 212]);
|
|
1364
|
-
* ```
|
|
1365
|
-
* @returns The retrieved messages.
|
|
1366
|
-
*/
|
|
1367
|
-
async getMessages(chatId, messageIds) {
|
|
1368
|
-
return await this.getMessagesInner(chatId, messageIds).then((v) => v.map((v) => v.message));
|
|
1369
|
-
}
|
|
1370
|
-
async [getMessageWithReply](chatId, messageId) {
|
|
1371
|
-
const messages = await this.getMessagesInner(chatId, [messageId]);
|
|
1277
|
+
}, getMessageWithReply)](chatId, messageId) {
|
|
1278
|
+
const messages = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getMessagesInner).call(this, chatId, [messageId]);
|
|
1372
1279
|
return messages[0]?.message ?? null;
|
|
1373
1280
|
}
|
|
1374
1281
|
/**
|
|
@@ -1386,7 +1293,44 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1386
1293
|
const messages = await this.getMessages(chatId, [messageId]);
|
|
1387
1294
|
return messages[0] ?? null;
|
|
1388
1295
|
}
|
|
1389
|
-
|
|
1296
|
+
/**
|
|
1297
|
+
* Download a file.
|
|
1298
|
+
*
|
|
1299
|
+
* @method
|
|
1300
|
+
* @param fileId The identifier of the file to download.
|
|
1301
|
+
* @example ```ts
|
|
1302
|
+
* for await (const chunk of client.download(fileId, { chunkSize: 256 * 1024 })) {
|
|
1303
|
+
* await outFile.write(chunk);
|
|
1304
|
+
* }
|
|
1305
|
+
* ```
|
|
1306
|
+
* @returns A generator yielding the contents of the file.
|
|
1307
|
+
*/
|
|
1308
|
+
async download(fileId, params) {
|
|
1309
|
+
const fileId_ = _3_types_js_1.FileID.decode(fileId);
|
|
1310
|
+
switch (fileId_.fileType) {
|
|
1311
|
+
case _3_types_js_1.FileType.ChatPhoto: {
|
|
1312
|
+
const big = fileId_.params.thumbnailSource == _3_types_js_1.ThumbnailSource.ChatPhotoBig;
|
|
1313
|
+
const peer = await this.getInputPeer(fileId_.params.chatId);
|
|
1314
|
+
const location = new _2_tl_js_1.types.InputPeerPhotoFileLocation({ big: big ? true : undefined, peer, photoId: fileId_.params.mediaId });
|
|
1315
|
+
return __classPrivateFieldGet(this, _Client_instances, "m", _Client_downloadInner).call(this, location, fileId_.dcId, params);
|
|
1316
|
+
}
|
|
1317
|
+
case _3_types_js_1.FileType.Photo: {
|
|
1318
|
+
if (fileId_.params.mediaId == undefined || fileId_.params.accessHash == undefined || fileId_.params.fileReference == undefined || fileId_.params.thumbnailSize == undefined) {
|
|
1319
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
1320
|
+
}
|
|
1321
|
+
const location = new _2_tl_js_1.types.InputPhotoFileLocation({
|
|
1322
|
+
id: fileId_.params.mediaId,
|
|
1323
|
+
accessHash: fileId_.params.accessHash,
|
|
1324
|
+
fileReference: fileId_.params.fileReference,
|
|
1325
|
+
thumbSize: fileId_.params.thumbnailSize,
|
|
1326
|
+
});
|
|
1327
|
+
return __classPrivateFieldGet(this, _Client_instances, "m", _Client_downloadInner).call(this, location, fileId_.dcId, params);
|
|
1328
|
+
}
|
|
1329
|
+
default:
|
|
1330
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
async [(_Client_downloadInner = async function* _Client_downloadInner(location, dcId, params) {
|
|
1390
1334
|
const chunkSize = params?.chunkSize ?? 1024 * 1024;
|
|
1391
1335
|
if ((0, _1_utilities_js_1.mod)(chunkSize, 1024) != 0) {
|
|
1392
1336
|
throw new Error("chunkSize must be divisible by 1024");
|
|
@@ -1426,45 +1370,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1426
1370
|
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
1427
1371
|
}
|
|
1428
1372
|
}
|
|
1429
|
-
}
|
|
1430
|
-
/**
|
|
1431
|
-
* Download a file.
|
|
1432
|
-
*
|
|
1433
|
-
* @method
|
|
1434
|
-
* @param fileId The identifier of the file to download.
|
|
1435
|
-
* @example ```ts
|
|
1436
|
-
* for await (const chunk of client.download(fileId, { chunkSize: 256 * 1024 })) {
|
|
1437
|
-
* await outFile.write(chunk);
|
|
1438
|
-
* }
|
|
1439
|
-
* ```
|
|
1440
|
-
* @returns A generator yielding the contents of the file.
|
|
1441
|
-
*/
|
|
1442
|
-
async download(fileId, params) {
|
|
1443
|
-
const fileId_ = _3_types_js_1.FileID.decode(fileId);
|
|
1444
|
-
switch (fileId_.fileType) {
|
|
1445
|
-
case _3_types_js_1.FileType.ChatPhoto: {
|
|
1446
|
-
const big = fileId_.params.thumbnailSource == _3_types_js_1.ThumbnailSource.ChatPhotoBig;
|
|
1447
|
-
const peer = await this.getInputPeer(fileId_.params.chatId);
|
|
1448
|
-
const location = new _2_tl_js_1.types.InputPeerPhotoFileLocation({ big: big ? true : undefined, peer, photoId: fileId_.params.mediaId });
|
|
1449
|
-
return this.downloadInner(location, fileId_.dcId, params);
|
|
1450
|
-
}
|
|
1451
|
-
case _3_types_js_1.FileType.Photo: {
|
|
1452
|
-
if (fileId_.params.mediaId == undefined || fileId_.params.accessHash == undefined || fileId_.params.fileReference == undefined || fileId_.params.thumbnailSize == undefined) {
|
|
1453
|
-
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
1454
|
-
}
|
|
1455
|
-
const location = new _2_tl_js_1.types.InputPhotoFileLocation({
|
|
1456
|
-
id: fileId_.params.mediaId,
|
|
1457
|
-
accessHash: fileId_.params.accessHash,
|
|
1458
|
-
fileReference: fileId_.params.fileReference,
|
|
1459
|
-
thumbSize: fileId_.params.thumbnailSize,
|
|
1460
|
-
});
|
|
1461
|
-
return this.downloadInner(location, fileId_.dcId, params);
|
|
1462
|
-
}
|
|
1463
|
-
default:
|
|
1464
|
-
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
1465
|
-
}
|
|
1466
|
-
}
|
|
1467
|
-
async [getStickerSetName](inputStickerSet, hash = 0) {
|
|
1373
|
+
}, getStickerSetName)](inputStickerSet, hash = 0) {
|
|
1468
1374
|
const maybeStickerSetName = await this.storage.getStickerSetName(inputStickerSet.id, inputStickerSet.accessHash);
|
|
1469
1375
|
if (maybeStickerSetName != null && Date.now() - maybeStickerSetName[1].getTime() < _4_constants_js_1.STICKER_SET_NAME_TTL) {
|
|
1470
1376
|
return maybeStickerSetName[0];
|
|
@@ -1498,7 +1404,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1498
1404
|
dropAuthor: params?.dropSenderName || undefined,
|
|
1499
1405
|
dropMediaCaptions: params?.dropCaption || undefined,
|
|
1500
1406
|
}));
|
|
1501
|
-
return await this.
|
|
1407
|
+
return await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, to, result);
|
|
1502
1408
|
}
|
|
1503
1409
|
/**
|
|
1504
1410
|
* Forward a single message.
|
|
@@ -1524,102 +1430,6 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1524
1430
|
}
|
|
1525
1431
|
return (0, _3_types_js_1.constructUser)(users[0][_2_tl_js_1.as](_2_tl_js_1.types.User));
|
|
1526
1432
|
}
|
|
1527
|
-
// TODO: log errors
|
|
1528
|
-
async handleUpdate(update) {
|
|
1529
|
-
if (update instanceof _2_tl_js_1.types.UpdateShortMessage) {
|
|
1530
|
-
update = new _2_tl_js_1.types.UpdateNewMessage({
|
|
1531
|
-
message: new _2_tl_js_1.types.Message({
|
|
1532
|
-
out: update.out,
|
|
1533
|
-
mentioned: update.mentioned,
|
|
1534
|
-
mediaUnread: update.mediaUnread,
|
|
1535
|
-
silent: update.silent,
|
|
1536
|
-
id: update.id,
|
|
1537
|
-
fromId: update.out ? new _2_tl_js_1.types.PeerUser({ userId: await this.getSelfId().then(BigInt) }) : new _2_tl_js_1.types.PeerUser({ userId: update.userId }),
|
|
1538
|
-
peerId: new _2_tl_js_1.types.PeerChat({ chatId: update.userId }),
|
|
1539
|
-
message: update.message,
|
|
1540
|
-
date: update.date,
|
|
1541
|
-
fwdFrom: update.fwdFrom,
|
|
1542
|
-
viaBotId: update.viaBotId,
|
|
1543
|
-
replyTo: update.replyTo,
|
|
1544
|
-
entities: update.entities,
|
|
1545
|
-
ttlPeriod: update.ttlPeriod,
|
|
1546
|
-
}),
|
|
1547
|
-
pts: update.pts,
|
|
1548
|
-
ptsCount: update.ptsCount,
|
|
1549
|
-
});
|
|
1550
|
-
}
|
|
1551
|
-
else if (update instanceof _2_tl_js_1.types.UpdateShortChatMessage) {
|
|
1552
|
-
update = new _2_tl_js_1.types.UpdateNewMessage({
|
|
1553
|
-
message: new _2_tl_js_1.types.Message({
|
|
1554
|
-
out: update.out,
|
|
1555
|
-
mentioned: update.mentioned,
|
|
1556
|
-
mediaUnread: update.mediaUnread,
|
|
1557
|
-
silent: update.silent,
|
|
1558
|
-
id: update.id,
|
|
1559
|
-
fromId: new _2_tl_js_1.types.PeerUser({ userId: update.fromId }),
|
|
1560
|
-
peerId: new _2_tl_js_1.types.PeerChat({ chatId: update.chatId }),
|
|
1561
|
-
fwdFrom: update.fwdFrom,
|
|
1562
|
-
viaBotId: update.viaBotId,
|
|
1563
|
-
replyTo: update.replyTo,
|
|
1564
|
-
date: update.date,
|
|
1565
|
-
message: update.message,
|
|
1566
|
-
entities: update.entities,
|
|
1567
|
-
ttlPeriod: update.ttlPeriod,
|
|
1568
|
-
}),
|
|
1569
|
-
pts: update.pts,
|
|
1570
|
-
ptsCount: update.ptsCount,
|
|
1571
|
-
});
|
|
1572
|
-
}
|
|
1573
|
-
if (update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateNewChannelMessage || update instanceof _2_tl_js_1.types.UpdateNewChannelMessage) {
|
|
1574
|
-
if (update.message instanceof _2_tl_js_1.types.Message || update.message instanceof _2_tl_js_1.types.MessageService) {
|
|
1575
|
-
await this.storage.setMessage((0, _2_tl_js_1.peerToChatId)(update.message.peerId), update.message.id, update.message);
|
|
1576
|
-
}
|
|
1577
|
-
}
|
|
1578
|
-
if (update instanceof _2_tl_js_1.types.UpdateNewMessage ||
|
|
1579
|
-
update instanceof _2_tl_js_1.types.UpdateNewChannelMessage ||
|
|
1580
|
-
update instanceof _2_tl_js_1.types.UpdateEditMessage ||
|
|
1581
|
-
update instanceof _2_tl_js_1.types.UpdateEditChannelMessage) {
|
|
1582
|
-
const key = update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateNewChannelMessage ? "message" : "editedMessage";
|
|
1583
|
-
const message = await (0, _3_types_js_1.constructMessage)(update.message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this));
|
|
1584
|
-
await this.handle({ [key]: message }, _0_utilities_js_1.resolve);
|
|
1585
|
-
}
|
|
1586
|
-
if (update instanceof _2_tl_js_1.types.UpdateDeleteMessages) {
|
|
1587
|
-
const deletedMessages = new Array();
|
|
1588
|
-
for (const messageId of update.messages) {
|
|
1589
|
-
const chatId = await this.storage.getMessageChat(messageId);
|
|
1590
|
-
if (chatId) {
|
|
1591
|
-
const message = await this.storage.getMessage(chatId, messageId);
|
|
1592
|
-
if (message != null) {
|
|
1593
|
-
deletedMessages.push(await (0, _3_types_js_1.constructMessage)(message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this)));
|
|
1594
|
-
}
|
|
1595
|
-
await this.storage.setMessage(chatId, messageId, null);
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
|
-
if (deletedMessages.length > 0) {
|
|
1599
|
-
await this.handle({ deletedMessages: deletedMessages }, _0_utilities_js_1.resolve);
|
|
1600
|
-
}
|
|
1601
|
-
}
|
|
1602
|
-
else if (update instanceof _2_tl_js_1.types.UpdateDeleteChannelMessages) {
|
|
1603
|
-
const chatId = (0, _2_tl_js_1.getChannelChatId)(update.channelId);
|
|
1604
|
-
const deletedMessages = new Array();
|
|
1605
|
-
for (const messageId of update.messages) {
|
|
1606
|
-
const message = await this.storage.getMessage(chatId, messageId);
|
|
1607
|
-
if (message) {
|
|
1608
|
-
deletedMessages.push(await (0, _3_types_js_1.constructMessage)(message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this)));
|
|
1609
|
-
}
|
|
1610
|
-
await this.storage.setMessage(chatId, messageId, null);
|
|
1611
|
-
}
|
|
1612
|
-
if (deletedMessages.length > 0) {
|
|
1613
|
-
await this.handle({ deletedMessages: deletedMessages }, _0_utilities_js_1.resolve);
|
|
1614
|
-
}
|
|
1615
|
-
}
|
|
1616
|
-
if (update instanceof _2_tl_js_1.types.UpdateBotCallbackQuery || update instanceof _2_tl_js_1.types.UpdateInlineBotCallbackQuery) {
|
|
1617
|
-
await this.handle({ callbackQuery: await (0, _3_types_js_1.constructCallbackQuery)(update, this[getEntity].bind(this), this[getMessageWithReply].bind(this)) }, _0_utilities_js_1.resolve);
|
|
1618
|
-
}
|
|
1619
|
-
else if (update instanceof _2_tl_js_1.types.UpdateBotInlineQuery) {
|
|
1620
|
-
await this.handle({ inlineQuery: await (0, _3_types_js_1.constructInlineQuery)(update, this[getEntity].bind(this)) }, _0_utilities_js_1.resolve);
|
|
1621
|
-
}
|
|
1622
|
-
}
|
|
1623
1433
|
/**
|
|
1624
1434
|
* Answer a callback query. Bot-only.
|
|
1625
1435
|
*
|
|
@@ -1627,7 +1437,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1627
1437
|
* @param id ID of the callback query to answer.
|
|
1628
1438
|
*/
|
|
1629
1439
|
async answerCallbackQuery(id, params) {
|
|
1630
|
-
await this.
|
|
1440
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "answerCallbackQuery");
|
|
1631
1441
|
await this.invoke(new _2_tl_js_1.functions.MessagesSetBotCallbackAnswer({
|
|
1632
1442
|
queryId: BigInt(id),
|
|
1633
1443
|
cacheTime: params?.cacheTime ?? 0,
|
|
@@ -1635,18 +1445,6 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1635
1445
|
alert: params?.alert ? true : undefined,
|
|
1636
1446
|
}));
|
|
1637
1447
|
}
|
|
1638
|
-
async constructReplyMarkup(params) {
|
|
1639
|
-
if (params?.replyMarkup) {
|
|
1640
|
-
await this.assertBot("replyMarkup");
|
|
1641
|
-
return (0, _3_types_js_1.replyMarkupToTlObject)(params.replyMarkup, this.usernameResolver.bind(this));
|
|
1642
|
-
}
|
|
1643
|
-
}
|
|
1644
|
-
static assertMsgHas(message, key) {
|
|
1645
|
-
if (!(key in message) || message[key] === undefined) {
|
|
1646
|
-
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
1647
|
-
}
|
|
1648
|
-
return message;
|
|
1649
|
-
}
|
|
1650
1448
|
/**
|
|
1651
1449
|
* Send a poll.
|
|
1652
1450
|
*
|
|
@@ -1664,9 +1462,9 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1664
1462
|
const replyToMsgId = params?.replyToMessageId;
|
|
1665
1463
|
const topMsgId = params?.messageThreadId;
|
|
1666
1464
|
const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined; // TODO: check default sendAs
|
|
1667
|
-
const replyMarkup = await this.
|
|
1465
|
+
const replyMarkup = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params);
|
|
1668
1466
|
const explanation = params?.explanation;
|
|
1669
|
-
const parseResult = explanation !== undefined ? this.
|
|
1467
|
+
const parseResult = explanation !== undefined ? __classPrivateFieldGet(this, _Client_instances, "m", _Client_parseText).call(this, explanation, { parseMode: params?.explanationParseMode, entities: params?.explanationEntities }) : undefined;
|
|
1670
1468
|
const solution = parseResult === undefined ? undefined : parseResult[0];
|
|
1671
1469
|
const solutionEntities = parseResult === undefined ? undefined : parseResult[1];
|
|
1672
1470
|
const answers = options.map((v, i) => new _2_tl_js_1.types.PollAnswer({ option: new Uint8Array([i]), text: v }));
|
|
@@ -1698,8 +1496,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1698
1496
|
media,
|
|
1699
1497
|
message: "",
|
|
1700
1498
|
}));
|
|
1701
|
-
const message = await this.
|
|
1702
|
-
return Client.
|
|
1499
|
+
const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
|
|
1500
|
+
return __classPrivateFieldGet(Client, _a, "m", _Client_assertMsgHas).call(Client, message, "poll");
|
|
1703
1501
|
}
|
|
1704
1502
|
/**
|
|
1705
1503
|
* Send a chat action.
|
|
@@ -1779,7 +1577,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1779
1577
|
autoStart: false,
|
|
1780
1578
|
});
|
|
1781
1579
|
signal?.addEventListener("abort", () => (0, _1_utilities_js_1.drop)(client.disconnect()));
|
|
1782
|
-
client.
|
|
1580
|
+
__classPrivateFieldGet(client, _Client_state, "f").salt = __classPrivateFieldGet(this, _Client_state, "f").salt;
|
|
1783
1581
|
await client.connect();
|
|
1784
1582
|
let part = 0;
|
|
1785
1583
|
const partCount = Math.ceil(contents.length / chunkSize);
|
|
@@ -1874,7 +1672,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1874
1672
|
async answerInlineQuery(id, results, params) {
|
|
1875
1673
|
await this.invoke(new _2_tl_js_1.functions.MessagesSetInlineBotResults({
|
|
1876
1674
|
queryId: BigInt(id),
|
|
1877
|
-
results: await Promise.all(results.map((v) => (0, _3_types_js_1.inlineQueryResultToTlObject)(v, this.
|
|
1675
|
+
results: await Promise.all(results.map((v) => (0, _3_types_js_1.inlineQueryResultToTlObject)(v, __classPrivateFieldGet(this, _Client_instances, "m", _Client_parseText).bind(this), __classPrivateFieldGet(this, _Client_usernameResolver, "f").bind(this)))),
|
|
1878
1676
|
cacheTime: params?.cacheTime ?? 300,
|
|
1879
1677
|
private: params?.isPersonal ? true : undefined,
|
|
1880
1678
|
switchWebview: params?.button && params.button.webApp ? new _2_tl_js_1.types.InlineBotWebView({ text: params.button.text, url: params.button.webApp.url }) : undefined,
|
|
@@ -1884,8 +1682,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1884
1682
|
}));
|
|
1885
1683
|
}
|
|
1886
1684
|
use(handler) {
|
|
1887
|
-
const handle = this
|
|
1888
|
-
this
|
|
1685
|
+
const handle = __classPrivateFieldGet(this, _Client_handle, "f");
|
|
1686
|
+
__classPrivateFieldSet(this, _Client_handle, async (upd, next) => {
|
|
1889
1687
|
let called = false;
|
|
1890
1688
|
await handle(upd, async () => {
|
|
1891
1689
|
if (called)
|
|
@@ -1893,7 +1691,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1893
1691
|
called = true;
|
|
1894
1692
|
await handler(upd, next);
|
|
1895
1693
|
});
|
|
1896
|
-
};
|
|
1694
|
+
}, "f");
|
|
1897
1695
|
}
|
|
1898
1696
|
branch(predicate, trueHandler, falseHandler) {
|
|
1899
1697
|
this.use(async (upd, next) => {
|
|
@@ -1929,17 +1727,14 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1929
1727
|
}
|
|
1930
1728
|
}, handler);
|
|
1931
1729
|
}
|
|
1932
|
-
async setMyInfo(info) {
|
|
1933
|
-
await this.invoke(new _2_tl_js_1.functions.BotsSetBotInfo({ bot: new _2_tl_js_1.types.InputUserSelf(), ...info }));
|
|
1934
|
-
}
|
|
1935
1730
|
/**
|
|
1936
1731
|
* Set the bot's description in the given language. Bot-only.
|
|
1937
1732
|
*
|
|
1938
1733
|
* @method
|
|
1939
1734
|
*/
|
|
1940
1735
|
async setMyDescription({ description, languageCode }) {
|
|
1941
|
-
await this.
|
|
1942
|
-
await this.
|
|
1736
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "setMyDescription");
|
|
1737
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { description, langCode: languageCode ?? "" });
|
|
1943
1738
|
}
|
|
1944
1739
|
/**
|
|
1945
1740
|
* Set the bot's name in the given language. Bot-only.
|
|
@@ -1947,8 +1742,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1947
1742
|
* @method
|
|
1948
1743
|
*/
|
|
1949
1744
|
async setMyName({ name, languageCode }) {
|
|
1950
|
-
await this.
|
|
1951
|
-
await this.
|
|
1745
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "setMyName");
|
|
1746
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { name, langCode: languageCode ?? "" });
|
|
1952
1747
|
}
|
|
1953
1748
|
/**
|
|
1954
1749
|
* Set the bot's short description in the given language. Bot-only.
|
|
@@ -1956,11 +1751,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1956
1751
|
* @method
|
|
1957
1752
|
*/
|
|
1958
1753
|
async setMyShortDescription({ shortDescription: about, languageCode }) {
|
|
1959
|
-
await this.
|
|
1960
|
-
await this.
|
|
1961
|
-
}
|
|
1962
|
-
getMyInfo(languageCode) {
|
|
1963
|
-
return this.invoke(new _2_tl_js_1.functions.BotsGetBotInfo({ bot: new _2_tl_js_1.types.InputUserSelf(), langCode: languageCode ?? "" }));
|
|
1754
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "setMyShortDescription");
|
|
1755
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { about, langCode: languageCode ?? "" });
|
|
1964
1756
|
}
|
|
1965
1757
|
/**
|
|
1966
1758
|
* Get the bot's description in the given language. Bot-only.
|
|
@@ -1968,8 +1760,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1968
1760
|
* @method
|
|
1969
1761
|
*/
|
|
1970
1762
|
async getMyDescription(params) {
|
|
1971
|
-
await this.
|
|
1972
|
-
return await this.
|
|
1763
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "getMyDescription");
|
|
1764
|
+
return await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getMyInfo).call(this, params?.languageCode).then((v) => v.description);
|
|
1973
1765
|
}
|
|
1974
1766
|
/**
|
|
1975
1767
|
* Set the bot's name in the given language. Bot-only.
|
|
@@ -1977,8 +1769,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1977
1769
|
* @method
|
|
1978
1770
|
*/
|
|
1979
1771
|
async getMyName(params) {
|
|
1980
|
-
await this.
|
|
1981
|
-
return await this.
|
|
1772
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "getMyName");
|
|
1773
|
+
return await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getMyInfo).call(this, params?.languageCode).then((v) => v.description);
|
|
1982
1774
|
}
|
|
1983
1775
|
/**
|
|
1984
1776
|
* Get the bot's short description in the given language. Bot-only.
|
|
@@ -1986,8 +1778,119 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1986
1778
|
* @method
|
|
1987
1779
|
*/
|
|
1988
1780
|
async getMyShortDescription(params) {
|
|
1989
|
-
await this.
|
|
1990
|
-
return await this.
|
|
1781
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "getMyShortDescription");
|
|
1782
|
+
return await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getMyInfo).call(this, params?.languageCode).then((v) => v.about);
|
|
1991
1783
|
}
|
|
1992
1784
|
}
|
|
1993
1785
|
exports.Client = Client;
|
|
1786
|
+
_a = Client, _Client_handleUpdate =
|
|
1787
|
+
// TODO: log errors
|
|
1788
|
+
async function _Client_handleUpdate(update) {
|
|
1789
|
+
if (update instanceof _2_tl_js_1.types.UpdateShortMessage) {
|
|
1790
|
+
update = new _2_tl_js_1.types.UpdateNewMessage({
|
|
1791
|
+
message: new _2_tl_js_1.types.Message({
|
|
1792
|
+
out: update.out,
|
|
1793
|
+
mentioned: update.mentioned,
|
|
1794
|
+
mediaUnread: update.mediaUnread,
|
|
1795
|
+
silent: update.silent,
|
|
1796
|
+
id: update.id,
|
|
1797
|
+
fromId: update.out ? new _2_tl_js_1.types.PeerUser({ userId: await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getSelfId).call(this).then(BigInt) }) : new _2_tl_js_1.types.PeerUser({ userId: update.userId }),
|
|
1798
|
+
peerId: new _2_tl_js_1.types.PeerChat({ chatId: update.userId }),
|
|
1799
|
+
message: update.message,
|
|
1800
|
+
date: update.date,
|
|
1801
|
+
fwdFrom: update.fwdFrom,
|
|
1802
|
+
viaBotId: update.viaBotId,
|
|
1803
|
+
replyTo: update.replyTo,
|
|
1804
|
+
entities: update.entities,
|
|
1805
|
+
ttlPeriod: update.ttlPeriod,
|
|
1806
|
+
}),
|
|
1807
|
+
pts: update.pts,
|
|
1808
|
+
ptsCount: update.ptsCount,
|
|
1809
|
+
});
|
|
1810
|
+
}
|
|
1811
|
+
else if (update instanceof _2_tl_js_1.types.UpdateShortChatMessage) {
|
|
1812
|
+
update = new _2_tl_js_1.types.UpdateNewMessage({
|
|
1813
|
+
message: new _2_tl_js_1.types.Message({
|
|
1814
|
+
out: update.out,
|
|
1815
|
+
mentioned: update.mentioned,
|
|
1816
|
+
mediaUnread: update.mediaUnread,
|
|
1817
|
+
silent: update.silent,
|
|
1818
|
+
id: update.id,
|
|
1819
|
+
fromId: new _2_tl_js_1.types.PeerUser({ userId: update.fromId }),
|
|
1820
|
+
peerId: new _2_tl_js_1.types.PeerChat({ chatId: update.chatId }),
|
|
1821
|
+
fwdFrom: update.fwdFrom,
|
|
1822
|
+
viaBotId: update.viaBotId,
|
|
1823
|
+
replyTo: update.replyTo,
|
|
1824
|
+
date: update.date,
|
|
1825
|
+
message: update.message,
|
|
1826
|
+
entities: update.entities,
|
|
1827
|
+
ttlPeriod: update.ttlPeriod,
|
|
1828
|
+
}),
|
|
1829
|
+
pts: update.pts,
|
|
1830
|
+
ptsCount: update.ptsCount,
|
|
1831
|
+
});
|
|
1832
|
+
}
|
|
1833
|
+
if (update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateNewChannelMessage || update instanceof _2_tl_js_1.types.UpdateNewChannelMessage) {
|
|
1834
|
+
if (update.message instanceof _2_tl_js_1.types.Message || update.message instanceof _2_tl_js_1.types.MessageService) {
|
|
1835
|
+
await this.storage.setMessage((0, _2_tl_js_1.peerToChatId)(update.message.peerId), update.message.id, update.message);
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
if (update instanceof _2_tl_js_1.types.UpdateNewMessage ||
|
|
1839
|
+
update instanceof _2_tl_js_1.types.UpdateNewChannelMessage ||
|
|
1840
|
+
update instanceof _2_tl_js_1.types.UpdateEditMessage ||
|
|
1841
|
+
update instanceof _2_tl_js_1.types.UpdateEditChannelMessage) {
|
|
1842
|
+
const key = update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateNewChannelMessage ? "message" : "editedMessage";
|
|
1843
|
+
const message = await (0, _3_types_js_1.constructMessage)(update.message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this));
|
|
1844
|
+
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, { [key]: message }, _0_utilities_js_1.resolve);
|
|
1845
|
+
}
|
|
1846
|
+
if (update instanceof _2_tl_js_1.types.UpdateDeleteMessages) {
|
|
1847
|
+
const deletedMessages = new Array();
|
|
1848
|
+
for (const messageId of update.messages) {
|
|
1849
|
+
const chatId = await this.storage.getMessageChat(messageId);
|
|
1850
|
+
if (chatId) {
|
|
1851
|
+
const message = await this.storage.getMessage(chatId, messageId);
|
|
1852
|
+
if (message != null) {
|
|
1853
|
+
deletedMessages.push(await (0, _3_types_js_1.constructMessage)(message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this)));
|
|
1854
|
+
}
|
|
1855
|
+
await this.storage.setMessage(chatId, messageId, null);
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
if (deletedMessages.length > 0) {
|
|
1859
|
+
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, { deletedMessages: deletedMessages }, _0_utilities_js_1.resolve);
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
else if (update instanceof _2_tl_js_1.types.UpdateDeleteChannelMessages) {
|
|
1863
|
+
const chatId = (0, _2_tl_js_1.getChannelChatId)(update.channelId);
|
|
1864
|
+
const deletedMessages = new Array();
|
|
1865
|
+
for (const messageId of update.messages) {
|
|
1866
|
+
const message = await this.storage.getMessage(chatId, messageId);
|
|
1867
|
+
if (message) {
|
|
1868
|
+
deletedMessages.push(await (0, _3_types_js_1.constructMessage)(message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this)));
|
|
1869
|
+
}
|
|
1870
|
+
await this.storage.setMessage(chatId, messageId, null);
|
|
1871
|
+
}
|
|
1872
|
+
if (deletedMessages.length > 0) {
|
|
1873
|
+
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, { deletedMessages: deletedMessages }, _0_utilities_js_1.resolve);
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
if (update instanceof _2_tl_js_1.types.UpdateBotCallbackQuery || update instanceof _2_tl_js_1.types.UpdateInlineBotCallbackQuery) {
|
|
1877
|
+
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, { callbackQuery: await (0, _3_types_js_1.constructCallbackQuery)(update, this[getEntity].bind(this), this[getMessageWithReply].bind(this)) }, _0_utilities_js_1.resolve);
|
|
1878
|
+
}
|
|
1879
|
+
else if (update instanceof _2_tl_js_1.types.UpdateBotInlineQuery) {
|
|
1880
|
+
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, { inlineQuery: await (0, _3_types_js_1.constructInlineQuery)(update, this[getEntity].bind(this)) }, _0_utilities_js_1.resolve);
|
|
1881
|
+
}
|
|
1882
|
+
}, _Client_constructReplyMarkup = async function _Client_constructReplyMarkup(params) {
|
|
1883
|
+
if (params?.replyMarkup) {
|
|
1884
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "replyMarkup");
|
|
1885
|
+
return (0, _3_types_js_1.replyMarkupToTlObject)(params.replyMarkup, __classPrivateFieldGet(this, _Client_usernameResolver, "f").bind(this));
|
|
1886
|
+
}
|
|
1887
|
+
}, _Client_assertMsgHas = function _Client_assertMsgHas(message, key) {
|
|
1888
|
+
if (!(key in message) || message[key] === undefined) {
|
|
1889
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
1890
|
+
}
|
|
1891
|
+
return message;
|
|
1892
|
+
}, _Client_setMyInfo = async function _Client_setMyInfo(info) {
|
|
1893
|
+
await this.invoke(new _2_tl_js_1.functions.BotsSetBotInfo({ bot: new _2_tl_js_1.types.InputUserSelf(), ...info }));
|
|
1894
|
+
}, _Client_getMyInfo = function _Client_getMyInfo(languageCode) {
|
|
1895
|
+
return this.invoke(new _2_tl_js_1.functions.BotsGetBotInfo({ bot: new _2_tl_js_1.types.InputUserSelf(), langCode: languageCode ?? "" }));
|
|
1896
|
+
};
|