@mtkruto/node 0.67.2 → 0.68.0
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_errors.js +2 -6
- package/esm/3_errors.js +2 -12
- package/esm/3_types.d.ts +1 -0
- package/esm/3_types.d.ts.map +1 -1
- package/esm/3_types.js +1 -0
- package/esm/4_errors.js +2 -12
- package/esm/_dnt.polyfills.d.ts +99 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/_dnt.polyfills.js +127 -1
- package/esm/_dnt.test_polyfills.d.ts.map +1 -0
- package/esm/client/0_filters_test.d.ts.map +1 -1
- package/esm/client/0_markdown_test.d.ts.map +1 -1
- package/esm/client/0_params.d.ts +2 -0
- package/esm/client/0_params.d.ts.map +1 -1
- package/esm/client/0_password.d.ts +5 -5
- package/esm/client/0_password.d.ts.map +1 -1
- package/esm/client/0_password_test.d.ts.map +1 -1
- package/esm/client/0_storage_operations.js +143 -155
- package/esm/client/0_storage_operations_test.d.ts.map +1 -1
- package/esm/client/0_utilities.d.ts +1 -1
- package/esm/client/0_utilities_test.d.ts.map +1 -1
- package/esm/client/1_client_plain.js +4 -22
- package/esm/client/1_composer.js +8 -21
- package/esm/client/2_account_manager.js +85 -97
- package/esm/client/2_bot_info_manager.js +26 -38
- package/esm/client/2_business_connection_manager.js +10 -23
- package/esm/client/2_client_encrypted.js +194 -211
- package/esm/client/2_file_manager.d.ts +4 -3
- package/esm/client/2_file_manager.d.ts.map +1 -1
- package/esm/client/2_file_manager.js +268 -224
- package/esm/client/2_file_manager_test.d.ts.map +1 -1
- package/esm/client/2_network_statistics_manager.js +8 -21
- package/esm/client/2_payment_manager.js +7 -20
- package/esm/client/2_reaction_manager.js +7 -20
- package/esm/client/2_translations_manager.js +97 -107
- package/esm/client/2_update_manager.js +764 -759
- package/esm/client/3_client_encrypted_pool.js +10 -26
- package/esm/client/3_client_encrypted_pool_test.d.ts.map +1 -1
- package/esm/client/3_message_manager.d.ts +1 -1
- package/esm/client/3_message_manager.js +441 -448
- package/esm/client/3_message_manager_test.d.ts.map +1 -1
- package/esm/client/3_video_chat_manager.d.ts +1 -1
- package/esm/client/3_video_chat_manager.js +57 -68
- package/esm/client/4_callback_query_manager.js +18 -30
- package/esm/client/4_chat_list_manager.js +322 -318
- package/esm/client/4_chat_manager.js +118 -131
- package/esm/client/4_forum_manager.js +67 -73
- package/esm/client/4_gift_manager.js +16 -29
- package/esm/client/4_inline_query_manager.js +16 -28
- package/esm/client/4_link_preview_manager.js +6 -19
- package/esm/client/4_poll_manager.js +44 -57
- package/esm/client/4_story_manager.js +41 -53
- package/esm/client/5_client.d.ts +7 -0
- package/esm/client/5_client.d.ts.map +1 -1
- package/esm/client/5_client.js +1269 -1288
- package/esm/connection/1_connection_tcp.node.js +48 -65
- package/esm/connection/1_connection_web_socket.js +75 -91
- package/esm/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
- package/esm/deps/jsr.io/@std/async/1.0.13/mux_async_iterator.js +31 -47
- package/esm/deps/jsr.io/@std/async/1.0.13/tee.js +11 -34
- package/esm/deps/jsr.io/@std/datetime/0.225.5/_date_time_formatter.js +4 -17
- package/esm/mod.js +2 -12
- package/esm/session/0_session_state.js +12 -38
- package/esm/session/1_session.js +49 -72
- package/esm/session/2_session_encrypted.js +324 -320
- package/esm/storage/1_utilities_test.d.ts.map +1 -1
- package/esm/storage/2_storage_indexed_db.js +26 -44
- package/esm/storage/2_storage_local_storage.node.js +12 -25
- package/esm/storage/2_storage_memory.js +24 -41
- package/esm/storage/2_storage_session_storage.js +3 -16
- package/esm/tl/0_utilities_test.d.ts.map +1 -1
- package/esm/tl/1_tl_reader.js +80 -88
- package/esm/tl/1_tl_reader_test.d.ts.map +1 -1
- package/esm/tl/1_tl_writer.js +155 -164
- package/esm/tl/1_tl_writer_test.d.ts.map +1 -1
- package/esm/transport/0_transport.js +1 -8
- package/esm/transport/1_transport_abridged.js +11 -24
- package/esm/transport/1_transport_intermediate.js +10 -23
- package/esm/transport/2_transport_provider_web_socket.d.ts.map +1 -1
- package/esm/types/0_upload_progress.d.ts +29 -0
- package/esm/types/0_upload_progress.d.ts.map +1 -0
- package/esm/types/0_upload_progress.js +20 -0
- package/esm/types/1_sticker.d.ts +1 -1
- package/esm/types/1_sticker.d.ts.map +1 -1
- package/esm/types/2_poll_answer.d.ts +19 -0
- package/esm/types/2_poll_answer.d.ts.map +1 -1
- package/esm/types/2_poll_answer.js +19 -0
- package/esm/types/7_update.d.ts +21 -2
- package/esm/types/7_update.d.ts.map +1 -1
- package/esm/utilities/0_bigint_test.d.ts.map +1 -1
- package/esm/utilities/0_buffer.d.ts +1 -1
- package/esm/utilities/0_buffer.d.ts.map +1 -1
- package/esm/utilities/0_buffer_test.d.ts.map +1 -1
- package/esm/utilities/0_hash.d.ts +2 -2
- package/esm/utilities/0_hash.d.ts.map +1 -1
- package/esm/utilities/0_mutex.js +4 -19
- package/esm/utilities/0_part_stream.js +11 -25
- package/esm/utilities/0_part_stream_test.d.ts.map +1 -1
- package/esm/utilities/0_rle.d.ts +2 -2
- package/esm/utilities/0_rle.d.ts.map +1 -1
- package/esm/utilities/0_rle_test.d.ts.map +1 -1
- package/esm/utilities/0_text.d.ts +20 -1
- package/esm/utilities/0_text.d.ts.map +1 -1
- package/esm/utilities/0_text.js +19 -0
- package/esm/utilities/1_auth.d.ts +1 -1
- package/esm/utilities/1_auth.d.ts.map +1 -1
- package/esm/utilities/1_base64.d.ts +1 -1
- package/esm/utilities/1_base64.d.ts.map +1 -1
- package/esm/utilities/1_base64_test.d.ts.map +1 -1
- package/esm/utilities/1_crypto.js +42 -53
- package/esm/utilities/1_crypto_test.d.ts.map +1 -1
- package/esm/utilities/1_logger.d.ts +2 -2
- package/esm/utilities/1_math_test.d.ts.map +1 -1
- package/esm/utilities/2_queue.js +29 -47
- package/package.json +1 -1
- package/script/0_errors.js +2 -6
- package/script/2_tl.js +17 -7
- package/script/3_errors.js +2 -12
- package/script/3_types.d.ts +1 -0
- package/script/3_types.d.ts.map +1 -1
- package/script/3_types.js +1 -0
- package/script/4_constants.js +17 -7
- package/script/4_errors.js +2 -12
- package/script/_dnt.polyfills.d.ts +99 -0
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +128 -0
- package/script/_dnt.test_polyfills.d.ts.map +1 -0
- package/script/client/0_filters_test.d.ts.map +1 -1
- package/script/client/0_markdown_test.d.ts.map +1 -1
- package/script/client/0_params.d.ts +2 -0
- package/script/client/0_params.d.ts.map +1 -1
- package/script/client/0_password.d.ts +5 -5
- package/script/client/0_password.d.ts.map +1 -1
- package/script/client/0_password.js +17 -7
- package/script/client/0_password_test.d.ts.map +1 -1
- package/script/client/0_storage_operations.js +143 -155
- package/script/client/0_storage_operations_test.d.ts.map +1 -1
- package/script/client/0_utilities.d.ts +1 -1
- package/script/client/0_utilities_test.d.ts.map +1 -1
- package/script/client/1_client_plain.js +4 -22
- package/script/client/1_composer.js +8 -21
- package/script/client/2_account_manager.js +85 -97
- package/script/client/2_bot_info_manager.js +26 -38
- package/script/client/2_business_connection_manager.js +10 -23
- package/script/client/2_client_encrypted.js +195 -212
- package/script/client/2_file_manager.d.ts +4 -3
- package/script/client/2_file_manager.d.ts.map +1 -1
- package/script/client/2_file_manager.js +285 -231
- package/script/client/2_file_manager_test.d.ts.map +1 -1
- package/script/client/2_network_statistics_manager.js +8 -21
- package/script/client/2_payment_manager.js +7 -20
- package/script/client/2_reaction_manager.js +7 -20
- package/script/client/2_translations_manager.js +98 -108
- package/script/client/2_update_manager.js +764 -759
- package/script/client/3_client_encrypted_pool.js +10 -26
- package/script/client/3_client_encrypted_pool_test.d.ts.map +1 -1
- package/script/client/3_message_manager.d.ts +1 -1
- package/script/client/3_message_manager.js +441 -448
- package/script/client/3_message_manager_test.d.ts.map +1 -1
- package/script/client/3_video_chat_manager.d.ts +1 -1
- package/script/client/3_video_chat_manager.js +57 -68
- package/script/client/4_callback_query_manager.js +18 -30
- package/script/client/4_chat_list_manager.js +322 -318
- package/script/client/4_chat_manager.js +118 -131
- package/script/client/4_forum_manager.js +67 -73
- package/script/client/4_gift_manager.js +16 -29
- package/script/client/4_inline_query_manager.js +16 -28
- package/script/client/4_link_preview_manager.js +6 -19
- package/script/client/4_poll_manager.js +44 -57
- package/script/client/4_story_manager.js +41 -53
- package/script/client/5_client.d.ts +7 -0
- package/script/client/5_client.d.ts.map +1 -1
- package/script/client/5_client.js +1269 -1288
- package/script/connection/1_connection_tcp.node.js +48 -65
- package/script/connection/1_connection_web_socket.js +92 -98
- package/script/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
- package/script/deps/jsr.io/@std/assert/1.0.13/equal.js +17 -7
- package/script/deps/jsr.io/@std/async/1.0.13/delay.js +17 -7
- package/script/deps/jsr.io/@std/async/1.0.13/mux_async_iterator.js +31 -47
- package/script/deps/jsr.io/@std/async/1.0.13/tee.js +11 -34
- package/script/deps/jsr.io/@std/datetime/0.225.5/_date_time_formatter.js +4 -17
- package/script/deps/jsr.io/@std/internal/1.0.10/format.js +17 -7
- package/script/deps/jsr.io/@std/internal/1.0.10/styles.js +17 -7
- package/script/deps/jsr.io/@std/path/1.1.0/_os.js +17 -7
- package/script/mod.js +19 -19
- package/script/session/0_session_state.js +12 -38
- package/script/session/1_session.js +66 -79
- package/script/session/2_session_encrypted.js +325 -321
- package/script/storage/1_utilities_test.d.ts.map +1 -1
- package/script/storage/2_storage_indexed_db.js +26 -44
- package/script/storage/2_storage_local_storage.node.js +12 -25
- package/script/storage/2_storage_memory.js +24 -41
- package/script/storage/2_storage_session_storage.js +3 -16
- package/script/tl/0_utilities_test.d.ts.map +1 -1
- package/script/tl/1_tl_reader.js +81 -89
- package/script/tl/1_tl_reader_test.d.ts.map +1 -1
- package/script/tl/1_tl_writer.js +156 -165
- package/script/tl/1_tl_writer_test.d.ts.map +1 -1
- package/script/tl/2_telegram.js +17 -7
- package/script/transport/0_obfuscation.js +17 -7
- package/script/transport/0_transport.js +1 -8
- package/script/transport/1_transport_abridged.js +11 -24
- package/script/transport/1_transport_intermediate.js +10 -23
- package/script/transport/2_transport_provider_web_socket.d.ts.map +1 -1
- package/script/types/0_upload_progress.d.ts +29 -0
- package/script/types/0_upload_progress.d.ts.map +1 -0
- package/script/types/0_upload_progress.js +21 -0
- package/script/types/1_sticker.d.ts +1 -1
- package/script/types/1_sticker.d.ts.map +1 -1
- package/script/types/2_poll_answer.d.ts +19 -0
- package/script/types/2_poll_answer.d.ts.map +1 -1
- package/script/types/2_poll_answer.js +19 -0
- package/script/types/7_update.d.ts +21 -2
- package/script/types/7_update.d.ts.map +1 -1
- package/script/utilities/0_bigint.js +17 -7
- package/script/utilities/0_bigint_test.d.ts.map +1 -1
- package/script/utilities/0_buffer.d.ts +1 -1
- package/script/utilities/0_buffer.d.ts.map +1 -1
- package/script/utilities/0_buffer_test.d.ts.map +1 -1
- package/script/utilities/0_env.js +17 -7
- package/script/utilities/0_hash.d.ts +2 -2
- package/script/utilities/0_hash.d.ts.map +1 -1
- package/script/utilities/0_hash.js +17 -7
- package/script/utilities/0_misc.js +17 -7
- package/script/utilities/0_mutex.js +4 -19
- package/script/utilities/0_part_stream.js +11 -25
- package/script/utilities/0_part_stream_test.d.ts.map +1 -1
- package/script/utilities/0_rle.d.ts +2 -2
- package/script/utilities/0_rle.d.ts.map +1 -1
- package/script/utilities/0_rle_test.d.ts.map +1 -1
- package/script/utilities/0_text.d.ts +20 -1
- package/script/utilities/0_text.d.ts.map +1 -1
- package/script/utilities/0_text.js +19 -0
- package/script/utilities/1_auth.d.ts +1 -1
- package/script/utilities/1_auth.d.ts.map +1 -1
- package/script/utilities/1_auth.js +17 -7
- package/script/utilities/1_base64.d.ts +1 -1
- package/script/utilities/1_base64.d.ts.map +1 -1
- package/script/utilities/1_base64_test.d.ts.map +1 -1
- package/script/utilities/1_crypto.js +60 -61
- package/script/utilities/1_crypto_test.d.ts.map +1 -1
- package/script/utilities/1_logger.d.ts +2 -2
- package/script/utilities/1_math_test.d.ts.map +1 -1
- package/script/utilities/2_queue.js +30 -48
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"0_utilities_test.d.ts","sourceRoot":"","sources":["../../src/client/0_utilities_test.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"0_utilities_test.d.ts","sourceRoot":"","sources":["../../src/client/0_utilities_test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,2BAA2B,CAAC"}
|
|
@@ -17,18 +17,6 @@
|
|
|
17
17
|
* You should have received a copy of the GNU Lesser General Public License
|
|
18
18
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
21
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
22
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
23
|
-
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");
|
|
24
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
25
|
-
};
|
|
26
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
27
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
28
|
-
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");
|
|
29
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
30
|
-
};
|
|
31
|
-
var _ClientPlain_publicKeys;
|
|
32
20
|
import { assert, assertEquals, concat, ige256Decrypt, ige256Encrypt, unreachable } from "../0_deps.js";
|
|
33
21
|
import { bigIntFromBuffer, bufferFromBigInt, factorize, getLogger, getRandomBigInt, modExp, rsaPad, sha1 } from "../1_utilities.js";
|
|
34
22
|
import { Mtproto } from "../2_tl.js";
|
|
@@ -42,16 +30,11 @@ const LcreateAuthKey = L.branch("createAuthKey");
|
|
|
42
30
|
* An MTProto client for making plain connections. Most users won't need to interact with this. Used internally for creating authorization keys.
|
|
43
31
|
*/
|
|
44
32
|
export class ClientPlain extends ClientAbstract {
|
|
33
|
+
#publicKeys;
|
|
34
|
+
session;
|
|
45
35
|
constructor(dc, params) {
|
|
46
36
|
super();
|
|
47
|
-
|
|
48
|
-
Object.defineProperty(this, "session", {
|
|
49
|
-
enumerable: true,
|
|
50
|
-
configurable: true,
|
|
51
|
-
writable: true,
|
|
52
|
-
value: void 0
|
|
53
|
-
});
|
|
54
|
-
__classPrivateFieldSet(this, _ClientPlain_publicKeys, params?.publicKeys ?? PUBLIC_KEYS, "f");
|
|
37
|
+
this.#publicKeys = params?.publicKeys ?? PUBLIC_KEYS;
|
|
55
38
|
this.session = new SessionPlain(dc, params);
|
|
56
39
|
}
|
|
57
40
|
async invoke(function_) {
|
|
@@ -89,7 +72,7 @@ export class ClientPlain extends ClientAbstract {
|
|
|
89
72
|
let publicKeyFingerprint;
|
|
90
73
|
let publicKey;
|
|
91
74
|
for (const fingerprint of resPq.server_public_key_fingerprints) {
|
|
92
|
-
const maybePublicKey =
|
|
75
|
+
const maybePublicKey = this.#publicKeys.find(([k]) => (k == fingerprint));
|
|
93
76
|
if (maybePublicKey) {
|
|
94
77
|
publicKeyFingerprint = fingerprint;
|
|
95
78
|
publicKey = maybePublicKey[1];
|
|
@@ -163,4 +146,3 @@ export class ClientPlain extends ClientAbstract {
|
|
|
163
146
|
return [authKey, bigIntFromBuffer(salt, true, false)];
|
|
164
147
|
}
|
|
165
148
|
}
|
|
166
|
-
_ClientPlain_publicKeys = new WeakMap();
|
package/esm/client/1_composer.js
CHANGED
|
@@ -17,18 +17,6 @@
|
|
|
17
17
|
* You should have received a copy of the GNU Lesser General Public License
|
|
18
18
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
21
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
22
|
-
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");
|
|
23
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
24
|
-
};
|
|
25
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
26
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
27
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
28
|
-
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");
|
|
29
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
30
|
-
};
|
|
31
|
-
var _Composer_handle, _Composer_prefixes;
|
|
32
20
|
import { InputError } from "../0_errors.js";
|
|
33
21
|
import { match } from "./0_filters.js";
|
|
34
22
|
export function flatten(mw) {
|
|
@@ -52,23 +40,23 @@ export function skip(_ctx, next) {
|
|
|
52
40
|
return next();
|
|
53
41
|
}
|
|
54
42
|
export class Composer {
|
|
43
|
+
#handle;
|
|
44
|
+
#prefixes;
|
|
55
45
|
set prefixes(value) {
|
|
56
|
-
if (
|
|
46
|
+
if (this.#prefixes !== undefined) {
|
|
57
47
|
throw new InputError("Prefixes already set");
|
|
58
48
|
}
|
|
59
|
-
|
|
49
|
+
this.#prefixes = value;
|
|
60
50
|
}
|
|
61
51
|
constructor(...middleware) {
|
|
62
|
-
|
|
63
|
-
_Composer_prefixes.set(this, void 0);
|
|
64
|
-
__classPrivateFieldSet(this, _Composer_handle, middleware.length == 0 ? skip : middleware.map(flatten).reduce(concat), "f");
|
|
52
|
+
this.#handle = middleware.length == 0 ? skip : middleware.map(flatten).reduce(concat);
|
|
65
53
|
}
|
|
66
54
|
middleware() {
|
|
67
|
-
return
|
|
55
|
+
return this.#handle;
|
|
68
56
|
}
|
|
69
57
|
use(...middleware) {
|
|
70
58
|
const composer = new Composer(...middleware);
|
|
71
|
-
|
|
59
|
+
this.#handle = concat(this.#handle, flatten(composer));
|
|
72
60
|
return composer;
|
|
73
61
|
}
|
|
74
62
|
branch(predicate, trueHandler_, falseHandler_) {
|
|
@@ -96,7 +84,7 @@ export class Composer {
|
|
|
96
84
|
command(commands, ...middleware) {
|
|
97
85
|
const commands__ = typeof commands === "object" && "names" in commands ? commands.names : commands;
|
|
98
86
|
const commands_ = Array.isArray(commands__) ? commands__ : [commands__];
|
|
99
|
-
const prefixes_ = typeof commands === "object" && "prefixes" in commands ? commands.prefixes : (
|
|
87
|
+
const prefixes_ = typeof commands === "object" && "prefixes" in commands ? commands.prefixes : (this.#prefixes ?? []);
|
|
100
88
|
const prefixes = Array.isArray(prefixes_) ? prefixes_ : [prefixes_];
|
|
101
89
|
for (const left of prefixes) {
|
|
102
90
|
for (const right of prefixes) {
|
|
@@ -165,4 +153,3 @@ export class Composer {
|
|
|
165
153
|
}, ...middleware);
|
|
166
154
|
}
|
|
167
155
|
}
|
|
168
|
-
_Composer_handle = new WeakMap(), _Composer_prefixes = new WeakMap();
|
|
@@ -17,117 +17,119 @@
|
|
|
17
17
|
* You should have received a copy of the GNU Lesser General Public License
|
|
18
18
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
21
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
22
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
23
|
-
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");
|
|
24
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
25
|
-
};
|
|
26
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
27
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
28
|
-
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");
|
|
29
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
30
|
-
};
|
|
31
|
-
var _AccountManager_instances, _AccountManager_c, _AccountManager_toggleUsername, _AccountManager_getUserFull;
|
|
32
20
|
import { unreachable } from "../0_deps.js";
|
|
33
21
|
import { InputError } from "../0_errors.js";
|
|
34
22
|
import { Api } from "../2_tl.js";
|
|
35
23
|
import { birthdayToTlObject, constructInactiveChat, constructUser } from "../3_types.js";
|
|
36
24
|
import { canBeInputChannel, canBeInputUser, toInputChannel, toInputUser } from "./0_utilities.js";
|
|
37
25
|
export class AccountManager {
|
|
26
|
+
#c;
|
|
38
27
|
constructor(c) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
28
|
+
this.#c = c;
|
|
29
|
+
}
|
|
30
|
+
async #toggleUsername(id, username, active) {
|
|
31
|
+
const peer = await this.#c.getInputPeer(id);
|
|
32
|
+
if (Api.is("inputPeerSelf", peer)) {
|
|
33
|
+
await this.#c.invoke({ _: "account.toggleUsername", username, active });
|
|
34
|
+
}
|
|
35
|
+
else if (canBeInputUser(peer)) {
|
|
36
|
+
await this.#c.invoke({ _: "bots.toggleUsername", bot: toInputUser(peer), username, active });
|
|
37
|
+
}
|
|
38
|
+
else if (canBeInputChannel(peer)) {
|
|
39
|
+
await this.#c.invoke({ _: "channels.toggleUsername", channel: toInputChannel(peer), username, active });
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
unreachable();
|
|
43
|
+
}
|
|
42
44
|
}
|
|
43
45
|
async showUsername(id, username) {
|
|
44
|
-
|
|
45
|
-
await
|
|
46
|
+
this.#c.storage.assertUser("showUsername");
|
|
47
|
+
await this.#toggleUsername(id, username, true);
|
|
46
48
|
}
|
|
47
49
|
async hideUsername(id, username) {
|
|
48
|
-
|
|
49
|
-
await
|
|
50
|
+
this.#c.storage.assertUser("hideUsername");
|
|
51
|
+
await this.#toggleUsername(id, username, false);
|
|
50
52
|
}
|
|
51
53
|
async reorderUsernames(id, order) {
|
|
52
|
-
|
|
53
|
-
const peer = await
|
|
54
|
+
this.#c.storage.assertUser("reorderUsernames");
|
|
55
|
+
const peer = await this.#c.getInputPeer(id);
|
|
54
56
|
if (Api.is("inputPeerSelf", peer)) {
|
|
55
|
-
return await
|
|
57
|
+
return await this.#c.invoke({ _: "account.reorderUsernames", order });
|
|
56
58
|
}
|
|
57
59
|
else if (canBeInputUser(peer)) {
|
|
58
|
-
return await
|
|
60
|
+
return await this.#c.invoke({ _: "bots.reorderUsernames", bot: toInputUser(peer), order });
|
|
59
61
|
}
|
|
60
62
|
else if (canBeInputChannel(peer)) {
|
|
61
|
-
return await
|
|
63
|
+
return await this.#c.invoke({ _: "channels.reorderUsernames", channel: toInputChannel(peer), order });
|
|
62
64
|
}
|
|
63
65
|
else {
|
|
64
66
|
unreachable();
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
69
|
async hideUsernames(id) {
|
|
68
|
-
|
|
69
|
-
const peer = await
|
|
70
|
+
this.#c.storage.assertUser("hideUsernames");
|
|
71
|
+
const peer = await this.#c.getInputPeer(id);
|
|
70
72
|
if (canBeInputChannel(peer)) {
|
|
71
|
-
return await
|
|
73
|
+
return await this.#c.invoke({ _: "channels.deactivateAllUsernames", channel: toInputChannel(peer) });
|
|
72
74
|
}
|
|
73
75
|
else {
|
|
74
76
|
unreachable();
|
|
75
77
|
}
|
|
76
78
|
}
|
|
77
79
|
async getInactiveChats() {
|
|
78
|
-
|
|
79
|
-
const { chats, dates } = await
|
|
80
|
+
this.#c.storage.assertUser("getInactiveChats");
|
|
81
|
+
const { chats, dates } = await this.#c.invoke({ _: "channels.getInactiveChannels" });
|
|
80
82
|
return chats.map((v, i) => constructInactiveChat(v, dates[i]));
|
|
81
83
|
}
|
|
82
84
|
async setOnline(online) {
|
|
83
|
-
|
|
84
|
-
await
|
|
85
|
+
this.#c.storage.assertUser("setOnline");
|
|
86
|
+
await this.#c.invoke({ _: "account.updateStatus", offline: !online });
|
|
85
87
|
}
|
|
86
88
|
async setEmojiStatus(id, params) {
|
|
87
|
-
|
|
89
|
+
this.#c.storage.assertUser("setEmojiStatus");
|
|
88
90
|
const document_id = BigInt(id);
|
|
89
91
|
const until = params?.until;
|
|
90
92
|
const emoji_status = { _: "emojiStatus", document_id, until };
|
|
91
|
-
await
|
|
93
|
+
await this.#c.invoke({ _: "account.updateEmojiStatus", emoji_status });
|
|
92
94
|
}
|
|
93
95
|
async setUserEmojiStatus(userId, id, params) {
|
|
94
|
-
|
|
95
|
-
const user_id = await
|
|
96
|
+
this.#c.storage.assertBot("setUserEmojiStatus");
|
|
97
|
+
const user_id = await this.#c.getInputUser(userId);
|
|
96
98
|
const document_id = BigInt(id);
|
|
97
99
|
const until = params?.until;
|
|
98
100
|
const emoji_status = { _: "emojiStatus", document_id, until };
|
|
99
|
-
await
|
|
101
|
+
await this.#c.invoke({ _: "bots.updateUserEmojiStatus", user_id, emoji_status });
|
|
100
102
|
}
|
|
101
103
|
async setBotCanSetEmojiStatus(botId, canSetEmojiStatus) {
|
|
102
|
-
|
|
103
|
-
const bot = await
|
|
104
|
+
this.#c.storage.assertUser("setBotCanSetEmojiStatus");
|
|
105
|
+
const bot = await this.#c.getInputUser(botId);
|
|
104
106
|
const enabled = canSetEmojiStatus;
|
|
105
|
-
await
|
|
107
|
+
await this.#c.invoke({ _: "bots.toggleUserEmojiStatusPermission", bot, enabled });
|
|
106
108
|
}
|
|
107
109
|
async getContacts() {
|
|
108
|
-
|
|
109
|
-
const result = await
|
|
110
|
+
this.#c.storage.assertUser("getContacts");
|
|
111
|
+
const result = await this.#c.invoke({ _: "contacts.getContacts", hash: 0n });
|
|
110
112
|
if (!Api.is("contacts.contacts", result)) {
|
|
111
113
|
unreachable();
|
|
112
114
|
}
|
|
113
115
|
return result.users.map((v) => Api.is("user", v) ? constructUser(v) : null).filter((v) => v != null);
|
|
114
116
|
}
|
|
115
117
|
async deleteContacts(userIds) {
|
|
116
|
-
|
|
117
|
-
const id = await Promise.all(userIds.map((v) =>
|
|
118
|
-
await
|
|
118
|
+
this.#c.storage.assertUser("deleteContacts");
|
|
119
|
+
const id = await Promise.all(userIds.map((v) => this.#c.getInputUser(v)));
|
|
120
|
+
await this.#c.invoke({ _: "contacts.deleteContacts", id });
|
|
119
121
|
}
|
|
120
122
|
async deleteContact(userId) {
|
|
121
|
-
|
|
123
|
+
this.#c.storage.assertUser("deleteContact");
|
|
122
124
|
await this.deleteContacts([userId]);
|
|
123
125
|
}
|
|
124
126
|
async addContact(userId, params) {
|
|
125
|
-
|
|
126
|
-
const id = await
|
|
127
|
+
this.#c.storage.assertUser("addContact");
|
|
128
|
+
const id = await this.#c.getInputUser(userId);
|
|
127
129
|
if (!Api.is("inputPeerUser", id)) {
|
|
128
130
|
unreachable();
|
|
129
131
|
}
|
|
130
|
-
const user = await
|
|
132
|
+
const user = await this.#c.getEntity(Api.inputPeerToPeer(id));
|
|
131
133
|
if (!user || !("first_name" in user)) {
|
|
132
134
|
unreachable();
|
|
133
135
|
}
|
|
@@ -135,13 +137,31 @@ export class AccountManager {
|
|
|
135
137
|
const last_name = params?.lastName ?? user.last_name ?? "";
|
|
136
138
|
const phone = "";
|
|
137
139
|
const add_phone_privacy_exception = params?.sharePhoneNumber ? true : undefined;
|
|
138
|
-
await
|
|
140
|
+
await this.#c.invoke({ _: "contacts.addContact", add_phone_privacy_exception, id, first_name, last_name, phone });
|
|
141
|
+
}
|
|
142
|
+
async #getUserFull(chatId) {
|
|
143
|
+
const inputPeer = await this.#c.getInputPeer(chatId);
|
|
144
|
+
const chatId_ = await this.#c.getInputPeerChatId(inputPeer);
|
|
145
|
+
let fullChat = await this.#c.storage.getFullChat(chatId_);
|
|
146
|
+
if (fullChat != null) {
|
|
147
|
+
if (!Api.is("userFull", fullChat)) {
|
|
148
|
+
unreachable();
|
|
149
|
+
}
|
|
150
|
+
return fullChat;
|
|
151
|
+
}
|
|
152
|
+
if (canBeInputUser(inputPeer)) {
|
|
153
|
+
fullChat = (await this.#c.invoke({ _: "users.getFullUser", id: toInputUser(inputPeer) })).full_user;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
unreachable();
|
|
157
|
+
}
|
|
158
|
+
return fullChat;
|
|
139
159
|
}
|
|
140
160
|
async updateProfile(params) {
|
|
141
|
-
|
|
142
|
-
const selfId = await
|
|
143
|
-
const userFull = await
|
|
144
|
-
const entity = await
|
|
161
|
+
this.#c.storage.assertUser("updateProfile");
|
|
162
|
+
const selfId = await this.#c.getSelfId();
|
|
163
|
+
const userFull = await this.#getUserFull(selfId);
|
|
164
|
+
const entity = await this.#c.getEntity(Api.chatIdToPeer(selfId));
|
|
145
165
|
if (!Api.is("user", entity)) {
|
|
146
166
|
unreachable();
|
|
147
167
|
}
|
|
@@ -167,33 +187,33 @@ export class AccountManager {
|
|
|
167
187
|
if (!params?.firstName && !params?.lastName && !params?.bio) {
|
|
168
188
|
throw new InputError("At least one parameter must be specified.");
|
|
169
189
|
}
|
|
170
|
-
await
|
|
190
|
+
await this.#c.invoke({ _: "account.updateProfile", first_name: params.firstName, last_name: params.lastName, about: params.bio });
|
|
171
191
|
}
|
|
172
192
|
async setBirthday(params) {
|
|
173
|
-
|
|
193
|
+
this.#c.storage.assertUser("setBirthday");
|
|
174
194
|
const birthday = params?.birthday ? birthdayToTlObject(params.birthday) : undefined;
|
|
175
|
-
await
|
|
195
|
+
await this.#c.invoke({ _: "account.updateBirthday", birthday });
|
|
176
196
|
}
|
|
177
197
|
async setPersonalChannel(params) {
|
|
178
|
-
|
|
198
|
+
this.#c.storage.assertUser("setPersonalChannel");
|
|
179
199
|
let channel = { _: "inputChannelEmpty" };
|
|
180
200
|
if (params?.chatId) {
|
|
181
|
-
channel = await
|
|
201
|
+
channel = await this.#c.getInputChannel(params.chatId);
|
|
182
202
|
}
|
|
183
|
-
await
|
|
203
|
+
await this.#c.invoke({ _: "account.updatePersonalChannel", channel });
|
|
184
204
|
}
|
|
185
205
|
async setNameColor(color, params) {
|
|
186
|
-
|
|
206
|
+
this.#c.storage.assertUser("setNameColor");
|
|
187
207
|
const background_emoji_id = params?.customEmojiId ? BigInt(params.customEmojiId) : undefined;
|
|
188
|
-
await
|
|
208
|
+
await this.#c.invoke({ _: "account.updateColor", color, background_emoji_id });
|
|
189
209
|
}
|
|
190
210
|
async setProfileColor(color, params) {
|
|
191
|
-
|
|
211
|
+
this.#c.storage.assertUser("setProfileColor");
|
|
192
212
|
const background_emoji_id = params?.customEmojiId ? BigInt(params.customEmojiId) : undefined;
|
|
193
|
-
await
|
|
213
|
+
await this.#c.invoke({ _: "account.updateColor", for_profile: true, color, background_emoji_id });
|
|
194
214
|
}
|
|
195
215
|
async setLocation(params) {
|
|
196
|
-
|
|
216
|
+
this.#c.storage.assertUser("setLocation");
|
|
197
217
|
let address = params?.address;
|
|
198
218
|
if (typeof address === "string") {
|
|
199
219
|
address = address.trim();
|
|
@@ -208,38 +228,6 @@ export class AccountManager {
|
|
|
208
228
|
if (params?.latitude && params.longitude) {
|
|
209
229
|
geo_point = { _: "inputGeoPoint", lat: params.latitude, long: params.longitude };
|
|
210
230
|
}
|
|
211
|
-
await
|
|
231
|
+
await this.#c.invoke({ _: "account.updateBusinessLocation", address, geo_point });
|
|
212
232
|
}
|
|
213
233
|
}
|
|
214
|
-
_AccountManager_c = new WeakMap(), _AccountManager_instances = new WeakSet(), _AccountManager_toggleUsername = async function _AccountManager_toggleUsername(id, username, active) {
|
|
215
|
-
const peer = await __classPrivateFieldGet(this, _AccountManager_c, "f").getInputPeer(id);
|
|
216
|
-
if (Api.is("inputPeerSelf", peer)) {
|
|
217
|
-
await __classPrivateFieldGet(this, _AccountManager_c, "f").invoke({ _: "account.toggleUsername", username, active });
|
|
218
|
-
}
|
|
219
|
-
else if (canBeInputUser(peer)) {
|
|
220
|
-
await __classPrivateFieldGet(this, _AccountManager_c, "f").invoke({ _: "bots.toggleUsername", bot: toInputUser(peer), username, active });
|
|
221
|
-
}
|
|
222
|
-
else if (canBeInputChannel(peer)) {
|
|
223
|
-
await __classPrivateFieldGet(this, _AccountManager_c, "f").invoke({ _: "channels.toggleUsername", channel: toInputChannel(peer), username, active });
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
unreachable();
|
|
227
|
-
}
|
|
228
|
-
}, _AccountManager_getUserFull = async function _AccountManager_getUserFull(chatId) {
|
|
229
|
-
const inputPeer = await __classPrivateFieldGet(this, _AccountManager_c, "f").getInputPeer(chatId);
|
|
230
|
-
const chatId_ = await __classPrivateFieldGet(this, _AccountManager_c, "f").getInputPeerChatId(inputPeer);
|
|
231
|
-
let fullChat = await __classPrivateFieldGet(this, _AccountManager_c, "f").storage.getFullChat(chatId_);
|
|
232
|
-
if (fullChat != null) {
|
|
233
|
-
if (!Api.is("userFull", fullChat)) {
|
|
234
|
-
unreachable();
|
|
235
|
-
}
|
|
236
|
-
return fullChat;
|
|
237
|
-
}
|
|
238
|
-
if (canBeInputUser(inputPeer)) {
|
|
239
|
-
fullChat = (await __classPrivateFieldGet(this, _AccountManager_c, "f").invoke({ _: "users.getFullUser", id: toInputUser(inputPeer) })).full_user;
|
|
240
|
-
}
|
|
241
|
-
else {
|
|
242
|
-
unreachable();
|
|
243
|
-
}
|
|
244
|
-
return fullChat;
|
|
245
|
-
};
|
|
@@ -17,70 +17,58 @@
|
|
|
17
17
|
* You should have received a copy of the GNU Lesser General Public License
|
|
18
18
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
21
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
22
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
23
|
-
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");
|
|
24
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
25
|
-
};
|
|
26
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
27
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
28
|
-
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");
|
|
29
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
30
|
-
};
|
|
31
|
-
var _BotInfoManager_instances, _BotInfoManager_c, _BotInfoManager_setMyInfo, _BotInfoManager_getMyInfo;
|
|
32
20
|
import { botCommandScopeToTlObject } from "../3_types.js";
|
|
33
21
|
export class BotInfoManager {
|
|
22
|
+
#c;
|
|
34
23
|
constructor(c) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
24
|
+
this.#c = c;
|
|
25
|
+
}
|
|
26
|
+
async #setMyInfo(info) {
|
|
27
|
+
await this.#c.invoke({ _: "bots.setBotInfo", ...info });
|
|
38
28
|
}
|
|
39
29
|
async setMyDescription(params) {
|
|
40
|
-
|
|
41
|
-
await
|
|
30
|
+
this.#c.storage.assertBot("setMyDescription");
|
|
31
|
+
await this.#setMyInfo({ description: params?.description, lang_code: params?.languageCode ?? "" });
|
|
42
32
|
}
|
|
43
33
|
async setMyName(params) {
|
|
44
|
-
|
|
45
|
-
await
|
|
34
|
+
this.#c.storage.assertBot("setMyName");
|
|
35
|
+
await this.#setMyInfo({ name: params?.name, lang_code: params?.languageCode ?? "" });
|
|
46
36
|
}
|
|
47
37
|
async setMyShortDescription(params) {
|
|
48
|
-
|
|
49
|
-
await
|
|
38
|
+
this.#c.storage.assertBot("setMyShortDescription");
|
|
39
|
+
await this.#setMyInfo({ about: params?.shortDescription, lang_code: params?.languageCode ?? "" });
|
|
40
|
+
}
|
|
41
|
+
#getMyInfo(languageCode) {
|
|
42
|
+
return this.#c.invoke({ _: "bots.getBotInfo", lang_code: languageCode ?? "" });
|
|
50
43
|
}
|
|
51
44
|
async getMyDescription(params) {
|
|
52
|
-
|
|
53
|
-
return (await
|
|
45
|
+
this.#c.storage.assertBot("getMyDescription");
|
|
46
|
+
return (await this.#getMyInfo(params?.languageCode)).description;
|
|
54
47
|
}
|
|
55
48
|
async getMyName(params) {
|
|
56
|
-
|
|
57
|
-
return (await
|
|
49
|
+
this.#c.storage.assertBot("getMyName");
|
|
50
|
+
return (await this.#getMyInfo(params?.languageCode)).description;
|
|
58
51
|
}
|
|
59
52
|
async getMyShortDescription(params) {
|
|
60
|
-
|
|
61
|
-
return (await
|
|
53
|
+
this.#c.storage.assertBot("getMyShortDescription");
|
|
54
|
+
return (await this.#getMyInfo(params?.languageCode)).about;
|
|
62
55
|
}
|
|
63
56
|
async getMyCommands(params) {
|
|
64
|
-
|
|
65
|
-
const commands_ = await
|
|
57
|
+
this.#c.storage.assertBot("getMyCommands");
|
|
58
|
+
const commands_ = await this.#c.invoke({
|
|
66
59
|
_: "bots.getBotCommands",
|
|
67
60
|
lang_code: params?.languageCode ?? "",
|
|
68
|
-
scope: await botCommandScopeToTlObject(params?.scope ?? { type: "default" },
|
|
61
|
+
scope: await botCommandScopeToTlObject(params?.scope ?? { type: "default" }, this.#c.getInputPeer),
|
|
69
62
|
});
|
|
70
63
|
return commands_.map((v) => ({ command: v.command, description: v.description }));
|
|
71
64
|
}
|
|
72
65
|
async setMyCommands(commands, params) {
|
|
73
|
-
|
|
74
|
-
await
|
|
66
|
+
this.#c.storage.assertBot("setMyCommands");
|
|
67
|
+
await this.#c.invoke({
|
|
75
68
|
_: "bots.setBotCommands",
|
|
76
69
|
commands: commands.map((v) => ({ ...v, _: "botCommand" })),
|
|
77
70
|
lang_code: params?.languageCode ?? "",
|
|
78
|
-
scope: await botCommandScopeToTlObject(params?.scope ?? { type: "default" },
|
|
71
|
+
scope: await botCommandScopeToTlObject(params?.scope ?? { type: "default" }, this.#c.getInputPeer),
|
|
79
72
|
});
|
|
80
73
|
}
|
|
81
74
|
}
|
|
82
|
-
_BotInfoManager_c = new WeakMap(), _BotInfoManager_instances = new WeakSet(), _BotInfoManager_setMyInfo = async function _BotInfoManager_setMyInfo(info) {
|
|
83
|
-
await __classPrivateFieldGet(this, _BotInfoManager_c, "f").invoke({ _: "bots.setBotInfo", ...info });
|
|
84
|
-
}, _BotInfoManager_getMyInfo = function _BotInfoManager_getMyInfo(languageCode) {
|
|
85
|
-
return __classPrivateFieldGet(this, _BotInfoManager_c, "f").invoke({ _: "bots.getBotInfo", lang_code: languageCode ?? "" });
|
|
86
|
-
};
|
|
@@ -17,39 +17,27 @@
|
|
|
17
17
|
* You should have received a copy of the GNU Lesser General Public License
|
|
18
18
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
21
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
22
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
23
|
-
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");
|
|
24
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
25
|
-
};
|
|
26
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
27
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
28
|
-
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");
|
|
29
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
30
|
-
};
|
|
31
|
-
var _BusinessConnectionManager_c;
|
|
32
20
|
import { Api } from "../2_tl.js";
|
|
33
21
|
import { constructBusinessConnection } from "../3_types.js";
|
|
34
22
|
const businessConnectionManagerUpdates = [
|
|
35
23
|
"updateBotBusinessConnect",
|
|
36
24
|
];
|
|
37
25
|
export class BusinessConnectionManager {
|
|
26
|
+
#c;
|
|
38
27
|
constructor(c) {
|
|
39
|
-
|
|
40
|
-
__classPrivateFieldSet(this, _BusinessConnectionManager_c, c, "f");
|
|
28
|
+
this.#c = c;
|
|
41
29
|
}
|
|
42
30
|
async getBusinessConnection(id) {
|
|
43
|
-
const connection_ = await
|
|
31
|
+
const connection_ = await this.#c.messageStorage.getBusinessConnection(id);
|
|
44
32
|
if (!connection_) {
|
|
45
|
-
const connection_ = await
|
|
33
|
+
const connection_ = await this.#c.invoke({ _: "account.getBotBusinessConnection", connection_id: id })
|
|
46
34
|
.then((v) => Api.as("updates", v))
|
|
47
35
|
.then((v) => Api.as("updateBotBusinessConnect", v.updates[0]).connection);
|
|
48
|
-
await
|
|
49
|
-
return await constructBusinessConnection(connection_,
|
|
36
|
+
await this.#c.messageStorage.setBusinessConnection(id, connection_);
|
|
37
|
+
return await constructBusinessConnection(connection_, this.#c.getEntity);
|
|
50
38
|
}
|
|
51
39
|
else {
|
|
52
|
-
return await constructBusinessConnection(connection_,
|
|
40
|
+
return await constructBusinessConnection(connection_, this.#c.getEntity);
|
|
53
41
|
}
|
|
54
42
|
}
|
|
55
43
|
canHandleUpdate(update) {
|
|
@@ -57,13 +45,12 @@ export class BusinessConnectionManager {
|
|
|
57
45
|
}
|
|
58
46
|
async handleUpdate(update) {
|
|
59
47
|
if (update.connection.disabled) {
|
|
60
|
-
await
|
|
48
|
+
await this.#c.messageStorage.setBusinessConnection(update.connection.connection_id, null);
|
|
61
49
|
}
|
|
62
50
|
else {
|
|
63
|
-
await
|
|
51
|
+
await this.#c.messageStorage.setBusinessConnection(update.connection.connection_id, update.connection);
|
|
64
52
|
}
|
|
65
|
-
const businessConnection = await constructBusinessConnection(update.connection,
|
|
53
|
+
const businessConnection = await constructBusinessConnection(update.connection, this.#c.getEntity);
|
|
66
54
|
return { businessConnection };
|
|
67
55
|
}
|
|
68
56
|
}
|
|
69
|
-
_BusinessConnectionManager_c = new WeakMap();
|