@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
package/esm/client/5_client.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 _Client_instances, _Client_clients, _Client_downloadPools, _Client_uploadPools, _Client_guaranteeUpdateDelivery, _Client_accountManager, _Client_botInfoManager, _Client_businessConnectionManager, _Client_fileManager, _Client_networkStatisticsManager, _Client_paymentManager, _Client_reactionManager, _Client_translationsManager, _Client_updateManager, _Client_messageManager, _Client_videoChatManager, _Client_callbackQueryManager, _Client_chatListManager, _Client_chatManager, _Client_forumManager, _Client_giftManager, _Client_inlineQueryManager, _Client_linkPreviewManager, _Client_pollManager, _Client_storyManager, _Client_managers, _Client_storage_, _Client_messageStorage_, _Client_parseMode, _Client_apiId, _Client_apiHash, _Client_transportProvider, _Client_publicKeys, _Client_outgoingMessages, _Client_persistCache, _Client_disableUpdates, _Client_authString, _Client_initialDc, _Client_L, _Client_LsignIn, _Client_LupdateGapRecoveryLoop, _Client_LhandleMigrationError, _Client_Lmin, _Client_setMainClient, _Client_newClient, _Client_disconnectAllClients, _Client_client_get, _Client_constructContext, _Client_propagateConnectionState, _Client_lastPropagatedConnectionState, _Client_stateChangeHandler, _Client_storageInited, _Client_initStorage, _Client_connectMutex, _Client_lastPropagatedAuthorizationState, _Client_propagateAuthorizationState, _Client_getSelfId, _Client_getIsPremium, _Client_lastUpdates, _Client_updateGapRecoveryLoopAbortController, _Client_startUpdateGapRecoveryLoop, _Client_updateGapRecoveryLoop, _Client_clientDisconnectionLoopAbortController, _Client_startClientDisconnectionLoop, _Client_clientDisconnectionLoop, _Client_getClient, _Client_getMainClientMutex, _Client_getMainClient, _Client_getDownloadClient, _Client_getUploadPoolSize, _Client_getUploadClient, _Client_setupClient, _Client_importAuthorization, _Client_invoke, _Client_handleInvokeError, _Client_authStringImported, _Client_getUserAccessHash, _Client_getChannelAccessHash, _Client_getInputPeerChatId, _Client_getInputPeerInner, _Client_getMinInputPeer, _Client_handleCtxUpdate, _Client_queueHandleCtxUpdate, _Client_handleUpdate, _Client_lastGetMe, _Client_getMe, _Client_previouslyConnected, _Client_lastConnectionState, _Client_onConnectionStateChange;
|
|
32
20
|
import { delay, MINUTE, SECOND, unreachable } from "../0_deps.js";
|
|
33
21
|
import { AccessError, ConnectionError, InputError } from "../0_errors.js";
|
|
34
22
|
import { cleanObject, drop, getLogger, mustPrompt, mustPromptOneOf, Mutex, ZERO_CHANNEL_ID } from "../1_utilities.js";
|
|
@@ -79,615 +67,130 @@ const getEntity = Symbol();
|
|
|
79
67
|
* An MTKruto client.
|
|
80
68
|
*/
|
|
81
69
|
export class Client extends Composer {
|
|
70
|
+
#clients = new Array();
|
|
71
|
+
#downloadPools = {};
|
|
72
|
+
#uploadPools = {};
|
|
73
|
+
#guaranteeUpdateDelivery;
|
|
74
|
+
// 2_
|
|
75
|
+
#accountManager;
|
|
76
|
+
#botInfoManager;
|
|
77
|
+
#businessConnectionManager;
|
|
78
|
+
#fileManager;
|
|
79
|
+
#networkStatisticsManager;
|
|
80
|
+
#paymentManager;
|
|
81
|
+
#reactionManager;
|
|
82
|
+
#translationsManager;
|
|
83
|
+
#updateManager;
|
|
84
|
+
// 3_
|
|
85
|
+
#messageManager;
|
|
86
|
+
#videoChatManager;
|
|
87
|
+
// 4_
|
|
88
|
+
#callbackQueryManager;
|
|
89
|
+
#chatListManager;
|
|
90
|
+
#chatManager;
|
|
91
|
+
#forumManager;
|
|
92
|
+
#giftManager;
|
|
93
|
+
#inlineQueryManager;
|
|
94
|
+
#linkPreviewManager;
|
|
95
|
+
#pollManager;
|
|
96
|
+
#storyManager;
|
|
97
|
+
// deno-lint-ignore no-explicit-any
|
|
98
|
+
#managers;
|
|
82
99
|
// deno-lint-ignore no-explicit-any
|
|
83
100
|
get managers() {
|
|
84
|
-
return
|
|
101
|
+
return this.#managers ?? (this.#managers ??= {
|
|
85
102
|
// 2_
|
|
86
|
-
accountManager:
|
|
87
|
-
botInfoManager:
|
|
88
|
-
businessConnectionManager:
|
|
89
|
-
fileManager:
|
|
90
|
-
networkStatisticsManager:
|
|
91
|
-
paymentManager:
|
|
92
|
-
reactionManager:
|
|
93
|
-
translationsManager:
|
|
94
|
-
updateManager:
|
|
103
|
+
accountManager: this.#accountManager,
|
|
104
|
+
botInfoManager: this.#botInfoManager,
|
|
105
|
+
businessConnectionManager: this.#businessConnectionManager,
|
|
106
|
+
fileManager: this.#fileManager,
|
|
107
|
+
networkStatisticsManager: this.#networkStatisticsManager,
|
|
108
|
+
paymentManager: this.#paymentManager,
|
|
109
|
+
reactionManager: this.#reactionManager,
|
|
110
|
+
translationsManager: this.#translationsManager,
|
|
111
|
+
updateManager: this.#updateManager,
|
|
95
112
|
// 3_
|
|
96
|
-
messageManager:
|
|
97
|
-
videoChatManager:
|
|
113
|
+
messageManager: this.#messageManager,
|
|
114
|
+
videoChatManager: this.#videoChatManager,
|
|
98
115
|
// 4_
|
|
99
|
-
callbackQueryManager:
|
|
100
|
-
chatListManager:
|
|
101
|
-
chatManager:
|
|
102
|
-
forumManager:
|
|
103
|
-
giftManager:
|
|
104
|
-
inlineQueryManager:
|
|
105
|
-
linkPreviewManager:
|
|
106
|
-
pollManager:
|
|
107
|
-
storyManager:
|
|
108
|
-
}
|
|
116
|
+
callbackQueryManager: this.#callbackQueryManager,
|
|
117
|
+
chatListManager: this.#chatListManager,
|
|
118
|
+
chatManager: this.#chatManager,
|
|
119
|
+
forumManager: this.#forumManager,
|
|
120
|
+
giftManager: this.#giftManager,
|
|
121
|
+
inlineQueryManager: this.#inlineQueryManager,
|
|
122
|
+
linkPreviewManager: this.#linkPreviewManager,
|
|
123
|
+
pollManager: this.#pollManager,
|
|
124
|
+
storyManager: this.#storyManager,
|
|
125
|
+
});
|
|
109
126
|
}
|
|
127
|
+
#storage_;
|
|
128
|
+
#messageStorage_;
|
|
129
|
+
storage;
|
|
130
|
+
messageStorage;
|
|
131
|
+
#parseMode;
|
|
132
|
+
#apiId;
|
|
133
|
+
#apiHash;
|
|
134
|
+
#transportProvider;
|
|
135
|
+
appVersion;
|
|
136
|
+
deviceModel;
|
|
137
|
+
language;
|
|
138
|
+
platform;
|
|
139
|
+
systemLangCode;
|
|
140
|
+
systemVersion;
|
|
141
|
+
#publicKeys;
|
|
142
|
+
#outgoingMessages;
|
|
143
|
+
#persistCache;
|
|
144
|
+
#disableUpdates;
|
|
145
|
+
#authString;
|
|
146
|
+
#initialDc;
|
|
147
|
+
#L;
|
|
148
|
+
#LsignIn;
|
|
149
|
+
#LupdateGapRecoveryLoop;
|
|
150
|
+
#LhandleMigrationError;
|
|
151
|
+
#Lmin;
|
|
110
152
|
/**
|
|
111
153
|
* Constructs the client.
|
|
112
154
|
*/
|
|
113
155
|
constructor(params) {
|
|
114
156
|
super();
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
_Client_businessConnectionManager.set(this, void 0);
|
|
124
|
-
_Client_fileManager.set(this, void 0);
|
|
125
|
-
_Client_networkStatisticsManager.set(this, void 0);
|
|
126
|
-
_Client_paymentManager.set(this, void 0);
|
|
127
|
-
_Client_reactionManager.set(this, void 0);
|
|
128
|
-
_Client_translationsManager.set(this, void 0);
|
|
129
|
-
_Client_updateManager.set(this, void 0);
|
|
130
|
-
// 3_
|
|
131
|
-
_Client_messageManager.set(this, void 0);
|
|
132
|
-
_Client_videoChatManager.set(this, void 0);
|
|
133
|
-
// 4_
|
|
134
|
-
_Client_callbackQueryManager.set(this, void 0);
|
|
135
|
-
_Client_chatListManager.set(this, void 0);
|
|
136
|
-
_Client_chatManager.set(this, void 0);
|
|
137
|
-
_Client_forumManager.set(this, void 0);
|
|
138
|
-
_Client_giftManager.set(this, void 0);
|
|
139
|
-
_Client_inlineQueryManager.set(this, void 0);
|
|
140
|
-
_Client_linkPreviewManager.set(this, void 0);
|
|
141
|
-
_Client_pollManager.set(this, void 0);
|
|
142
|
-
_Client_storyManager.set(this, void 0);
|
|
143
|
-
// deno-lint-ignore no-explicit-any
|
|
144
|
-
_Client_managers.set(this, void 0);
|
|
145
|
-
_Client_storage_.set(this, void 0);
|
|
146
|
-
_Client_messageStorage_.set(this, void 0);
|
|
147
|
-
Object.defineProperty(this, "storage", {
|
|
148
|
-
enumerable: true,
|
|
149
|
-
configurable: true,
|
|
150
|
-
writable: true,
|
|
151
|
-
value: void 0
|
|
152
|
-
});
|
|
153
|
-
Object.defineProperty(this, "messageStorage", {
|
|
154
|
-
enumerable: true,
|
|
155
|
-
configurable: true,
|
|
156
|
-
writable: true,
|
|
157
|
-
value: void 0
|
|
158
|
-
});
|
|
159
|
-
_Client_parseMode.set(this, void 0);
|
|
160
|
-
_Client_apiId.set(this, void 0);
|
|
161
|
-
_Client_apiHash.set(this, void 0);
|
|
162
|
-
_Client_transportProvider.set(this, void 0);
|
|
163
|
-
Object.defineProperty(this, "appVersion", {
|
|
164
|
-
enumerable: true,
|
|
165
|
-
configurable: true,
|
|
166
|
-
writable: true,
|
|
167
|
-
value: void 0
|
|
168
|
-
});
|
|
169
|
-
Object.defineProperty(this, "deviceModel", {
|
|
170
|
-
enumerable: true,
|
|
171
|
-
configurable: true,
|
|
172
|
-
writable: true,
|
|
173
|
-
value: void 0
|
|
174
|
-
});
|
|
175
|
-
Object.defineProperty(this, "language", {
|
|
176
|
-
enumerable: true,
|
|
177
|
-
configurable: true,
|
|
178
|
-
writable: true,
|
|
179
|
-
value: void 0
|
|
180
|
-
});
|
|
181
|
-
Object.defineProperty(this, "platform", {
|
|
182
|
-
enumerable: true,
|
|
183
|
-
configurable: true,
|
|
184
|
-
writable: true,
|
|
185
|
-
value: void 0
|
|
186
|
-
});
|
|
187
|
-
Object.defineProperty(this, "systemLangCode", {
|
|
188
|
-
enumerable: true,
|
|
189
|
-
configurable: true,
|
|
190
|
-
writable: true,
|
|
191
|
-
value: void 0
|
|
192
|
-
});
|
|
193
|
-
Object.defineProperty(this, "systemVersion", {
|
|
194
|
-
enumerable: true,
|
|
195
|
-
configurable: true,
|
|
196
|
-
writable: true,
|
|
197
|
-
value: void 0
|
|
198
|
-
});
|
|
199
|
-
_Client_publicKeys.set(this, void 0);
|
|
200
|
-
_Client_outgoingMessages.set(this, void 0);
|
|
201
|
-
_Client_persistCache.set(this, void 0);
|
|
202
|
-
_Client_disableUpdates.set(this, void 0);
|
|
203
|
-
_Client_authString.set(this, void 0);
|
|
204
|
-
_Client_initialDc.set(this, void 0);
|
|
205
|
-
_Client_L.set(this, void 0);
|
|
206
|
-
_Client_LsignIn.set(this, void 0);
|
|
207
|
-
_Client_LupdateGapRecoveryLoop.set(this, void 0);
|
|
208
|
-
_Client_LhandleMigrationError.set(this, void 0);
|
|
209
|
-
_Client_Lmin.set(this, void 0);
|
|
210
|
-
_Client_constructContext.set(this, async (update) => {
|
|
211
|
-
const msg = "message" in update ? update.message : "editedMessage" in update ? update.editedMessage : "scheduledMessage" in update ? update.scheduledMessage : "callbackQuery" in update ? update.callbackQuery.message : undefined;
|
|
212
|
-
const reactions = "messageInteractions" in update ? update.messageInteractions : undefined;
|
|
213
|
-
const mustGetMsg = () => {
|
|
214
|
-
if (msg !== undefined) {
|
|
215
|
-
return { chatId: msg.chat.id, messageId: msg.id, businessConnectionId: msg.businessConnectionId, senderId: msg.from?.id, userId: msg.from?.id };
|
|
216
|
-
}
|
|
217
|
-
else if (reactions !== undefined) {
|
|
218
|
-
return { chatId: reactions.chatId, messageId: reactions.messageId };
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
unreachable();
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
const mustGetUserId = () => {
|
|
225
|
-
if (msg?.from) {
|
|
226
|
-
return msg.from.id;
|
|
227
|
-
}
|
|
228
|
-
else if ("callbackQuery" in update) {
|
|
229
|
-
return update.callbackQuery.from.id;
|
|
230
|
-
}
|
|
231
|
-
else if ("chosenInlineResult" in update) {
|
|
232
|
-
return update.chosenInlineResult.from.id;
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
unreachable();
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
const mustGetInlineMsgId = () => {
|
|
239
|
-
if ("chosenInlineResult" in update) {
|
|
240
|
-
if (update.chosenInlineResult.inlineMessageId) {
|
|
241
|
-
return update.chosenInlineResult.inlineMessageId;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
else if ("callbackQuery" in update) {
|
|
245
|
-
if (update.callbackQuery.inlineMessageId) {
|
|
246
|
-
return update.callbackQuery.inlineMessageId;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
unreachable();
|
|
250
|
-
};
|
|
251
|
-
const chat_ = "messageReactions" in update ? update.messageReactions.chat : "messageReactionCount" in update ? update.messageReactionCount.chat : "chatMember" in update ? update.chatMember.chat : "myChatMember" in update ? update.myChatMember.chat : "joinRequest" in update ? update.joinRequest.chat : "story" in update ? update.story.chat : undefined;
|
|
252
|
-
const chat = chat_ ?? msg?.chat;
|
|
253
|
-
const from = "callbackQuery" in update ? update.callbackQuery.from : "inlineQuery" in update ? update.inlineQuery.from : "chatMember" in update ? update.chatMember.from : "myChatMember" in update ? update.myChatMember.from : "messageReactions" in update ? update.messageReactions.user : "preCheckoutQuery" in update ? update.preCheckoutQuery.from : "joinRequest" in update ? update.joinRequest.from : "businessConnection" in update ? update.businessConnection.user : "pollAnswer" in update ? update.pollAnswer.from : msg?.from ? msg.from : undefined;
|
|
254
|
-
const getReplyTo = (quote, chatId, messageId) => {
|
|
255
|
-
if ("story" in update) {
|
|
256
|
-
return { chatId: update.story.chat.id, storyId: update.story.id };
|
|
257
|
-
}
|
|
258
|
-
const isPrivate = chatId > 0;
|
|
259
|
-
const shouldQuote = quote === undefined ? !isPrivate : quote;
|
|
260
|
-
return shouldQuote ? { messageId } : undefined;
|
|
261
|
-
};
|
|
262
|
-
const me = "connectionState" in update ? __classPrivateFieldGet(this, _Client_lastGetMe, "f") : ("authorizationState" in update && !update.authorizationState.authorized) ? __classPrivateFieldGet(this, _Client_lastGetMe, "f") : await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getMe).call(this);
|
|
263
|
-
const context = {
|
|
264
|
-
...update,
|
|
265
|
-
client: this,
|
|
266
|
-
me: (me == null ? undefined : me),
|
|
267
|
-
msg: msg,
|
|
268
|
-
chat: chat,
|
|
269
|
-
from: from,
|
|
270
|
-
get toJSON() {
|
|
271
|
-
return () => update;
|
|
272
|
-
},
|
|
273
|
-
reply: (text, params) => {
|
|
274
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
275
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
276
|
-
return this.sendMessage(chatId, text, { ...params, replyTo, businessConnectionId });
|
|
277
|
-
},
|
|
278
|
-
replyPoll: (question, options, params) => {
|
|
279
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
280
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
281
|
-
return this.sendPoll(chatId, question, options, { ...params, replyTo, businessConnectionId });
|
|
282
|
-
},
|
|
283
|
-
replyPhoto: (photo, params) => {
|
|
284
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
285
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
286
|
-
return this.sendPhoto(chatId, photo, { ...params, replyTo, businessConnectionId });
|
|
287
|
-
},
|
|
288
|
-
replyMediaGroup: (media, params) => {
|
|
289
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
290
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
291
|
-
return this.sendMediaGroup(chatId, media, { ...params, replyTo, businessConnectionId });
|
|
292
|
-
},
|
|
293
|
-
replyInvoice: (title, description, payload, currency, prices, params) => {
|
|
294
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
295
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
296
|
-
return this.sendInvoice(chatId, title, description, payload, currency, prices, { ...params, replyTo, businessConnectionId });
|
|
297
|
-
},
|
|
298
|
-
replyDocument: (document, params) => {
|
|
299
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
300
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
301
|
-
return this.sendDocument(chatId, document, { ...params, replyTo, businessConnectionId });
|
|
302
|
-
},
|
|
303
|
-
replySticker: (sticker, params) => {
|
|
304
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
305
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
306
|
-
return this.sendSticker(chatId, sticker, { ...params, replyTo, businessConnectionId });
|
|
307
|
-
},
|
|
308
|
-
replyContact: (firstName, number, params) => {
|
|
309
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
310
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
311
|
-
return this.sendContact(chatId, firstName, number, { ...params, replyTo, businessConnectionId });
|
|
312
|
-
},
|
|
313
|
-
replyLocation: (latitude, longitude, params) => {
|
|
314
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
315
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
316
|
-
return this.sendLocation(chatId, latitude, longitude, { ...params, replyTo, businessConnectionId });
|
|
317
|
-
},
|
|
318
|
-
replyDice: (params) => {
|
|
319
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
320
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
321
|
-
return this.sendDice(chatId, { ...params, replyTo, businessConnectionId });
|
|
322
|
-
},
|
|
323
|
-
replyVenue: (latitude, longitude, title, address, params) => {
|
|
324
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
325
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
326
|
-
return this.sendVenue(chatId, latitude, longitude, title, address, { ...params, replyTo, businessConnectionId });
|
|
327
|
-
},
|
|
328
|
-
replyVideo: (video, params) => {
|
|
329
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
330
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
331
|
-
return this.sendVideo(chatId, video, { ...params, replyTo, businessConnectionId });
|
|
332
|
-
},
|
|
333
|
-
replyAnimation: (document, params) => {
|
|
334
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
335
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
336
|
-
return this.sendAnimation(chatId, document, { ...params, replyTo, businessConnectionId });
|
|
337
|
-
},
|
|
338
|
-
replyVoice: (document, params) => {
|
|
339
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
340
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
341
|
-
return this.sendVoice(chatId, document, { ...params, replyTo, businessConnectionId });
|
|
342
|
-
},
|
|
343
|
-
replyAudio: (document, params) => {
|
|
344
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
345
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
346
|
-
return this.sendAudio(chatId, document, { ...params, replyTo, businessConnectionId });
|
|
347
|
-
},
|
|
348
|
-
replyVideoNote: (videoNote, params) => {
|
|
349
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
350
|
-
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
351
|
-
return this.sendVideoNote(chatId, videoNote, { ...params, replyTo, businessConnectionId });
|
|
352
|
-
},
|
|
353
|
-
delete: () => {
|
|
354
|
-
const { chatId, messageId } = mustGetMsg();
|
|
355
|
-
return this.deleteMessage(chatId, messageId);
|
|
356
|
-
},
|
|
357
|
-
forward: (to, params) => {
|
|
358
|
-
const { chatId, messageId } = mustGetMsg();
|
|
359
|
-
return this.forwardMessage(chatId, to, messageId, params);
|
|
360
|
-
},
|
|
361
|
-
pin: (params) => {
|
|
362
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
363
|
-
return this.pinMessage(chatId, messageId, { ...params, businessConnectionId });
|
|
364
|
-
},
|
|
365
|
-
unpin: () => {
|
|
366
|
-
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
367
|
-
return this.unpinMessage(chatId, messageId, { businessConnectionId });
|
|
368
|
-
},
|
|
369
|
-
banSender: (params) => {
|
|
370
|
-
const { chatId, senderId } = mustGetMsg();
|
|
371
|
-
if (!senderId) {
|
|
372
|
-
unreachable();
|
|
373
|
-
}
|
|
374
|
-
return this.banChatMember(chatId, senderId, params);
|
|
375
|
-
},
|
|
376
|
-
kickSender: () => {
|
|
377
|
-
const { chatId, senderId } = mustGetMsg();
|
|
378
|
-
if (!senderId) {
|
|
379
|
-
unreachable();
|
|
380
|
-
}
|
|
381
|
-
return this.kickChatMember(chatId, senderId);
|
|
382
|
-
},
|
|
383
|
-
setSenderRights: (params) => {
|
|
384
|
-
const { chatId, senderId } = mustGetMsg();
|
|
385
|
-
if (!senderId) {
|
|
386
|
-
unreachable();
|
|
387
|
-
}
|
|
388
|
-
return this.setChatMemberRights(chatId, senderId, params);
|
|
389
|
-
},
|
|
390
|
-
getChatAdministrators: () => {
|
|
391
|
-
const { chatId } = mustGetMsg();
|
|
392
|
-
return this.getChatAdministrators(chatId);
|
|
393
|
-
},
|
|
394
|
-
react: (reactions, params) => {
|
|
395
|
-
const { chatId, messageId } = mustGetMsg();
|
|
396
|
-
return this.setReactions(chatId, messageId, reactions, params);
|
|
397
|
-
},
|
|
398
|
-
answerCallbackQuery: (params) => {
|
|
399
|
-
if (!("callbackQuery" in update)) {
|
|
400
|
-
unreachable();
|
|
401
|
-
}
|
|
402
|
-
return this.answerCallbackQuery(update.callbackQuery.id, params);
|
|
403
|
-
},
|
|
404
|
-
answerInlineQuery: (results, params) => {
|
|
405
|
-
if (!("inlineQuery" in update)) {
|
|
406
|
-
unreachable();
|
|
407
|
-
}
|
|
408
|
-
return this.answerInlineQuery(update.inlineQuery.id, results, params);
|
|
409
|
-
},
|
|
410
|
-
sendChatAction: (chatAction, params) => {
|
|
411
|
-
const { chatId } = mustGetMsg();
|
|
412
|
-
return this.sendChatAction(chatId, chatAction, params);
|
|
413
|
-
},
|
|
414
|
-
editInlineMessageText: (text, params) => {
|
|
415
|
-
const inlineMessageId = mustGetInlineMsgId();
|
|
416
|
-
return this.editInlineMessageText(inlineMessageId, text, params);
|
|
417
|
-
},
|
|
418
|
-
editInlineMessageMedia: (media, params) => {
|
|
419
|
-
const inlineMessageId = mustGetInlineMsgId();
|
|
420
|
-
return this.editInlineMessageMedia(inlineMessageId, media, params);
|
|
421
|
-
},
|
|
422
|
-
editInlineMessageCaption: (params) => {
|
|
423
|
-
const inlineMessageId = mustGetInlineMsgId();
|
|
424
|
-
return this.editInlineMessageCaption(inlineMessageId, params);
|
|
425
|
-
},
|
|
426
|
-
editInlineMessageLiveLocation: (latitude, longitude, params) => {
|
|
427
|
-
const inlineMessageId = mustGetInlineMsgId();
|
|
428
|
-
return this.editInlineMessageLiveLocation(inlineMessageId, latitude, longitude, params);
|
|
429
|
-
},
|
|
430
|
-
editInlineMessageReplyMarkup: (params) => {
|
|
431
|
-
const inlineMessageId = mustGetInlineMsgId();
|
|
432
|
-
return this.editInlineMessageReplyMarkup(inlineMessageId, params);
|
|
433
|
-
},
|
|
434
|
-
editMessageText: (messageId, text, params) => {
|
|
435
|
-
const { chatId } = mustGetMsg();
|
|
436
|
-
return this.editMessageText(chatId, messageId, text, params);
|
|
437
|
-
},
|
|
438
|
-
editMessageCaption: (messageId, params) => {
|
|
439
|
-
const { chatId } = mustGetMsg();
|
|
440
|
-
return this.editMessageCaption(chatId, messageId, params);
|
|
441
|
-
},
|
|
442
|
-
editMessageMedia: (messageId, media, params) => {
|
|
443
|
-
const { chatId } = mustGetMsg();
|
|
444
|
-
return this.editMessageMedia(chatId, messageId, media, params);
|
|
445
|
-
},
|
|
446
|
-
editMessageLiveLocation: (messageId, latitude, longitude, params) => {
|
|
447
|
-
const { chatId } = mustGetMsg();
|
|
448
|
-
return this.editMessageLiveLocation(chatId, messageId, latitude, longitude, params);
|
|
449
|
-
},
|
|
450
|
-
editMessageReplyMarkup: (messageId, params) => {
|
|
451
|
-
const { chatId } = mustGetMsg();
|
|
452
|
-
return this.editMessageReplyMarkup(chatId, messageId, params);
|
|
453
|
-
},
|
|
454
|
-
getMessage: (messageId) => {
|
|
455
|
-
const { chatId } = mustGetMsg();
|
|
456
|
-
return this.getMessage(chatId, messageId);
|
|
457
|
-
},
|
|
458
|
-
getMessages: (messageIds) => {
|
|
459
|
-
const { chatId } = mustGetMsg();
|
|
460
|
-
return this.getMessages(chatId, messageIds);
|
|
461
|
-
},
|
|
462
|
-
forwardMessage: (to, messageId, params) => {
|
|
463
|
-
const { chatId } = mustGetMsg();
|
|
464
|
-
return this.forwardMessage(chatId, to, messageId, params);
|
|
465
|
-
},
|
|
466
|
-
forwardMessages: (to, messageIds, params) => {
|
|
467
|
-
const { chatId } = mustGetMsg();
|
|
468
|
-
return this.forwardMessages(chatId, to, messageIds, params);
|
|
469
|
-
},
|
|
470
|
-
deleteMessage: (messageId, params) => {
|
|
471
|
-
const { chatId } = mustGetMsg();
|
|
472
|
-
return this.deleteMessage(chatId, messageId, params);
|
|
473
|
-
},
|
|
474
|
-
deleteMessages: (messageIds, params) => {
|
|
475
|
-
const { chatId } = mustGetMsg();
|
|
476
|
-
return this.deleteMessages(chatId, messageIds, params);
|
|
477
|
-
},
|
|
478
|
-
pinMessage: (messageId, params) => {
|
|
479
|
-
const { chatId } = mustGetMsg();
|
|
480
|
-
return this.pinMessage(chatId, messageId, params);
|
|
481
|
-
},
|
|
482
|
-
unpinMessage: (messageId) => {
|
|
483
|
-
const { chatId } = mustGetMsg();
|
|
484
|
-
return this.unpinMessage(chatId, messageId);
|
|
485
|
-
},
|
|
486
|
-
unpinMessages: () => {
|
|
487
|
-
const { chatId } = mustGetMsg();
|
|
488
|
-
return this.unpinMessages(chatId);
|
|
489
|
-
},
|
|
490
|
-
setAvailableReactions: (availableReactions) => {
|
|
491
|
-
const { chatId } = mustGetMsg();
|
|
492
|
-
return this.setAvailableReactions(chatId, availableReactions);
|
|
493
|
-
},
|
|
494
|
-
addReaction: (messageId, reaction, params) => {
|
|
495
|
-
const { chatId } = mustGetMsg();
|
|
496
|
-
return this.addReaction(chatId, messageId, reaction, params);
|
|
497
|
-
},
|
|
498
|
-
removeReaction: (messageId, reaction) => {
|
|
499
|
-
const { chatId } = mustGetMsg();
|
|
500
|
-
return this.removeReaction(chatId, messageId, reaction);
|
|
501
|
-
},
|
|
502
|
-
setReactions: (messageId, reactions, params) => {
|
|
503
|
-
const { chatId } = mustGetMsg();
|
|
504
|
-
return this.setReactions(chatId, messageId, reactions, params);
|
|
505
|
-
},
|
|
506
|
-
read: () => {
|
|
507
|
-
const { chatId, messageId } = mustGetMsg();
|
|
508
|
-
return this.readMessages(chatId, messageId);
|
|
509
|
-
},
|
|
510
|
-
setChatPhoto: (photo, params) => {
|
|
511
|
-
const { chatId } = mustGetMsg();
|
|
512
|
-
return this.setChatPhoto(chatId, photo, params);
|
|
513
|
-
},
|
|
514
|
-
deleteChatPhoto: () => {
|
|
515
|
-
const { chatId } = mustGetMsg();
|
|
516
|
-
return this.deleteChatPhoto(chatId);
|
|
517
|
-
},
|
|
518
|
-
banChatMember: (memberId, params) => {
|
|
519
|
-
const { chatId } = mustGetMsg();
|
|
520
|
-
return this.banChatMember(chatId, memberId, params);
|
|
521
|
-
},
|
|
522
|
-
unbanChatMember: (memberId) => {
|
|
523
|
-
const { chatId } = mustGetMsg();
|
|
524
|
-
return this.unbanChatMember(chatId, memberId);
|
|
525
|
-
},
|
|
526
|
-
kickChatMember: (memberId) => {
|
|
527
|
-
const { chatId } = mustGetMsg();
|
|
528
|
-
return this.kickChatMember(chatId, memberId);
|
|
529
|
-
},
|
|
530
|
-
setChatMemberRights: (memberId, params) => {
|
|
531
|
-
const { chatId } = mustGetMsg();
|
|
532
|
-
return this.setChatMemberRights(chatId, memberId, params);
|
|
533
|
-
},
|
|
534
|
-
deleteChatMemberMessages: (userId) => {
|
|
535
|
-
const { chatId } = mustGetMsg();
|
|
536
|
-
return this.deleteChatMemberMessages(chatId, userId);
|
|
537
|
-
},
|
|
538
|
-
searchMessages: (query, params) => {
|
|
539
|
-
const { chatId } = mustGetMsg();
|
|
540
|
-
return this.searchMessages(chatId, query, params);
|
|
541
|
-
},
|
|
542
|
-
setBoostsRequiredToCircumventRestrictions: (boosts) => {
|
|
543
|
-
const { chatId } = mustGetMsg();
|
|
544
|
-
return this.setBoostsRequiredToCircumventRestrictions(chatId, boosts);
|
|
545
|
-
},
|
|
546
|
-
createInviteLink: (params) => {
|
|
547
|
-
const { chatId } = mustGetMsg();
|
|
548
|
-
return this.createInviteLink(chatId, params);
|
|
549
|
-
},
|
|
550
|
-
getCreatedInviteLinks: (params) => {
|
|
551
|
-
const { chatId } = mustGetMsg();
|
|
552
|
-
return this.getCreatedInviteLinks(chatId, params);
|
|
553
|
-
},
|
|
554
|
-
leave: () => {
|
|
555
|
-
const { chatId } = mustGetMsg();
|
|
556
|
-
return this.leaveChat(chatId);
|
|
557
|
-
},
|
|
558
|
-
block: () => {
|
|
559
|
-
return this.blockUser(mustGetUserId());
|
|
560
|
-
},
|
|
561
|
-
unblock: () => {
|
|
562
|
-
return this.unblockUser(mustGetUserId());
|
|
563
|
-
},
|
|
564
|
-
getChatMember: (userId) => {
|
|
565
|
-
const { chatId } = mustGetMsg();
|
|
566
|
-
return this.getChatMember(chatId, userId);
|
|
567
|
-
},
|
|
568
|
-
getChatMembers: (params) => {
|
|
569
|
-
const { chatId } = mustGetMsg();
|
|
570
|
-
return this.getChatMembers(chatId, params);
|
|
571
|
-
},
|
|
572
|
-
setChatStickerSet: (setName) => {
|
|
573
|
-
const { chatId } = mustGetMsg();
|
|
574
|
-
return this.setChatStickerSet(chatId, setName);
|
|
575
|
-
},
|
|
576
|
-
deleteChatStickerSet: () => {
|
|
577
|
-
const { chatId } = mustGetMsg();
|
|
578
|
-
return this.deleteChatStickerSet(chatId);
|
|
579
|
-
},
|
|
580
|
-
getBusinessConnection: () => {
|
|
581
|
-
const { businessConnectionId } = mustGetMsg();
|
|
582
|
-
if (!businessConnectionId) {
|
|
583
|
-
unreachable();
|
|
584
|
-
}
|
|
585
|
-
return this.getBusinessConnection(businessConnectionId);
|
|
586
|
-
},
|
|
587
|
-
answerPreCheckoutQuery: (ok, params) => {
|
|
588
|
-
if (!("preCheckoutQuery" in update)) {
|
|
589
|
-
unreachable();
|
|
590
|
-
}
|
|
591
|
-
return this.answerPreCheckoutQuery(update.preCheckoutQuery.id, ok, params);
|
|
592
|
-
},
|
|
593
|
-
approveJoinRequest: () => {
|
|
594
|
-
const { chatId, userId } = mustGetMsg();
|
|
595
|
-
if (!userId) {
|
|
596
|
-
unreachable();
|
|
597
|
-
}
|
|
598
|
-
return this.approveJoinRequest(chatId, userId);
|
|
599
|
-
},
|
|
600
|
-
declineJoinRequest: () => {
|
|
601
|
-
const { chatId, userId } = mustGetMsg();
|
|
602
|
-
if (!userId) {
|
|
603
|
-
unreachable();
|
|
604
|
-
}
|
|
605
|
-
return this.declineJoinRequest(chatId, userId);
|
|
606
|
-
},
|
|
607
|
-
};
|
|
608
|
-
return cleanObject(context);
|
|
609
|
-
});
|
|
610
|
-
_Client_lastPropagatedConnectionState.set(this, null);
|
|
611
|
-
_Client_stateChangeHandler.set(this, ((connected) => {
|
|
612
|
-
const connectionState = connected ? "ready" : "notConnected";
|
|
613
|
-
if (__classPrivateFieldGet(this, _Client_lastPropagatedConnectionState, "f") != connectionState) {
|
|
614
|
-
__classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateConnectionState).call(this, connectionState);
|
|
615
|
-
}
|
|
616
|
-
}).bind(this));
|
|
617
|
-
_Client_storageInited.set(this, false);
|
|
618
|
-
_Client_connectMutex.set(this, new Mutex());
|
|
619
|
-
_Client_lastPropagatedAuthorizationState.set(this, null);
|
|
620
|
-
_Client_lastUpdates.set(this, new Date());
|
|
621
|
-
_Client_updateGapRecoveryLoopAbortController.set(this, void 0);
|
|
622
|
-
_Client_clientDisconnectionLoopAbortController.set(this, void 0);
|
|
623
|
-
_Client_getMainClientMutex.set(this, new Mutex());
|
|
624
|
-
_Client_handleInvokeError.set(this, skipInvoke());
|
|
625
|
-
/**
|
|
626
|
-
* Invokes a function waiting and returning its reply if the second parameter is not `true`. Requires the client
|
|
627
|
-
* to be connected.
|
|
628
|
-
*
|
|
629
|
-
* @param function_ The function to invoke.
|
|
630
|
-
*/
|
|
631
|
-
Object.defineProperty(this, "invoke", {
|
|
632
|
-
enumerable: true,
|
|
633
|
-
configurable: true,
|
|
634
|
-
writable: true,
|
|
635
|
-
value: Object.assign(__classPrivateFieldGet(this, _Client_instances, "m", _Client_invoke), {
|
|
636
|
-
use: (handler) => {
|
|
637
|
-
const handle = __classPrivateFieldGet(this, _Client_handleInvokeError, "f");
|
|
638
|
-
__classPrivateFieldSet(this, _Client_handleInvokeError, async (ctx, next) => {
|
|
639
|
-
let result = null;
|
|
640
|
-
return await handle(ctx, async () => {
|
|
641
|
-
if (result != null)
|
|
642
|
-
return result;
|
|
643
|
-
result = await handler(ctx, next);
|
|
644
|
-
return result;
|
|
645
|
-
});
|
|
646
|
-
}, "f");
|
|
647
|
-
},
|
|
648
|
-
})
|
|
649
|
-
});
|
|
650
|
-
_Client_authStringImported.set(this, false);
|
|
651
|
-
_Client_lastGetMe.set(this, null);
|
|
652
|
-
_Client_previouslyConnected.set(this, false);
|
|
653
|
-
_Client_lastConnectionState.set(this, false);
|
|
654
|
-
__classPrivateFieldSet(this, _Client_apiId, params?.apiId ?? 0, "f");
|
|
655
|
-
__classPrivateFieldSet(this, _Client_apiHash, params?.apiHash ?? "", "f");
|
|
656
|
-
__classPrivateFieldSet(this, _Client_transportProvider, params?.transportProvider, "f");
|
|
657
|
-
__classPrivateFieldSet(this, _Client_initialDc, params?.initialDc ?? INITIAL_DC, "f");
|
|
658
|
-
__classPrivateFieldSet(this, _Client_storage_, params?.storage || new StorageMemory(), "f");
|
|
659
|
-
__classPrivateFieldSet(this, _Client_persistCache, params?.persistCache ?? false, "f");
|
|
660
|
-
if (!__classPrivateFieldGet(this, _Client_persistCache, "f")) {
|
|
661
|
-
__classPrivateFieldSet(this, _Client_messageStorage_, new StorageMemory(), "f");
|
|
157
|
+
this.#apiId = params?.apiId ?? 0;
|
|
158
|
+
this.#apiHash = params?.apiHash ?? "";
|
|
159
|
+
this.#transportProvider = params?.transportProvider;
|
|
160
|
+
this.#initialDc = params?.initialDc ?? INITIAL_DC;
|
|
161
|
+
this.#storage_ = params?.storage || new StorageMemory();
|
|
162
|
+
this.#persistCache = params?.persistCache ?? false;
|
|
163
|
+
if (!this.#persistCache) {
|
|
164
|
+
this.#messageStorage_ = new StorageMemory();
|
|
662
165
|
}
|
|
663
166
|
else {
|
|
664
|
-
|
|
167
|
+
this.#messageStorage_ = this.#storage_;
|
|
665
168
|
}
|
|
666
|
-
this.storage = new StorageOperations(
|
|
667
|
-
this.messageStorage = new StorageOperations(
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
169
|
+
this.storage = new StorageOperations(this.#storage_);
|
|
170
|
+
this.messageStorage = new StorageOperations(this.#messageStorage_);
|
|
171
|
+
this.#parseMode = params?.parseMode ?? null;
|
|
172
|
+
this.#disableUpdates = params?.disableUpdates ?? false;
|
|
173
|
+
this.#authString = params?.authString;
|
|
671
174
|
this.appVersion = params?.appVersion ?? APP_VERSION;
|
|
672
175
|
this.deviceModel = params?.deviceModel ?? DEVICE_MODEL;
|
|
673
176
|
this.language = params?.language ?? LANG_CODE;
|
|
674
177
|
this.platform = params?.platform ?? LANG_PACK;
|
|
675
178
|
this.systemLangCode = params?.systemLangCode ?? SYSTEM_LANG_CODE;
|
|
676
179
|
this.systemVersion = params?.systemVersion ?? SYSTEM_VERSION;
|
|
677
|
-
|
|
678
|
-
|
|
180
|
+
this.#publicKeys = params?.publicKeys;
|
|
181
|
+
this.#outgoingMessages = params?.outgoingMessages ?? null;
|
|
679
182
|
if (params?.prefixes) {
|
|
680
183
|
this.prefixes = params?.prefixes;
|
|
681
184
|
}
|
|
682
|
-
|
|
683
|
-
const L =
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
185
|
+
this.#guaranteeUpdateDelivery = params?.guaranteeUpdateDelivery ?? false;
|
|
186
|
+
const L = this.#L = getLogger("Client").client(id++);
|
|
187
|
+
this.#LsignIn = L.branch("signIn");
|
|
188
|
+
this.#LupdateGapRecoveryLoop = L.branch("updateGapRecoveryLoop");
|
|
189
|
+
this.#LhandleMigrationError = L.branch("[handleMigrationError]");
|
|
190
|
+
this.#Lmin = L.branch("min");
|
|
688
191
|
const c = {
|
|
689
192
|
id,
|
|
690
|
-
getUploadPoolSize:
|
|
193
|
+
getUploadPoolSize: this.#getUploadPoolSize.bind(this),
|
|
691
194
|
invoke: async (function_, params) => {
|
|
692
195
|
if (params?.businessConnectionId) {
|
|
693
196
|
if (Mtproto.is("ping", function_)) {
|
|
@@ -701,48 +204,48 @@ export class Client extends Composer {
|
|
|
701
204
|
},
|
|
702
205
|
storage: this.storage,
|
|
703
206
|
messageStorage: this.messageStorage,
|
|
704
|
-
guaranteeUpdateDelivery:
|
|
705
|
-
setConnectionState:
|
|
706
|
-
resetConnectionState: () =>
|
|
707
|
-
getSelfId:
|
|
708
|
-
getIsPremium:
|
|
207
|
+
guaranteeUpdateDelivery: this.#guaranteeUpdateDelivery,
|
|
208
|
+
setConnectionState: this.#propagateConnectionState.bind(this),
|
|
209
|
+
resetConnectionState: () => this.#stateChangeHandler(this.connected),
|
|
210
|
+
getSelfId: this.#getSelfId.bind(this),
|
|
211
|
+
getIsPremium: this.#getIsPremium.bind(this),
|
|
709
212
|
getInputPeer: this.getInputPeer.bind(this),
|
|
710
213
|
getInputChannel: this.getInputChannel.bind(this),
|
|
711
214
|
getInputUser: this.getInputUser.bind(this),
|
|
712
|
-
getInputPeerChatId:
|
|
215
|
+
getInputPeerChatId: this.#getInputPeerChatId.bind(this),
|
|
713
216
|
getEntity: this[getEntity].bind(this),
|
|
714
|
-
handleUpdate:
|
|
715
|
-
parseMode:
|
|
716
|
-
outgoingMessages:
|
|
217
|
+
handleUpdate: this.#queueHandleCtxUpdate.bind(this),
|
|
218
|
+
parseMode: this.#parseMode,
|
|
219
|
+
outgoingMessages: this.#outgoingMessages,
|
|
717
220
|
dropPendingUpdates: params?.dropPendingUpdates,
|
|
718
221
|
disconnected: () => this.disconnected,
|
|
719
222
|
langPack: this.platform,
|
|
720
223
|
langCode: this.language,
|
|
721
224
|
};
|
|
722
225
|
// 2_
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
const fileManager =
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
226
|
+
this.#accountManager = new AccountManager(c);
|
|
227
|
+
this.#botInfoManager = new BotInfoManager(c);
|
|
228
|
+
this.#businessConnectionManager = new BusinessConnectionManager(c);
|
|
229
|
+
const fileManager = this.#fileManager = new FileManager(c);
|
|
230
|
+
this.#networkStatisticsManager = new NetworkStatisticsManager(c);
|
|
231
|
+
this.#paymentManager = new PaymentManager(c);
|
|
232
|
+
this.#reactionManager = new ReactionManager(c);
|
|
233
|
+
this.#translationsManager = new TranslationsManager(c);
|
|
234
|
+
this.#updateManager = new UpdateManager(c);
|
|
732
235
|
// 3_
|
|
733
|
-
const messageManager =
|
|
734
|
-
|
|
236
|
+
const messageManager = this.#messageManager = new MessageManager({ ...c, fileManager });
|
|
237
|
+
this.#videoChatManager = new VideoChatManager({ ...c, fileManager });
|
|
735
238
|
// 4_
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
239
|
+
this.#callbackQueryManager = new CallbackQueryManager({ ...c, messageManager });
|
|
240
|
+
this.#chatListManager = new ChatListManager({ ...c, fileManager, messageManager });
|
|
241
|
+
this.#chatManager = new ChatManager({ ...c, fileManager, messageManager });
|
|
242
|
+
this.#forumManager = new ForumManager({ ...c, messageManager });
|
|
243
|
+
this.#giftManager = new GiftManager({ ...c, messageManager });
|
|
244
|
+
this.#inlineQueryManager = new InlineQueryManager({ ...c, messageManager });
|
|
245
|
+
this.#linkPreviewManager = new LinkPreviewManager({ ...c, messageManager });
|
|
246
|
+
this.#pollManager = new PollManager({ ...c, messageManager });
|
|
247
|
+
this.#storyManager = new StoryManager({ ...c, fileManager, messageManager });
|
|
248
|
+
this.#updateManager.setUpdateHandler(this.#handleUpdate.bind(this));
|
|
746
249
|
if (params?.defaultHandlers ?? true) {
|
|
747
250
|
this.invoke.use(async ({ error }, next) => {
|
|
748
251
|
if (error instanceof FloodWait && error.seconds <= 10) {
|
|
@@ -756,123 +259,622 @@ export class Client extends Composer {
|
|
|
756
259
|
});
|
|
757
260
|
}
|
|
758
261
|
}
|
|
262
|
+
#setMainClient(client) {
|
|
263
|
+
this.#disconnectAllClients();
|
|
264
|
+
this.#clients = [client];
|
|
265
|
+
client.handlers.onUpdate = (updates) => {
|
|
266
|
+
this.#updateManager.processUpdates(updates, true, null);
|
|
267
|
+
this.#lastUpdates = new Date();
|
|
268
|
+
};
|
|
269
|
+
client.handlers.onDeserializationError = async () => {
|
|
270
|
+
await this.#updateManager.recoverUpdateGap("deserialization error");
|
|
271
|
+
};
|
|
272
|
+
client.handlers.onNewServerSalt = async (serverSalt) => {
|
|
273
|
+
await this.storage.setServerSalt(serverSalt);
|
|
274
|
+
};
|
|
275
|
+
client.onConnectionStateChange = this.#onConnectionStateChange.bind(this);
|
|
276
|
+
}
|
|
277
|
+
#newClient(dc, main, cdn) {
|
|
278
|
+
const client = new ClientEncrypted(dc, this.#apiId, {
|
|
279
|
+
appVersion: this.appVersion,
|
|
280
|
+
deviceModel: this.deviceModel,
|
|
281
|
+
langCode: this.language,
|
|
282
|
+
langPack: this.platform,
|
|
283
|
+
systemLangCode: this.systemLangCode,
|
|
284
|
+
systemVersion: this.systemVersion,
|
|
285
|
+
transportProvider: this.#transportProvider,
|
|
286
|
+
cdn,
|
|
287
|
+
disableUpdates: !main || cdn,
|
|
288
|
+
publicKeys: this.#publicKeys,
|
|
289
|
+
});
|
|
290
|
+
client.connectionCallback = this.#networkStatisticsManager.getTransportReadWriteCallback(cdn);
|
|
291
|
+
return client;
|
|
292
|
+
}
|
|
293
|
+
#disconnectAllClients() {
|
|
294
|
+
for (const client of this.#clients) {
|
|
295
|
+
client.disconnect();
|
|
296
|
+
}
|
|
297
|
+
for (const pool of Object.values(this.#downloadPools)) {
|
|
298
|
+
pool.disconnect();
|
|
299
|
+
}
|
|
300
|
+
for (const pool of Object.values(this.#uploadPools)) {
|
|
301
|
+
pool.disconnect();
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
get #client() {
|
|
305
|
+
return this.#clients[0];
|
|
306
|
+
}
|
|
759
307
|
// direct ClientEncrypted property proxies
|
|
760
308
|
get connected() {
|
|
761
|
-
return
|
|
309
|
+
return this.#client?.connected ?? false;
|
|
762
310
|
}
|
|
763
311
|
get disconnected() {
|
|
764
|
-
return
|
|
312
|
+
return this.#client?.disconnected ?? true;
|
|
313
|
+
}
|
|
314
|
+
#constructContext = async (update) => {
|
|
315
|
+
const msg = "message" in update ? update.message : "editedMessage" in update ? update.editedMessage : "scheduledMessage" in update ? update.scheduledMessage : "callbackQuery" in update ? update.callbackQuery.message : undefined;
|
|
316
|
+
const reactions = "messageInteractions" in update ? update.messageInteractions : undefined;
|
|
317
|
+
const mustGetMsg = () => {
|
|
318
|
+
if (msg !== undefined) {
|
|
319
|
+
return { chatId: msg.chat.id, messageId: msg.id, businessConnectionId: msg.businessConnectionId, senderId: msg.from?.id, userId: msg.from?.id };
|
|
320
|
+
}
|
|
321
|
+
else if (reactions !== undefined) {
|
|
322
|
+
return { chatId: reactions.chatId, messageId: reactions.messageId };
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
unreachable();
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
const mustGetUserId = () => {
|
|
329
|
+
if (msg?.from) {
|
|
330
|
+
return msg.from.id;
|
|
331
|
+
}
|
|
332
|
+
else if ("callbackQuery" in update) {
|
|
333
|
+
return update.callbackQuery.from.id;
|
|
334
|
+
}
|
|
335
|
+
else if ("chosenInlineResult" in update) {
|
|
336
|
+
return update.chosenInlineResult.from.id;
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
unreachable();
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
const mustGetInlineMsgId = () => {
|
|
343
|
+
if ("chosenInlineResult" in update) {
|
|
344
|
+
if (update.chosenInlineResult.inlineMessageId) {
|
|
345
|
+
return update.chosenInlineResult.inlineMessageId;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
else if ("callbackQuery" in update) {
|
|
349
|
+
if (update.callbackQuery.inlineMessageId) {
|
|
350
|
+
return update.callbackQuery.inlineMessageId;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
unreachable();
|
|
354
|
+
};
|
|
355
|
+
const chat_ = "messageReactions" in update ? update.messageReactions.chat : "messageReactionCount" in update ? update.messageReactionCount.chat : "chatMember" in update ? update.chatMember.chat : "myChatMember" in update ? update.myChatMember.chat : "joinRequest" in update ? update.joinRequest.chat : "story" in update ? update.story.chat : undefined;
|
|
356
|
+
const chat = chat_ ?? msg?.chat;
|
|
357
|
+
const from = "callbackQuery" in update ? update.callbackQuery.from : "inlineQuery" in update ? update.inlineQuery.from : "chatMember" in update ? update.chatMember.from : "myChatMember" in update ? update.myChatMember.from : "messageReactions" in update ? update.messageReactions.user : "preCheckoutQuery" in update ? update.preCheckoutQuery.from : "joinRequest" in update ? update.joinRequest.from : "businessConnection" in update ? update.businessConnection.user : "pollAnswer" in update ? update.pollAnswer.from : msg?.from ? msg.from : undefined;
|
|
358
|
+
const getReplyTo = (quote, chatId, messageId) => {
|
|
359
|
+
if ("story" in update) {
|
|
360
|
+
return { chatId: update.story.chat.id, storyId: update.story.id };
|
|
361
|
+
}
|
|
362
|
+
const isPrivate = chatId > 0;
|
|
363
|
+
const shouldQuote = quote === undefined ? !isPrivate : quote;
|
|
364
|
+
return shouldQuote ? { messageId } : undefined;
|
|
365
|
+
};
|
|
366
|
+
const me = "connectionState" in update ? this.#lastGetMe : ("authorizationState" in update && !update.authorizationState.authorized) ? this.#lastGetMe : await this.#getMe();
|
|
367
|
+
const context = {
|
|
368
|
+
...update,
|
|
369
|
+
client: this,
|
|
370
|
+
me: (me == null ? undefined : me),
|
|
371
|
+
msg: msg,
|
|
372
|
+
chat: chat,
|
|
373
|
+
from: from,
|
|
374
|
+
get toJSON() {
|
|
375
|
+
return () => update;
|
|
376
|
+
},
|
|
377
|
+
reply: (text, params) => {
|
|
378
|
+
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
379
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
380
|
+
return this.sendMessage(chatId, text, { ...params, replyTo, businessConnectionId });
|
|
381
|
+
},
|
|
382
|
+
replyPoll: (question, options, params) => {
|
|
383
|
+
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
384
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
385
|
+
return this.sendPoll(chatId, question, options, { ...params, replyTo, businessConnectionId });
|
|
386
|
+
},
|
|
387
|
+
replyPhoto: (photo, params) => {
|
|
388
|
+
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
389
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
390
|
+
return this.sendPhoto(chatId, photo, { ...params, replyTo, businessConnectionId });
|
|
391
|
+
},
|
|
392
|
+
replyMediaGroup: (media, params) => {
|
|
393
|
+
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
394
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
395
|
+
return this.sendMediaGroup(chatId, media, { ...params, replyTo, businessConnectionId });
|
|
396
|
+
},
|
|
397
|
+
replyInvoice: (title, description, payload, currency, prices, params) => {
|
|
398
|
+
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
399
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
400
|
+
return this.sendInvoice(chatId, title, description, payload, currency, prices, { ...params, replyTo, businessConnectionId });
|
|
401
|
+
},
|
|
402
|
+
replyDocument: (document, params) => {
|
|
403
|
+
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
404
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
405
|
+
return this.sendDocument(chatId, document, { ...params, replyTo, businessConnectionId });
|
|
406
|
+
},
|
|
407
|
+
replySticker: (sticker, params) => {
|
|
408
|
+
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
409
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
410
|
+
return this.sendSticker(chatId, sticker, { ...params, replyTo, businessConnectionId });
|
|
411
|
+
},
|
|
412
|
+
replyContact: (firstName, number, params) => {
|
|
413
|
+
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
414
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
415
|
+
return this.sendContact(chatId, firstName, number, { ...params, replyTo, businessConnectionId });
|
|
416
|
+
},
|
|
417
|
+
replyLocation: (latitude, longitude, params) => {
|
|
418
|
+
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
419
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
420
|
+
return this.sendLocation(chatId, latitude, longitude, { ...params, replyTo, businessConnectionId });
|
|
421
|
+
},
|
|
422
|
+
replyDice: (params) => {
|
|
423
|
+
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
424
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
425
|
+
return this.sendDice(chatId, { ...params, replyTo, businessConnectionId });
|
|
426
|
+
},
|
|
427
|
+
replyVenue: (latitude, longitude, title, address, params) => {
|
|
428
|
+
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
429
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
430
|
+
return this.sendVenue(chatId, latitude, longitude, title, address, { ...params, replyTo, businessConnectionId });
|
|
431
|
+
},
|
|
432
|
+
replyVideo: (video, params) => {
|
|
433
|
+
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
434
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
435
|
+
return this.sendVideo(chatId, video, { ...params, replyTo, businessConnectionId });
|
|
436
|
+
},
|
|
437
|
+
replyAnimation: (document, params) => {
|
|
438
|
+
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
439
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
440
|
+
return this.sendAnimation(chatId, document, { ...params, replyTo, businessConnectionId });
|
|
441
|
+
},
|
|
442
|
+
replyVoice: (document, params) => {
|
|
443
|
+
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
444
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
445
|
+
return this.sendVoice(chatId, document, { ...params, replyTo, businessConnectionId });
|
|
446
|
+
},
|
|
447
|
+
replyAudio: (document, params) => {
|
|
448
|
+
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
449
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
450
|
+
return this.sendAudio(chatId, document, { ...params, replyTo, businessConnectionId });
|
|
451
|
+
},
|
|
452
|
+
replyVideoNote: (videoNote, params) => {
|
|
453
|
+
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
454
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
455
|
+
return this.sendVideoNote(chatId, videoNote, { ...params, replyTo, businessConnectionId });
|
|
456
|
+
},
|
|
457
|
+
delete: () => {
|
|
458
|
+
const { chatId, messageId } = mustGetMsg();
|
|
459
|
+
return this.deleteMessage(chatId, messageId);
|
|
460
|
+
},
|
|
461
|
+
forward: (to, params) => {
|
|
462
|
+
const { chatId, messageId } = mustGetMsg();
|
|
463
|
+
return this.forwardMessage(chatId, to, messageId, params);
|
|
464
|
+
},
|
|
465
|
+
pin: (params) => {
|
|
466
|
+
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
467
|
+
return this.pinMessage(chatId, messageId, { ...params, businessConnectionId });
|
|
468
|
+
},
|
|
469
|
+
unpin: () => {
|
|
470
|
+
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
471
|
+
return this.unpinMessage(chatId, messageId, { businessConnectionId });
|
|
472
|
+
},
|
|
473
|
+
banSender: (params) => {
|
|
474
|
+
const { chatId, senderId } = mustGetMsg();
|
|
475
|
+
if (!senderId) {
|
|
476
|
+
unreachable();
|
|
477
|
+
}
|
|
478
|
+
return this.banChatMember(chatId, senderId, params);
|
|
479
|
+
},
|
|
480
|
+
kickSender: () => {
|
|
481
|
+
const { chatId, senderId } = mustGetMsg();
|
|
482
|
+
if (!senderId) {
|
|
483
|
+
unreachable();
|
|
484
|
+
}
|
|
485
|
+
return this.kickChatMember(chatId, senderId);
|
|
486
|
+
},
|
|
487
|
+
setSenderRights: (params) => {
|
|
488
|
+
const { chatId, senderId } = mustGetMsg();
|
|
489
|
+
if (!senderId) {
|
|
490
|
+
unreachable();
|
|
491
|
+
}
|
|
492
|
+
return this.setChatMemberRights(chatId, senderId, params);
|
|
493
|
+
},
|
|
494
|
+
getChatAdministrators: () => {
|
|
495
|
+
const { chatId } = mustGetMsg();
|
|
496
|
+
return this.getChatAdministrators(chatId);
|
|
497
|
+
},
|
|
498
|
+
react: (reactions, params) => {
|
|
499
|
+
const { chatId, messageId } = mustGetMsg();
|
|
500
|
+
return this.setReactions(chatId, messageId, reactions, params);
|
|
501
|
+
},
|
|
502
|
+
answerCallbackQuery: (params) => {
|
|
503
|
+
if (!("callbackQuery" in update)) {
|
|
504
|
+
unreachable();
|
|
505
|
+
}
|
|
506
|
+
return this.answerCallbackQuery(update.callbackQuery.id, params);
|
|
507
|
+
},
|
|
508
|
+
answerInlineQuery: (results, params) => {
|
|
509
|
+
if (!("inlineQuery" in update)) {
|
|
510
|
+
unreachable();
|
|
511
|
+
}
|
|
512
|
+
return this.answerInlineQuery(update.inlineQuery.id, results, params);
|
|
513
|
+
},
|
|
514
|
+
sendChatAction: (chatAction, params) => {
|
|
515
|
+
const { chatId } = mustGetMsg();
|
|
516
|
+
return this.sendChatAction(chatId, chatAction, params);
|
|
517
|
+
},
|
|
518
|
+
editInlineMessageText: (text, params) => {
|
|
519
|
+
const inlineMessageId = mustGetInlineMsgId();
|
|
520
|
+
return this.editInlineMessageText(inlineMessageId, text, params);
|
|
521
|
+
},
|
|
522
|
+
editInlineMessageMedia: (media, params) => {
|
|
523
|
+
const inlineMessageId = mustGetInlineMsgId();
|
|
524
|
+
return this.editInlineMessageMedia(inlineMessageId, media, params);
|
|
525
|
+
},
|
|
526
|
+
editInlineMessageCaption: (params) => {
|
|
527
|
+
const inlineMessageId = mustGetInlineMsgId();
|
|
528
|
+
return this.editInlineMessageCaption(inlineMessageId, params);
|
|
529
|
+
},
|
|
530
|
+
editInlineMessageLiveLocation: (latitude, longitude, params) => {
|
|
531
|
+
const inlineMessageId = mustGetInlineMsgId();
|
|
532
|
+
return this.editInlineMessageLiveLocation(inlineMessageId, latitude, longitude, params);
|
|
533
|
+
},
|
|
534
|
+
editInlineMessageReplyMarkup: (params) => {
|
|
535
|
+
const inlineMessageId = mustGetInlineMsgId();
|
|
536
|
+
return this.editInlineMessageReplyMarkup(inlineMessageId, params);
|
|
537
|
+
},
|
|
538
|
+
editMessageText: (messageId, text, params) => {
|
|
539
|
+
const { chatId } = mustGetMsg();
|
|
540
|
+
return this.editMessageText(chatId, messageId, text, params);
|
|
541
|
+
},
|
|
542
|
+
editMessageCaption: (messageId, params) => {
|
|
543
|
+
const { chatId } = mustGetMsg();
|
|
544
|
+
return this.editMessageCaption(chatId, messageId, params);
|
|
545
|
+
},
|
|
546
|
+
editMessageMedia: (messageId, media, params) => {
|
|
547
|
+
const { chatId } = mustGetMsg();
|
|
548
|
+
return this.editMessageMedia(chatId, messageId, media, params);
|
|
549
|
+
},
|
|
550
|
+
editMessageLiveLocation: (messageId, latitude, longitude, params) => {
|
|
551
|
+
const { chatId } = mustGetMsg();
|
|
552
|
+
return this.editMessageLiveLocation(chatId, messageId, latitude, longitude, params);
|
|
553
|
+
},
|
|
554
|
+
editMessageReplyMarkup: (messageId, params) => {
|
|
555
|
+
const { chatId } = mustGetMsg();
|
|
556
|
+
return this.editMessageReplyMarkup(chatId, messageId, params);
|
|
557
|
+
},
|
|
558
|
+
getMessage: (messageId) => {
|
|
559
|
+
const { chatId } = mustGetMsg();
|
|
560
|
+
return this.getMessage(chatId, messageId);
|
|
561
|
+
},
|
|
562
|
+
getMessages: (messageIds) => {
|
|
563
|
+
const { chatId } = mustGetMsg();
|
|
564
|
+
return this.getMessages(chatId, messageIds);
|
|
565
|
+
},
|
|
566
|
+
forwardMessage: (to, messageId, params) => {
|
|
567
|
+
const { chatId } = mustGetMsg();
|
|
568
|
+
return this.forwardMessage(chatId, to, messageId, params);
|
|
569
|
+
},
|
|
570
|
+
forwardMessages: (to, messageIds, params) => {
|
|
571
|
+
const { chatId } = mustGetMsg();
|
|
572
|
+
return this.forwardMessages(chatId, to, messageIds, params);
|
|
573
|
+
},
|
|
574
|
+
deleteMessage: (messageId, params) => {
|
|
575
|
+
const { chatId } = mustGetMsg();
|
|
576
|
+
return this.deleteMessage(chatId, messageId, params);
|
|
577
|
+
},
|
|
578
|
+
deleteMessages: (messageIds, params) => {
|
|
579
|
+
const { chatId } = mustGetMsg();
|
|
580
|
+
return this.deleteMessages(chatId, messageIds, params);
|
|
581
|
+
},
|
|
582
|
+
pinMessage: (messageId, params) => {
|
|
583
|
+
const { chatId } = mustGetMsg();
|
|
584
|
+
return this.pinMessage(chatId, messageId, params);
|
|
585
|
+
},
|
|
586
|
+
unpinMessage: (messageId) => {
|
|
587
|
+
const { chatId } = mustGetMsg();
|
|
588
|
+
return this.unpinMessage(chatId, messageId);
|
|
589
|
+
},
|
|
590
|
+
unpinMessages: () => {
|
|
591
|
+
const { chatId } = mustGetMsg();
|
|
592
|
+
return this.unpinMessages(chatId);
|
|
593
|
+
},
|
|
594
|
+
setAvailableReactions: (availableReactions) => {
|
|
595
|
+
const { chatId } = mustGetMsg();
|
|
596
|
+
return this.setAvailableReactions(chatId, availableReactions);
|
|
597
|
+
},
|
|
598
|
+
addReaction: (messageId, reaction, params) => {
|
|
599
|
+
const { chatId } = mustGetMsg();
|
|
600
|
+
return this.addReaction(chatId, messageId, reaction, params);
|
|
601
|
+
},
|
|
602
|
+
removeReaction: (messageId, reaction) => {
|
|
603
|
+
const { chatId } = mustGetMsg();
|
|
604
|
+
return this.removeReaction(chatId, messageId, reaction);
|
|
605
|
+
},
|
|
606
|
+
setReactions: (messageId, reactions, params) => {
|
|
607
|
+
const { chatId } = mustGetMsg();
|
|
608
|
+
return this.setReactions(chatId, messageId, reactions, params);
|
|
609
|
+
},
|
|
610
|
+
read: () => {
|
|
611
|
+
const { chatId, messageId } = mustGetMsg();
|
|
612
|
+
return this.readMessages(chatId, messageId);
|
|
613
|
+
},
|
|
614
|
+
setChatPhoto: (photo, params) => {
|
|
615
|
+
const { chatId } = mustGetMsg();
|
|
616
|
+
return this.setChatPhoto(chatId, photo, params);
|
|
617
|
+
},
|
|
618
|
+
deleteChatPhoto: () => {
|
|
619
|
+
const { chatId } = mustGetMsg();
|
|
620
|
+
return this.deleteChatPhoto(chatId);
|
|
621
|
+
},
|
|
622
|
+
banChatMember: (memberId, params) => {
|
|
623
|
+
const { chatId } = mustGetMsg();
|
|
624
|
+
return this.banChatMember(chatId, memberId, params);
|
|
625
|
+
},
|
|
626
|
+
unbanChatMember: (memberId) => {
|
|
627
|
+
const { chatId } = mustGetMsg();
|
|
628
|
+
return this.unbanChatMember(chatId, memberId);
|
|
629
|
+
},
|
|
630
|
+
kickChatMember: (memberId) => {
|
|
631
|
+
const { chatId } = mustGetMsg();
|
|
632
|
+
return this.kickChatMember(chatId, memberId);
|
|
633
|
+
},
|
|
634
|
+
setChatMemberRights: (memberId, params) => {
|
|
635
|
+
const { chatId } = mustGetMsg();
|
|
636
|
+
return this.setChatMemberRights(chatId, memberId, params);
|
|
637
|
+
},
|
|
638
|
+
deleteChatMemberMessages: (userId) => {
|
|
639
|
+
const { chatId } = mustGetMsg();
|
|
640
|
+
return this.deleteChatMemberMessages(chatId, userId);
|
|
641
|
+
},
|
|
642
|
+
searchMessages: (query, params) => {
|
|
643
|
+
const { chatId } = mustGetMsg();
|
|
644
|
+
return this.searchMessages(chatId, query, params);
|
|
645
|
+
},
|
|
646
|
+
setBoostsRequiredToCircumventRestrictions: (boosts) => {
|
|
647
|
+
const { chatId } = mustGetMsg();
|
|
648
|
+
return this.setBoostsRequiredToCircumventRestrictions(chatId, boosts);
|
|
649
|
+
},
|
|
650
|
+
createInviteLink: (params) => {
|
|
651
|
+
const { chatId } = mustGetMsg();
|
|
652
|
+
return this.createInviteLink(chatId, params);
|
|
653
|
+
},
|
|
654
|
+
getCreatedInviteLinks: (params) => {
|
|
655
|
+
const { chatId } = mustGetMsg();
|
|
656
|
+
return this.getCreatedInviteLinks(chatId, params);
|
|
657
|
+
},
|
|
658
|
+
leave: () => {
|
|
659
|
+
const { chatId } = mustGetMsg();
|
|
660
|
+
return this.leaveChat(chatId);
|
|
661
|
+
},
|
|
662
|
+
block: () => {
|
|
663
|
+
return this.blockUser(mustGetUserId());
|
|
664
|
+
},
|
|
665
|
+
unblock: () => {
|
|
666
|
+
return this.unblockUser(mustGetUserId());
|
|
667
|
+
},
|
|
668
|
+
getChatMember: (userId) => {
|
|
669
|
+
const { chatId } = mustGetMsg();
|
|
670
|
+
return this.getChatMember(chatId, userId);
|
|
671
|
+
},
|
|
672
|
+
getChatMembers: (params) => {
|
|
673
|
+
const { chatId } = mustGetMsg();
|
|
674
|
+
return this.getChatMembers(chatId, params);
|
|
675
|
+
},
|
|
676
|
+
setChatStickerSet: (setName) => {
|
|
677
|
+
const { chatId } = mustGetMsg();
|
|
678
|
+
return this.setChatStickerSet(chatId, setName);
|
|
679
|
+
},
|
|
680
|
+
deleteChatStickerSet: () => {
|
|
681
|
+
const { chatId } = mustGetMsg();
|
|
682
|
+
return this.deleteChatStickerSet(chatId);
|
|
683
|
+
},
|
|
684
|
+
getBusinessConnection: () => {
|
|
685
|
+
const { businessConnectionId } = mustGetMsg();
|
|
686
|
+
if (!businessConnectionId) {
|
|
687
|
+
unreachable();
|
|
688
|
+
}
|
|
689
|
+
return this.getBusinessConnection(businessConnectionId);
|
|
690
|
+
},
|
|
691
|
+
answerPreCheckoutQuery: (ok, params) => {
|
|
692
|
+
if (!("preCheckoutQuery" in update)) {
|
|
693
|
+
unreachable();
|
|
694
|
+
}
|
|
695
|
+
return this.answerPreCheckoutQuery(update.preCheckoutQuery.id, ok, params);
|
|
696
|
+
},
|
|
697
|
+
approveJoinRequest: () => {
|
|
698
|
+
const { chatId, userId } = mustGetMsg();
|
|
699
|
+
if (!userId) {
|
|
700
|
+
unreachable();
|
|
701
|
+
}
|
|
702
|
+
return this.approveJoinRequest(chatId, userId);
|
|
703
|
+
},
|
|
704
|
+
declineJoinRequest: () => {
|
|
705
|
+
const { chatId, userId } = mustGetMsg();
|
|
706
|
+
if (!userId) {
|
|
707
|
+
unreachable();
|
|
708
|
+
}
|
|
709
|
+
return this.declineJoinRequest(chatId, userId);
|
|
710
|
+
},
|
|
711
|
+
};
|
|
712
|
+
return cleanObject(context);
|
|
713
|
+
};
|
|
714
|
+
#propagateConnectionState(connectionState) {
|
|
715
|
+
this.#queueHandleCtxUpdate({ connectionState });
|
|
716
|
+
this.#lastPropagatedConnectionState = connectionState;
|
|
717
|
+
}
|
|
718
|
+
#lastPropagatedConnectionState = null;
|
|
719
|
+
#stateChangeHandler = ((connected) => {
|
|
720
|
+
const connectionState = connected ? "ready" : "notConnected";
|
|
721
|
+
if (this.#lastPropagatedConnectionState != connectionState) {
|
|
722
|
+
this.#propagateConnectionState(connectionState);
|
|
723
|
+
}
|
|
724
|
+
}).bind(this);
|
|
725
|
+
#storageInited = false;
|
|
726
|
+
async #initStorage() {
|
|
727
|
+
if (!this.#storageInited) {
|
|
728
|
+
await this.storage.initialize();
|
|
729
|
+
if (!this.#guaranteeUpdateDelivery) {
|
|
730
|
+
await this.storage.deleteUpdates();
|
|
731
|
+
}
|
|
732
|
+
this.#storageInited = true;
|
|
733
|
+
}
|
|
765
734
|
}
|
|
735
|
+
#connectMutex = new Mutex();
|
|
766
736
|
/**
|
|
767
737
|
* Loads the session if `setDc` was not called, initializes and connnects
|
|
768
738
|
* a `ClientPlain` to generate auth key if there was none, and connects the client.
|
|
769
739
|
* Before establishing the connection, the session is saved.
|
|
770
740
|
*/
|
|
771
741
|
async connect() {
|
|
772
|
-
const unlock = await
|
|
742
|
+
const unlock = await this.#connectMutex.lock();
|
|
773
743
|
try {
|
|
774
744
|
if (this.connected) {
|
|
775
745
|
return;
|
|
776
746
|
}
|
|
777
|
-
await
|
|
778
|
-
if (
|
|
779
|
-
await this.importAuthString(
|
|
747
|
+
await this.#initStorage();
|
|
748
|
+
if (this.#authString && !this.#authStringImported) {
|
|
749
|
+
await this.importAuthString(this.#authString);
|
|
780
750
|
}
|
|
781
751
|
const [authKey, dc] = await Promise.all([this.storage.getAuthKey(), this.storage.getDc()]);
|
|
782
752
|
if (authKey != null && dc != null) {
|
|
783
|
-
if (!
|
|
784
|
-
|
|
785
|
-
|
|
753
|
+
if (!this.#client || this.#client.dc != dc) {
|
|
754
|
+
this.#client?.disconnect();
|
|
755
|
+
this.#setMainClient(this.#newClient(dc, true, false));
|
|
786
756
|
}
|
|
787
|
-
await
|
|
788
|
-
if (
|
|
789
|
-
|
|
757
|
+
await this.#client.setAuthKey(authKey);
|
|
758
|
+
if (this.#client.serverSalt == 0n) {
|
|
759
|
+
this.#client.serverSalt = await this.storage.getServerSalt() ?? 0n;
|
|
790
760
|
}
|
|
791
761
|
}
|
|
792
762
|
else {
|
|
793
|
-
const dc = await this.storage.getDc() ??
|
|
794
|
-
if (!
|
|
795
|
-
|
|
796
|
-
|
|
763
|
+
const dc = await this.storage.getDc() ?? this.#initialDc;
|
|
764
|
+
if (!this.#client || this.#client.dc != dc) {
|
|
765
|
+
this.#client?.disconnect();
|
|
766
|
+
this.#setMainClient(this.#newClient(dc, true, false));
|
|
797
767
|
}
|
|
798
768
|
}
|
|
799
|
-
await
|
|
800
|
-
await Promise.all([this.storage.setAuthKey(
|
|
801
|
-
|
|
802
|
-
|
|
769
|
+
await this.#client.connect();
|
|
770
|
+
await Promise.all([this.storage.setAuthKey(this.#client.authKey), this.storage.setDc(this.#client.dc), this.storage.setServerSalt(this.#client.serverSalt)]);
|
|
771
|
+
this.#startUpdateGapRecoveryLoop();
|
|
772
|
+
this.#startClientDisconnectionLoop();
|
|
803
773
|
}
|
|
804
774
|
finally {
|
|
805
775
|
unlock();
|
|
806
776
|
}
|
|
807
777
|
}
|
|
808
|
-
async [(
|
|
809
|
-
__classPrivateFieldGet(this, _Client_instances, "m", _Client_disconnectAllClients).call(this);
|
|
810
|
-
__classPrivateFieldSet(this, _Client_clients, [client], "f");
|
|
811
|
-
client.handlers.onUpdate = (updates) => {
|
|
812
|
-
__classPrivateFieldGet(this, _Client_updateManager, "f").processUpdates(updates, true, null);
|
|
813
|
-
__classPrivateFieldSet(this, _Client_lastUpdates, new Date(), "f");
|
|
814
|
-
};
|
|
815
|
-
client.handlers.onDeserializationError = async () => {
|
|
816
|
-
await __classPrivateFieldGet(this, _Client_updateManager, "f").recoverUpdateGap("deserialization error");
|
|
817
|
-
};
|
|
818
|
-
client.handlers.onNewServerSalt = async (serverSalt) => {
|
|
819
|
-
await this.storage.setServerSalt(serverSalt);
|
|
820
|
-
};
|
|
821
|
-
client.onConnectionStateChange = __classPrivateFieldGet(this, _Client_instances, "m", _Client_onConnectionStateChange).bind(this);
|
|
822
|
-
}, _Client_newClient = function _Client_newClient(dc, main, cdn) {
|
|
823
|
-
const client = new ClientEncrypted(dc, __classPrivateFieldGet(this, _Client_apiId, "f"), {
|
|
824
|
-
appVersion: this.appVersion,
|
|
825
|
-
deviceModel: this.deviceModel,
|
|
826
|
-
langCode: this.language,
|
|
827
|
-
langPack: this.platform,
|
|
828
|
-
systemLangCode: this.systemLangCode,
|
|
829
|
-
systemVersion: this.systemVersion,
|
|
830
|
-
transportProvider: __classPrivateFieldGet(this, _Client_transportProvider, "f"),
|
|
831
|
-
cdn,
|
|
832
|
-
disableUpdates: !main || cdn,
|
|
833
|
-
publicKeys: __classPrivateFieldGet(this, _Client_publicKeys, "f"),
|
|
834
|
-
});
|
|
835
|
-
client.connectionCallback = __classPrivateFieldGet(this, _Client_networkStatisticsManager, "f").getTransportReadWriteCallback(cdn);
|
|
836
|
-
return client;
|
|
837
|
-
}, _Client_disconnectAllClients = function _Client_disconnectAllClients() {
|
|
838
|
-
for (const client of __classPrivateFieldGet(this, _Client_clients, "f")) {
|
|
839
|
-
client.disconnect();
|
|
840
|
-
}
|
|
841
|
-
for (const pool of Object.values(__classPrivateFieldGet(this, _Client_downloadPools, "f"))) {
|
|
842
|
-
pool.disconnect();
|
|
843
|
-
}
|
|
844
|
-
for (const pool of Object.values(__classPrivateFieldGet(this, _Client_uploadPools, "f"))) {
|
|
845
|
-
pool.disconnect();
|
|
846
|
-
}
|
|
847
|
-
}, _Client_client_get = function _Client_client_get() {
|
|
848
|
-
return __classPrivateFieldGet(this, _Client_clients, "f")[0];
|
|
849
|
-
}, _Client_propagateConnectionState = function _Client_propagateConnectionState(connectionState) {
|
|
850
|
-
__classPrivateFieldGet(this, _Client_instances, "m", _Client_queueHandleCtxUpdate).call(this, { connectionState });
|
|
851
|
-
__classPrivateFieldSet(this, _Client_lastPropagatedConnectionState, connectionState, "f");
|
|
852
|
-
}, _Client_initStorage = async function _Client_initStorage() {
|
|
853
|
-
if (!__classPrivateFieldGet(this, _Client_storageInited, "f")) {
|
|
854
|
-
await this.storage.initialize();
|
|
855
|
-
if (!__classPrivateFieldGet(this, _Client_guaranteeUpdateDelivery, "f")) {
|
|
856
|
-
await this.storage.deleteUpdates();
|
|
857
|
-
}
|
|
858
|
-
__classPrivateFieldSet(this, _Client_storageInited, true, "f");
|
|
859
|
-
}
|
|
860
|
-
}, handleMigrationError)](err) {
|
|
778
|
+
async [handleMigrationError](err) {
|
|
861
779
|
let newDc = String(err.dc);
|
|
862
|
-
if (Math.abs(getDcId(
|
|
780
|
+
if (Math.abs(getDcId(this.#client.dc, this.#client.cdn)) >= 10_000) {
|
|
863
781
|
newDc += "-test";
|
|
864
782
|
}
|
|
865
783
|
this.disconnect();
|
|
866
784
|
await this.storage.setDc(newDc);
|
|
867
785
|
await this.storage.setAuthKey(null);
|
|
868
786
|
await this.connect();
|
|
869
|
-
|
|
787
|
+
this.#LhandleMigrationError.debug(`migrated to DC${newDc}`);
|
|
870
788
|
}
|
|
871
789
|
disconnect() {
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
790
|
+
this.#disconnectAllClients();
|
|
791
|
+
this.#clientDisconnectionLoopAbortController?.abort();
|
|
792
|
+
this.#updateGapRecoveryLoopAbortController?.abort();
|
|
793
|
+
this.#updateManager.closeAllChats();
|
|
794
|
+
}
|
|
795
|
+
#lastPropagatedAuthorizationState = null;
|
|
796
|
+
async #propagateAuthorizationState(authorized) {
|
|
797
|
+
if (this.#lastPropagatedAuthorizationState != authorized) {
|
|
798
|
+
await this.#handleCtxUpdate({ authorizationState: { authorized } });
|
|
799
|
+
this.#lastPropagatedAuthorizationState = authorized;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
async #getSelfId() {
|
|
803
|
+
const id = await this.storage.getAccountId();
|
|
804
|
+
if (id == null) {
|
|
805
|
+
throw new Error("Unauthorized");
|
|
806
|
+
}
|
|
807
|
+
return id;
|
|
808
|
+
}
|
|
809
|
+
async #getIsPremium() {
|
|
810
|
+
const maybeIsPremium = await this.storage.getIsPremium();
|
|
811
|
+
if (maybeIsPremium != null) {
|
|
812
|
+
return maybeIsPremium;
|
|
813
|
+
}
|
|
814
|
+
return this.#lastGetMe?.isPremium ?? false;
|
|
815
|
+
}
|
|
816
|
+
#lastUpdates = new Date();
|
|
817
|
+
#updateGapRecoveryLoopAbortController;
|
|
818
|
+
#startUpdateGapRecoveryLoop() {
|
|
819
|
+
drop(this.#updateGapRecoveryLoop());
|
|
820
|
+
}
|
|
821
|
+
async #updateGapRecoveryLoop() {
|
|
822
|
+
this.#updateGapRecoveryLoopAbortController?.abort();
|
|
823
|
+
const controller = this.#updateGapRecoveryLoopAbortController = new AbortController();
|
|
824
|
+
while (this.connected) {
|
|
825
|
+
try {
|
|
826
|
+
await delay(60 * SECOND, { signal: controller.signal });
|
|
827
|
+
if (!this.connected) {
|
|
828
|
+
break;
|
|
829
|
+
}
|
|
830
|
+
controller.signal.throwIfAborted();
|
|
831
|
+
if (Date.now() - this.#lastUpdates.getTime() >= 15 * MINUTE) {
|
|
832
|
+
drop(this.#updateManager.recoverUpdateGap("lastUpdates").then(() => {
|
|
833
|
+
this.#lastUpdates = new Date();
|
|
834
|
+
}));
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
catch (err) {
|
|
838
|
+
if (err instanceof DOMException && err.name == "AbortError") {
|
|
839
|
+
break;
|
|
840
|
+
}
|
|
841
|
+
else if (!this.connected) {
|
|
842
|
+
break;
|
|
843
|
+
}
|
|
844
|
+
this.#LupdateGapRecoveryLoop.error(err);
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
#clientDisconnectionLoopAbortController;
|
|
849
|
+
#startClientDisconnectionLoop() {
|
|
850
|
+
drop(this.#clientDisconnectionLoop());
|
|
851
|
+
}
|
|
852
|
+
async #clientDisconnectionLoop() {
|
|
853
|
+
const controller = this.#clientDisconnectionLoopAbortController = new AbortController();
|
|
854
|
+
while (this.connected) {
|
|
855
|
+
try {
|
|
856
|
+
await delay(60 * SECOND, { signal: controller.signal });
|
|
857
|
+
if (!this.connected) {
|
|
858
|
+
break;
|
|
859
|
+
}
|
|
860
|
+
controller.signal.throwIfAborted();
|
|
861
|
+
const now = Date.now();
|
|
862
|
+
const disconnectAfter = 5 * MINUTE;
|
|
863
|
+
this.#clients.map((client, i) => {
|
|
864
|
+
if (i > 0 && !client.disconnected && client.lastRequest && now - client.lastRequest.getTime() >= disconnectAfter) {
|
|
865
|
+
client?.disconnect();
|
|
866
|
+
}
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
catch (err) {
|
|
870
|
+
if (err instanceof DOMException && err.name == "AbortError") {
|
|
871
|
+
break;
|
|
872
|
+
}
|
|
873
|
+
else if (!this.connected) {
|
|
874
|
+
break;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
}
|
|
876
878
|
}
|
|
877
879
|
/**
|
|
878
880
|
* Signs in using the provided parameters if not already signed in.
|
|
@@ -884,10 +886,10 @@ export class Client extends Composer {
|
|
|
884
886
|
*/
|
|
885
887
|
async signIn(params) {
|
|
886
888
|
try {
|
|
887
|
-
await
|
|
888
|
-
await
|
|
889
|
-
drop(
|
|
890
|
-
|
|
889
|
+
await this.#updateManager.fetchState("signIn");
|
|
890
|
+
await this.#propagateAuthorizationState(true);
|
|
891
|
+
drop(this.#updateManager.recoverUpdateGap("signIn"));
|
|
892
|
+
this.#LsignIn.debug("already signed in");
|
|
891
893
|
return;
|
|
892
894
|
}
|
|
893
895
|
catch (err) {
|
|
@@ -895,10 +897,10 @@ export class Client extends Composer {
|
|
|
895
897
|
throw err;
|
|
896
898
|
}
|
|
897
899
|
}
|
|
898
|
-
if (!
|
|
900
|
+
if (!this.#apiId) {
|
|
899
901
|
throw new InputError("apiId not set");
|
|
900
902
|
}
|
|
901
|
-
if (!
|
|
903
|
+
if (!this.#apiHash) {
|
|
902
904
|
throw new InputError("apiHash not set");
|
|
903
905
|
}
|
|
904
906
|
if (typeof params === "undefined") {
|
|
@@ -910,11 +912,11 @@ export class Client extends Composer {
|
|
|
910
912
|
params = { phone: () => mustPrompt("Phone number:"), code: () => mustPrompt("Verification code:"), password: () => mustPrompt("Password:") };
|
|
911
913
|
}
|
|
912
914
|
}
|
|
913
|
-
|
|
915
|
+
this.#LsignIn.debug("authorizing with", typeof params === "string" ? "bot token" : Api.is("auth.exportedAuthorization", params) ? "exported authorization" : "AuthorizeUserParams");
|
|
914
916
|
if (params && "botToken" in params) {
|
|
915
917
|
while (true) {
|
|
916
918
|
try {
|
|
917
|
-
const auth = await this.invoke({ _: "auth.importBotAuthorization", api_id:
|
|
919
|
+
const auth = await this.invoke({ _: "auth.importBotAuthorization", api_id: this.#apiId, api_hash: this.#apiHash, bot_auth_token: params.botToken, flags: 0 });
|
|
918
920
|
await this.storage.setAccountId(Number(Api.as("auth.authorization", auth).user.id));
|
|
919
921
|
await this.storage.setAccountType("bot");
|
|
920
922
|
break;
|
|
@@ -929,9 +931,9 @@ export class Client extends Composer {
|
|
|
929
931
|
}
|
|
930
932
|
}
|
|
931
933
|
}
|
|
932
|
-
|
|
933
|
-
await
|
|
934
|
-
await
|
|
934
|
+
this.#LsignIn.debug("authorized as bot");
|
|
935
|
+
await this.#propagateAuthorizationState(true);
|
|
936
|
+
await this.#updateManager.fetchState("authorize");
|
|
935
937
|
return;
|
|
936
938
|
}
|
|
937
939
|
auth: while (true) {
|
|
@@ -944,8 +946,8 @@ export class Client extends Composer {
|
|
|
944
946
|
const sendCode = () => this.invoke({
|
|
945
947
|
_: "auth.sendCode",
|
|
946
948
|
phone_number: phone,
|
|
947
|
-
api_id:
|
|
948
|
-
api_hash:
|
|
949
|
+
api_id: this.#apiId,
|
|
950
|
+
api_hash: this.#apiHash,
|
|
949
951
|
settings: { _: "codeSettings" },
|
|
950
952
|
}).then((v) => Api.as("auth.sentCode", v));
|
|
951
953
|
try {
|
|
@@ -967,279 +969,148 @@ export class Client extends Composer {
|
|
|
967
969
|
continue;
|
|
968
970
|
}
|
|
969
971
|
else {
|
|
970
|
-
throw err;
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
__classPrivateFieldGet(this, _Client_LsignIn, "f").debug("verification code sent");
|
|
975
|
-
let err;
|
|
976
|
-
code: while (true) {
|
|
977
|
-
const code = typeof params.code === "string" ? params.code : await params.code();
|
|
978
|
-
try {
|
|
979
|
-
const auth = await this.invoke({
|
|
980
|
-
_: "auth.signIn",
|
|
981
|
-
phone_number: phone,
|
|
982
|
-
phone_code: code,
|
|
983
|
-
phone_code_hash: sentCode.phone_code_hash,
|
|
984
|
-
});
|
|
985
|
-
await this.storage.setAccountId(Number(Api.as("auth.authorization", auth).user.id));
|
|
986
|
-
await this.storage.setAccountType("user");
|
|
987
|
-
__classPrivateFieldGet(this, _Client_LsignIn, "f").debug("signed in as user");
|
|
988
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateAuthorizationState).call(this, true);
|
|
989
|
-
await __classPrivateFieldGet(this, _Client_updateManager, "f").fetchState("signIn");
|
|
990
|
-
return;
|
|
991
|
-
}
|
|
992
|
-
catch (err_) {
|
|
993
|
-
if (err_ instanceof PhoneCodeInvalid) {
|
|
994
|
-
continue code;
|
|
995
|
-
}
|
|
996
|
-
else {
|
|
997
|
-
err = err_;
|
|
998
|
-
break code;
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
if (!(err instanceof SessionPasswordNeeded)) {
|
|
1003
|
-
throw err;
|
|
1004
|
-
}
|
|
1005
|
-
password: while (true) {
|
|
1006
|
-
const ap = await this.invoke({ _: "account.getPassword" });
|
|
1007
|
-
if (!(Api.is("passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow", ap.current_algo))) {
|
|
1008
|
-
throw new Error(`Handling ${ap.current_algo?._} not implemented`);
|
|
1009
|
-
}
|
|
1010
|
-
try {
|
|
1011
|
-
const password = typeof params.password === "string" ? params.password : await params.password(ap.hint ?? null);
|
|
1012
|
-
const input = await checkPassword(password, ap);
|
|
1013
|
-
const auth = await this.invoke({ _: "auth.checkPassword", password: input });
|
|
1014
|
-
await this.storage.setAccountId(Number(Api.as("auth.authorization", auth).user.id));
|
|
1015
|
-
await this.storage.setAccountType("user");
|
|
1016
|
-
__classPrivateFieldGet(this, _Client_LsignIn, "f").debug("signed in as user");
|
|
1017
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateAuthorizationState).call(this, true);
|
|
1018
|
-
await __classPrivateFieldGet(this, _Client_updateManager, "f").fetchState("signIn");
|
|
1019
|
-
return;
|
|
1020
|
-
}
|
|
1021
|
-
catch (err) {
|
|
1022
|
-
if (err instanceof PasswordHashInvalid) {
|
|
1023
|
-
continue password;
|
|
1024
|
-
}
|
|
1025
|
-
else {
|
|
1026
|
-
throw err;
|
|
1027
|
-
}
|
|
1028
|
-
}
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
catch (err) {
|
|
1032
|
-
if (err == restartAuth) {
|
|
1033
|
-
continue auth;
|
|
1034
|
-
}
|
|
1035
|
-
else {
|
|
1036
|
-
throw err;
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
async signOut() {
|
|
1042
|
-
try {
|
|
1043
|
-
await Promise.all([
|
|
1044
|
-
this.storage.reset(),
|
|
1045
|
-
this.invoke({ _: "auth.logOut" }).then(() => {
|
|
1046
|
-
__classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateAuthorizationState).call(this, false);
|
|
1047
|
-
}),
|
|
1048
|
-
]);
|
|
1049
|
-
}
|
|
1050
|
-
finally {
|
|
1051
|
-
__classPrivateFieldSet(this, _Client_lastGetMe, null, "f");
|
|
1052
|
-
this.disconnect();
|
|
1053
|
-
await this.connect();
|
|
1054
|
-
}
|
|
1055
|
-
}
|
|
1056
|
-
/**
|
|
1057
|
-
* Same as calling `.connect()` followed by `.signIn(params)`.
|
|
1058
|
-
*/
|
|
1059
|
-
async start(params) {
|
|
1060
|
-
await this.connect();
|
|
1061
|
-
await this.signIn(params);
|
|
1062
|
-
}
|
|
1063
|
-
exportAuthString() {
|
|
1064
|
-
return this.storage.exportAuthString(__classPrivateFieldGet(this, _Client_apiId, "f"));
|
|
1065
|
-
}
|
|
1066
|
-
async importAuthString(authString) {
|
|
1067
|
-
if (this.connected) {
|
|
1068
|
-
throw new Error("Cannot import auth string while the client is connected");
|
|
1069
|
-
}
|
|
1070
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_initStorage).call(this);
|
|
1071
|
-
await this.storage.importAuthString(authString);
|
|
1072
|
-
__classPrivateFieldSet(this, _Client_authStringImported, true, "f");
|
|
1073
|
-
if (!__classPrivateFieldGet(this, _Client_apiId, "f")) {
|
|
1074
|
-
__classPrivateFieldSet(this, _Client_apiId, await this.storage.getApiId() ?? 0, "f");
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
/**
|
|
1078
|
-
* Get a chat's inputPeer. Useful when calling API functions directly.
|
|
1079
|
-
*
|
|
1080
|
-
* @param id The identifier of a chat.
|
|
1081
|
-
*/
|
|
1082
|
-
async getInputPeer(id) {
|
|
1083
|
-
if (id === "me" || id == await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getSelfId).call(this)) {
|
|
1084
|
-
return { _: "inputPeerSelf" };
|
|
1085
|
-
}
|
|
1086
|
-
const inputPeer = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getInputPeerInner).call(this, id);
|
|
1087
|
-
if (((Api.is("inputPeerUser", inputPeer) || Api.is("inputPeerChannel", inputPeer)) && inputPeer.access_hash == 0n) && await this.storage.getAccountType() == "bot") {
|
|
1088
|
-
if ("channel_id" in inputPeer) {
|
|
1089
|
-
inputPeer.access_hash = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChannelAccessHash).call(this, inputPeer.channel_id);
|
|
1090
|
-
}
|
|
1091
|
-
else {
|
|
1092
|
-
inputPeer.access_hash = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getUserAccessHash).call(this, inputPeer.user_id);
|
|
1093
|
-
}
|
|
1094
|
-
}
|
|
1095
|
-
if ((Api.is("inputPeerUser", inputPeer) || Api.is("inputPeerChannel", inputPeer)) && inputPeer.access_hash == 0n) {
|
|
1096
|
-
throw new AccessError(`Cannot access the chat ${id} because there is no access hash for it.`);
|
|
1097
|
-
}
|
|
1098
|
-
return inputPeer;
|
|
1099
|
-
}
|
|
1100
|
-
/**
|
|
1101
|
-
* Get a channel or a supergroup's inputChannel. Useful when calling API functions directly.
|
|
1102
|
-
*
|
|
1103
|
-
* @param id The identifier of the channel or the supergroup.
|
|
1104
|
-
*/
|
|
1105
|
-
async getInputChannel(id) {
|
|
1106
|
-
const inputPeer = await this.getInputPeer(id);
|
|
1107
|
-
if (!canBeInputChannel(inputPeer)) {
|
|
1108
|
-
throw new TypeError(`The chat ${id} is not a channel neither a supergroup.`);
|
|
1109
|
-
}
|
|
1110
|
-
return toInputChannel(inputPeer);
|
|
1111
|
-
}
|
|
1112
|
-
/**
|
|
1113
|
-
* Get a user's inputUser. Useful when calling API functions directly.
|
|
1114
|
-
*
|
|
1115
|
-
* @param id The identifier of the user.
|
|
1116
|
-
*/
|
|
1117
|
-
async getInputUser(id) {
|
|
1118
|
-
const inputPeer = await this.getInputPeer(id);
|
|
1119
|
-
if (!canBeInputUser(inputPeer)) {
|
|
1120
|
-
throw new TypeError(`The chat ${id} is not a private chat.`);
|
|
1121
|
-
}
|
|
1122
|
-
return toInputUser(inputPeer);
|
|
1123
|
-
}
|
|
1124
|
-
async [(_Client_propagateAuthorizationState = async function _Client_propagateAuthorizationState(authorized) {
|
|
1125
|
-
if (__classPrivateFieldGet(this, _Client_lastPropagatedAuthorizationState, "f") != authorized) {
|
|
1126
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { authorizationState: { authorized } });
|
|
1127
|
-
__classPrivateFieldSet(this, _Client_lastPropagatedAuthorizationState, authorized, "f");
|
|
1128
|
-
}
|
|
1129
|
-
}, _Client_getSelfId = async function _Client_getSelfId() {
|
|
1130
|
-
const id = await this.storage.getAccountId();
|
|
1131
|
-
if (id == null) {
|
|
1132
|
-
throw new Error("Unauthorized");
|
|
1133
|
-
}
|
|
1134
|
-
return id;
|
|
1135
|
-
}, _Client_getIsPremium = async function _Client_getIsPremium() {
|
|
1136
|
-
const maybeIsPremium = await this.storage.getIsPremium();
|
|
1137
|
-
if (maybeIsPremium != null) {
|
|
1138
|
-
return maybeIsPremium;
|
|
1139
|
-
}
|
|
1140
|
-
return __classPrivateFieldGet(this, _Client_lastGetMe, "f")?.isPremium ?? false;
|
|
1141
|
-
}, _Client_startUpdateGapRecoveryLoop = function _Client_startUpdateGapRecoveryLoop() {
|
|
1142
|
-
drop(__classPrivateFieldGet(this, _Client_instances, "m", _Client_updateGapRecoveryLoop).call(this));
|
|
1143
|
-
}, _Client_updateGapRecoveryLoop = async function _Client_updateGapRecoveryLoop() {
|
|
1144
|
-
__classPrivateFieldGet(this, _Client_updateGapRecoveryLoopAbortController, "f")?.abort();
|
|
1145
|
-
const controller = __classPrivateFieldSet(this, _Client_updateGapRecoveryLoopAbortController, new AbortController(), "f");
|
|
1146
|
-
while (this.connected) {
|
|
1147
|
-
try {
|
|
1148
|
-
await delay(60 * SECOND, { signal: controller.signal });
|
|
1149
|
-
if (!this.connected) {
|
|
1150
|
-
break;
|
|
1151
|
-
}
|
|
1152
|
-
controller.signal.throwIfAborted();
|
|
1153
|
-
if (Date.now() - __classPrivateFieldGet(this, _Client_lastUpdates, "f").getTime() >= 15 * MINUTE) {
|
|
1154
|
-
drop(__classPrivateFieldGet(this, _Client_updateManager, "f").recoverUpdateGap("lastUpdates").then(() => {
|
|
1155
|
-
__classPrivateFieldSet(this, _Client_lastUpdates, new Date(), "f");
|
|
1156
|
-
}));
|
|
1157
|
-
}
|
|
1158
|
-
}
|
|
1159
|
-
catch (err) {
|
|
1160
|
-
if (err instanceof DOMException && err.name == "AbortError") {
|
|
1161
|
-
break;
|
|
972
|
+
throw err;
|
|
973
|
+
}
|
|
974
|
+
}
|
|
1162
975
|
}
|
|
1163
|
-
|
|
1164
|
-
|
|
976
|
+
this.#LsignIn.debug("verification code sent");
|
|
977
|
+
let err;
|
|
978
|
+
code: while (true) {
|
|
979
|
+
const code = typeof params.code === "string" ? params.code : await params.code();
|
|
980
|
+
try {
|
|
981
|
+
const auth = await this.invoke({
|
|
982
|
+
_: "auth.signIn",
|
|
983
|
+
phone_number: phone,
|
|
984
|
+
phone_code: code,
|
|
985
|
+
phone_code_hash: sentCode.phone_code_hash,
|
|
986
|
+
});
|
|
987
|
+
await this.storage.setAccountId(Number(Api.as("auth.authorization", auth).user.id));
|
|
988
|
+
await this.storage.setAccountType("user");
|
|
989
|
+
this.#LsignIn.debug("signed in as user");
|
|
990
|
+
await this.#propagateAuthorizationState(true);
|
|
991
|
+
await this.#updateManager.fetchState("signIn");
|
|
992
|
+
return;
|
|
993
|
+
}
|
|
994
|
+
catch (err_) {
|
|
995
|
+
if (err_ instanceof PhoneCodeInvalid) {
|
|
996
|
+
continue code;
|
|
997
|
+
}
|
|
998
|
+
else {
|
|
999
|
+
err = err_;
|
|
1000
|
+
break code;
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1165
1003
|
}
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
}
|
|
1169
|
-
}, _Client_startClientDisconnectionLoop = function _Client_startClientDisconnectionLoop() {
|
|
1170
|
-
drop(__classPrivateFieldGet(this, _Client_instances, "m", _Client_clientDisconnectionLoop).call(this));
|
|
1171
|
-
}, _Client_clientDisconnectionLoop = async function _Client_clientDisconnectionLoop() {
|
|
1172
|
-
const controller = __classPrivateFieldSet(this, _Client_clientDisconnectionLoopAbortController, new AbortController(), "f");
|
|
1173
|
-
while (this.connected) {
|
|
1174
|
-
try {
|
|
1175
|
-
await delay(60 * SECOND, { signal: controller.signal });
|
|
1176
|
-
if (!this.connected) {
|
|
1177
|
-
break;
|
|
1004
|
+
if (!(err instanceof SessionPasswordNeeded)) {
|
|
1005
|
+
throw err;
|
|
1178
1006
|
}
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
if (i > 0 && !client.disconnected && client.lastRequest && now - client.lastRequest.getTime() >= disconnectAfter) {
|
|
1184
|
-
client?.disconnect();
|
|
1007
|
+
password: while (true) {
|
|
1008
|
+
const ap = await this.invoke({ _: "account.getPassword" });
|
|
1009
|
+
if (!(Api.is("passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow", ap.current_algo))) {
|
|
1010
|
+
throw new Error(`Handling ${ap.current_algo?._} not implemented`);
|
|
1185
1011
|
}
|
|
1186
|
-
|
|
1012
|
+
try {
|
|
1013
|
+
const password = typeof params.password === "string" ? params.password : await params.password(ap.hint ?? null);
|
|
1014
|
+
const input = await checkPassword(password, ap);
|
|
1015
|
+
const auth = await this.invoke({ _: "auth.checkPassword", password: input });
|
|
1016
|
+
await this.storage.setAccountId(Number(Api.as("auth.authorization", auth).user.id));
|
|
1017
|
+
await this.storage.setAccountType("user");
|
|
1018
|
+
this.#LsignIn.debug("signed in as user");
|
|
1019
|
+
await this.#propagateAuthorizationState(true);
|
|
1020
|
+
await this.#updateManager.fetchState("signIn");
|
|
1021
|
+
return;
|
|
1022
|
+
}
|
|
1023
|
+
catch (err) {
|
|
1024
|
+
if (err instanceof PasswordHashInvalid) {
|
|
1025
|
+
continue password;
|
|
1026
|
+
}
|
|
1027
|
+
else {
|
|
1028
|
+
throw err;
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1187
1032
|
}
|
|
1188
1033
|
catch (err) {
|
|
1189
|
-
if (err
|
|
1190
|
-
|
|
1034
|
+
if (err == restartAuth) {
|
|
1035
|
+
continue auth;
|
|
1191
1036
|
}
|
|
1192
|
-
else
|
|
1193
|
-
|
|
1037
|
+
else {
|
|
1038
|
+
throw err;
|
|
1194
1039
|
}
|
|
1195
1040
|
}
|
|
1196
1041
|
}
|
|
1197
|
-
}
|
|
1042
|
+
}
|
|
1043
|
+
async signOut() {
|
|
1044
|
+
try {
|
|
1045
|
+
await Promise.all([
|
|
1046
|
+
this.storage.reset(),
|
|
1047
|
+
this.invoke({ _: "auth.logOut" }).then(() => {
|
|
1048
|
+
this.#propagateAuthorizationState(false);
|
|
1049
|
+
}),
|
|
1050
|
+
]);
|
|
1051
|
+
}
|
|
1052
|
+
finally {
|
|
1053
|
+
this.#lastGetMe = null;
|
|
1054
|
+
this.disconnect();
|
|
1055
|
+
await this.connect();
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
/**
|
|
1059
|
+
* Same as calling `.connect()` followed by `.signIn(params)`.
|
|
1060
|
+
*/
|
|
1061
|
+
async start(params) {
|
|
1062
|
+
await this.connect();
|
|
1063
|
+
await this.signIn(params);
|
|
1064
|
+
}
|
|
1065
|
+
async #getClient(params) {
|
|
1198
1066
|
let client;
|
|
1199
1067
|
switch (params.type) {
|
|
1200
1068
|
case undefined:
|
|
1201
|
-
client = await
|
|
1069
|
+
client = await this.#getMainClient(params.dc);
|
|
1202
1070
|
break;
|
|
1203
1071
|
case "download":
|
|
1204
|
-
client = await
|
|
1072
|
+
client = await this.#getDownloadClient(params.dc);
|
|
1205
1073
|
break;
|
|
1206
1074
|
case "upload":
|
|
1207
|
-
client = await
|
|
1075
|
+
client = await this.#getUploadClient();
|
|
1208
1076
|
break;
|
|
1209
1077
|
}
|
|
1210
|
-
if (client !==
|
|
1078
|
+
if (client !== this.#client && !this.disconnected && client.disconnected) {
|
|
1211
1079
|
await client.connect();
|
|
1212
1080
|
}
|
|
1213
1081
|
return client;
|
|
1214
|
-
}
|
|
1215
|
-
|
|
1216
|
-
|
|
1082
|
+
}
|
|
1083
|
+
#getMainClientMutex = new Mutex();
|
|
1084
|
+
async #getMainClient(dc) {
|
|
1085
|
+
if (dc === undefined || dc == this.#client?.dc) {
|
|
1086
|
+
return this.#client;
|
|
1217
1087
|
}
|
|
1218
|
-
let client =
|
|
1088
|
+
let client = this.#clients.find((v) => v.dc == dc);
|
|
1219
1089
|
if (client) {
|
|
1220
1090
|
return client;
|
|
1221
1091
|
}
|
|
1222
|
-
const unlock = await
|
|
1223
|
-
client =
|
|
1092
|
+
const unlock = await this.#getMainClientMutex.lock();
|
|
1093
|
+
client = this.#clients.find((v) => v.dc == dc);
|
|
1224
1094
|
if (client) {
|
|
1225
1095
|
return client;
|
|
1226
1096
|
}
|
|
1227
1097
|
try {
|
|
1228
|
-
client =
|
|
1229
|
-
await
|
|
1230
|
-
|
|
1098
|
+
client = this.#newClient(dc, false, false);
|
|
1099
|
+
await this.#setupClient(client);
|
|
1100
|
+
this.#clients.push(client);
|
|
1231
1101
|
return client;
|
|
1232
1102
|
}
|
|
1233
1103
|
finally {
|
|
1234
1104
|
unlock();
|
|
1235
1105
|
}
|
|
1236
|
-
}
|
|
1237
|
-
|
|
1238
|
-
|
|
1106
|
+
}
|
|
1107
|
+
async #getDownloadClient(dc) {
|
|
1108
|
+
dc ??= this.#client.dc;
|
|
1109
|
+
const pool = this.#downloadPools[dc] ??= new ClientEncryptedPool();
|
|
1239
1110
|
if (!pool.size) {
|
|
1240
1111
|
if (!pool.size) {
|
|
1241
1112
|
for (let i = 0; i < DOWNLOAD_POOL_SIZE; ++i) {
|
|
1242
|
-
pool.add(
|
|
1113
|
+
pool.add(this.#newClient(dc, false, true));
|
|
1243
1114
|
}
|
|
1244
1115
|
}
|
|
1245
1116
|
}
|
|
@@ -1247,28 +1118,31 @@ export class Client extends Composer {
|
|
|
1247
1118
|
if (client.authKey.length) {
|
|
1248
1119
|
return client;
|
|
1249
1120
|
}
|
|
1250
|
-
await
|
|
1121
|
+
await this.#setupClient(client);
|
|
1251
1122
|
return client;
|
|
1252
|
-
}
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
const
|
|
1123
|
+
}
|
|
1124
|
+
async #getUploadPoolSize() {
|
|
1125
|
+
const dc = this.#client.dc;
|
|
1126
|
+
return (dc != "2" && dc != "4") || await this.#getIsPremium() ? 8 : 4;
|
|
1127
|
+
}
|
|
1128
|
+
async #getUploadClient() {
|
|
1129
|
+
const dc = this.#client.dc;
|
|
1130
|
+
const poolSize = await this.#getUploadPoolSize();
|
|
1131
|
+
const pool = this.#uploadPools[dc] ??= new ClientEncryptedPool();
|
|
1259
1132
|
if (!pool.size) {
|
|
1260
1133
|
for (let i = 0; i < poolSize; ++i) {
|
|
1261
|
-
pool.add(await
|
|
1134
|
+
pool.add(await this.#newClient(dc, false, true));
|
|
1262
1135
|
}
|
|
1263
1136
|
}
|
|
1264
1137
|
const client = pool.nextClient();
|
|
1265
1138
|
if (client.authKey.length) {
|
|
1266
1139
|
return client;
|
|
1267
1140
|
}
|
|
1268
|
-
await
|
|
1141
|
+
await this.#setupClient(client);
|
|
1269
1142
|
return client;
|
|
1270
|
-
}
|
|
1271
|
-
|
|
1143
|
+
}
|
|
1144
|
+
async #setupClient(client) {
|
|
1145
|
+
const storage = client.dc == this.#client.dc ? this.storage : new StorageOperations(this.storage.provider.branch(client.dc + (client.cdn ? "_cdn" : "")));
|
|
1272
1146
|
const [authKey, serverSalt] = await Promise.all([storage.getAuthKey(), storage.getServerSalt()]);
|
|
1273
1147
|
if (authKey) {
|
|
1274
1148
|
await client.setAuthKey(authKey);
|
|
@@ -1278,17 +1152,18 @@ export class Client extends Composer {
|
|
|
1278
1152
|
}
|
|
1279
1153
|
await client.connect();
|
|
1280
1154
|
if (!authKey) {
|
|
1281
|
-
await
|
|
1155
|
+
await this.#importAuthorization(client);
|
|
1282
1156
|
}
|
|
1283
1157
|
await storage.setAuthKey(client.authKey);
|
|
1284
|
-
if (client.dc !==
|
|
1158
|
+
if (client.dc !== this.#client.dc) {
|
|
1285
1159
|
await storage.setServerSalt(client.serverSalt);
|
|
1286
1160
|
client.handlers.onNewServerSalt = async (serverSalt) => {
|
|
1287
1161
|
await storage.setServerSalt(serverSalt);
|
|
1288
1162
|
};
|
|
1289
1163
|
}
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1164
|
+
}
|
|
1165
|
+
async #importAuthorization(client) {
|
|
1166
|
+
if (this.#client.dc == client.dc && this.#client.cdn == client.cdn) {
|
|
1292
1167
|
const [authKey, serverSalt] = await Promise.all([this.storage.getAuthKey(), this.storage.getServerSalt()]);
|
|
1293
1168
|
if (authKey) {
|
|
1294
1169
|
await client.setAuthKey(authKey);
|
|
@@ -1298,29 +1173,30 @@ export class Client extends Composer {
|
|
|
1298
1173
|
}
|
|
1299
1174
|
return;
|
|
1300
1175
|
}
|
|
1301
|
-
const exportedAuthorization = await
|
|
1176
|
+
const exportedAuthorization = await this.#client.invoke({ _: "auth.exportAuthorization", dc_id: getDcId(client.dc, client.cdn) });
|
|
1302
1177
|
await client.invoke({ ...exportedAuthorization, _: "auth.importAuthorization" });
|
|
1303
|
-
}
|
|
1304
|
-
|
|
1178
|
+
}
|
|
1179
|
+
async #invoke(function_, params) {
|
|
1180
|
+
if (!this.#client) {
|
|
1305
1181
|
throw new ConnectionError("Not connected.");
|
|
1306
1182
|
}
|
|
1307
1183
|
let n = 1;
|
|
1308
1184
|
let client;
|
|
1309
1185
|
while (true) {
|
|
1310
|
-
client = params ? await
|
|
1311
|
-
const main = client ===
|
|
1186
|
+
client = params ? await this.#getClient(params) : this.#client;
|
|
1187
|
+
const main = client === this.#client;
|
|
1312
1188
|
try {
|
|
1313
1189
|
const result = await client.invoke(function_);
|
|
1314
1190
|
if (main) {
|
|
1315
1191
|
try {
|
|
1316
|
-
await
|
|
1192
|
+
await this.#updateManager.processResult(result);
|
|
1317
1193
|
}
|
|
1318
1194
|
catch (err) {
|
|
1319
|
-
|
|
1195
|
+
this.#L.error("failed to process result:", err);
|
|
1320
1196
|
}
|
|
1321
1197
|
if (Api.isOfEnum("Update", result) || Api.isOfEnum("Updates", result)) {
|
|
1322
1198
|
return new Promise((resolve) => {
|
|
1323
|
-
|
|
1199
|
+
this.#updateManager.processUpdates(result, true, Mtproto.is("ping", function_) ? null : function_, () => resolve(result));
|
|
1324
1200
|
});
|
|
1325
1201
|
}
|
|
1326
1202
|
}
|
|
@@ -1328,13 +1204,13 @@ export class Client extends Composer {
|
|
|
1328
1204
|
}
|
|
1329
1205
|
catch (err) {
|
|
1330
1206
|
if (err instanceof AuthKeyUnregistered && !main) {
|
|
1331
|
-
await
|
|
1207
|
+
await this.#importAuthorization(client);
|
|
1332
1208
|
continue;
|
|
1333
1209
|
}
|
|
1334
1210
|
else if (err instanceof ConnectionError && !main && !this.disconnected) {
|
|
1335
1211
|
continue;
|
|
1336
1212
|
}
|
|
1337
|
-
else if (await
|
|
1213
|
+
else if (await this.#handleInvokeError(Object.freeze({ client: this, error: err, function: function_, n: n++ }), () => Promise.resolve(false))) {
|
|
1338
1214
|
continue;
|
|
1339
1215
|
}
|
|
1340
1216
|
else {
|
|
@@ -1342,23 +1218,85 @@ export class Client extends Composer {
|
|
|
1342
1218
|
}
|
|
1343
1219
|
}
|
|
1344
1220
|
}
|
|
1345
|
-
}
|
|
1221
|
+
}
|
|
1222
|
+
#handleInvokeError = skipInvoke();
|
|
1223
|
+
/**
|
|
1224
|
+
* Invokes a function waiting and returning its reply if the second parameter is not `true`. Requires the client
|
|
1225
|
+
* to be connected.
|
|
1226
|
+
*
|
|
1227
|
+
* @param function_ The function to invoke.
|
|
1228
|
+
*/
|
|
1229
|
+
invoke = Object.assign(this.#invoke, {
|
|
1230
|
+
use: (handler) => {
|
|
1231
|
+
const handle = this.#handleInvokeError;
|
|
1232
|
+
this.#handleInvokeError = async (ctx, next) => {
|
|
1233
|
+
let result = null;
|
|
1234
|
+
return await handle(ctx, async () => {
|
|
1235
|
+
if (result != null)
|
|
1236
|
+
return result;
|
|
1237
|
+
result = await handler(ctx, next);
|
|
1238
|
+
return result;
|
|
1239
|
+
});
|
|
1240
|
+
};
|
|
1241
|
+
},
|
|
1242
|
+
});
|
|
1243
|
+
exportAuthString() {
|
|
1244
|
+
return this.storage.exportAuthString(this.#apiId);
|
|
1245
|
+
}
|
|
1246
|
+
#authStringImported = false;
|
|
1247
|
+
async importAuthString(authString) {
|
|
1248
|
+
if (this.connected) {
|
|
1249
|
+
throw new Error("Cannot import auth string while the client is connected");
|
|
1250
|
+
}
|
|
1251
|
+
await this.#initStorage();
|
|
1252
|
+
await this.storage.importAuthString(authString);
|
|
1253
|
+
this.#authStringImported = true;
|
|
1254
|
+
if (!this.#apiId) {
|
|
1255
|
+
this.#apiId = await this.storage.getApiId() ?? 0;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
async #getUserAccessHash(userId) {
|
|
1346
1259
|
const users = await this.invoke({ _: "users.getUsers", id: [{ _: "inputUser", user_id: userId, access_hash: 0n }] });
|
|
1347
1260
|
const user = Api.is("user", users[0]) ? users[0] : undefined;
|
|
1348
1261
|
if (user) {
|
|
1349
1262
|
await this.messageStorage.setEntity(user);
|
|
1350
1263
|
}
|
|
1351
1264
|
return user?.access_hash ?? 0n;
|
|
1352
|
-
}
|
|
1265
|
+
}
|
|
1266
|
+
async #getChannelAccessHash(channelId) {
|
|
1353
1267
|
const channels = await this.invoke({ _: "channels.getChannels", id: [{ _: "inputChannel", channel_id: channelId, access_hash: 0n }] });
|
|
1354
1268
|
const channel = Api.is("channel", channels.chats[0]) ? channels.chats[0] : undefined;
|
|
1355
1269
|
if (channel) {
|
|
1356
1270
|
await this.messageStorage.setEntity(channel);
|
|
1357
1271
|
}
|
|
1358
1272
|
return channel?.access_hash ?? 0n;
|
|
1359
|
-
}
|
|
1273
|
+
}
|
|
1274
|
+
/**
|
|
1275
|
+
* Get a chat's inputPeer. Useful when calling API functions directly.
|
|
1276
|
+
*
|
|
1277
|
+
* @param id The identifier of a chat.
|
|
1278
|
+
*/
|
|
1279
|
+
async getInputPeer(id) {
|
|
1280
|
+
if (id === "me" || id == await this.#getSelfId()) {
|
|
1281
|
+
return { _: "inputPeerSelf" };
|
|
1282
|
+
}
|
|
1283
|
+
const inputPeer = await this.#getInputPeerInner(id);
|
|
1284
|
+
if (((Api.is("inputPeerUser", inputPeer) || Api.is("inputPeerChannel", inputPeer)) && inputPeer.access_hash == 0n) && await this.storage.getAccountType() == "bot") {
|
|
1285
|
+
if ("channel_id" in inputPeer) {
|
|
1286
|
+
inputPeer.access_hash = await this.#getChannelAccessHash(inputPeer.channel_id);
|
|
1287
|
+
}
|
|
1288
|
+
else {
|
|
1289
|
+
inputPeer.access_hash = await this.#getUserAccessHash(inputPeer.user_id);
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
if ((Api.is("inputPeerUser", inputPeer) || Api.is("inputPeerChannel", inputPeer)) && inputPeer.access_hash == 0n) {
|
|
1293
|
+
throw new AccessError(`Cannot access the chat ${id} because there is no access hash for it.`);
|
|
1294
|
+
}
|
|
1295
|
+
return inputPeer;
|
|
1296
|
+
}
|
|
1297
|
+
async #getInputPeerChatId(inputPeer) {
|
|
1360
1298
|
if (Api.isOneOf(["inputPeerSelf", "inputUserSelf"], inputPeer)) {
|
|
1361
|
-
return await
|
|
1299
|
+
return await this.#getSelfId();
|
|
1362
1300
|
}
|
|
1363
1301
|
else if (Api.isOneOf(["inputPeerEmpty", "inputUserEmpty", "inputChannelEmpty"], inputPeer)) {
|
|
1364
1302
|
unreachable();
|
|
@@ -1366,7 +1304,32 @@ export class Client extends Composer {
|
|
|
1366
1304
|
else {
|
|
1367
1305
|
return Api.peerToChatId(inputPeer);
|
|
1368
1306
|
}
|
|
1369
|
-
}
|
|
1307
|
+
}
|
|
1308
|
+
/**
|
|
1309
|
+
* Get a channel or a supergroup's inputChannel. Useful when calling API functions directly.
|
|
1310
|
+
*
|
|
1311
|
+
* @param id The identifier of the channel or the supergroup.
|
|
1312
|
+
*/
|
|
1313
|
+
async getInputChannel(id) {
|
|
1314
|
+
const inputPeer = await this.getInputPeer(id);
|
|
1315
|
+
if (!canBeInputChannel(inputPeer)) {
|
|
1316
|
+
throw new TypeError(`The chat ${id} is not a channel neither a supergroup.`);
|
|
1317
|
+
}
|
|
1318
|
+
return toInputChannel(inputPeer);
|
|
1319
|
+
}
|
|
1320
|
+
/**
|
|
1321
|
+
* Get a user's inputUser. Useful when calling API functions directly.
|
|
1322
|
+
*
|
|
1323
|
+
* @param id The identifier of the user.
|
|
1324
|
+
*/
|
|
1325
|
+
async getInputUser(id) {
|
|
1326
|
+
const inputPeer = await this.getInputPeer(id);
|
|
1327
|
+
if (!canBeInputUser(inputPeer)) {
|
|
1328
|
+
throw new TypeError(`The chat ${id} is not a private chat.`);
|
|
1329
|
+
}
|
|
1330
|
+
return toInputUser(inputPeer);
|
|
1331
|
+
}
|
|
1332
|
+
async #getInputPeerInner(id) {
|
|
1370
1333
|
const idn = Number(id);
|
|
1371
1334
|
if (!isNaN(idn)) {
|
|
1372
1335
|
id = idn;
|
|
@@ -1382,8 +1345,8 @@ export class Client extends Composer {
|
|
|
1382
1345
|
}
|
|
1383
1346
|
else {
|
|
1384
1347
|
const resolved = await this.invoke({ _: "contacts.resolveUsername", username: id });
|
|
1385
|
-
await
|
|
1386
|
-
await
|
|
1348
|
+
await this.#updateManager.processChats(resolved.chats, resolved);
|
|
1349
|
+
await this.#updateManager.processUsers(resolved.users, resolved);
|
|
1387
1350
|
if (Api.is("peerUser", resolved.peer)) {
|
|
1388
1351
|
resolvedId = Api.peerToChatId(resolved.peer);
|
|
1389
1352
|
}
|
|
@@ -1425,15 +1388,16 @@ export class Client extends Composer {
|
|
|
1425
1388
|
const chatId = Api.peerToChatId(peer);
|
|
1426
1389
|
const minPeerReference = await this.messageStorage.getLastMinPeerReference(chatId);
|
|
1427
1390
|
if (minPeerReference) {
|
|
1428
|
-
const minInputPeer = await
|
|
1391
|
+
const minInputPeer = await this.#getMinInputPeer(canBeInputChannel(peer) ? "channel" : "user", { ...minPeerReference, senderId: chatId });
|
|
1429
1392
|
if (minInputPeer) {
|
|
1430
|
-
|
|
1393
|
+
this.#Lmin.debug("resolved input min peer", minInputPeer);
|
|
1431
1394
|
peer = minInputPeer;
|
|
1432
1395
|
}
|
|
1433
1396
|
}
|
|
1434
1397
|
}
|
|
1435
1398
|
return peer;
|
|
1436
|
-
}
|
|
1399
|
+
}
|
|
1400
|
+
async #getMinInputPeer(type, reference) {
|
|
1437
1401
|
const entity = await this.messageStorage.getEntity(reference.chatId);
|
|
1438
1402
|
if (Api.isOneOf(["channel", "channelForbidden"], entity) && entity.access_hash) {
|
|
1439
1403
|
const peer = { _: "inputPeerChannel", channel_id: entity.id, access_hash: entity.access_hash };
|
|
@@ -1447,7 +1411,8 @@ export class Client extends Composer {
|
|
|
1447
1411
|
else {
|
|
1448
1412
|
return null;
|
|
1449
1413
|
}
|
|
1450
|
-
}
|
|
1414
|
+
}
|
|
1415
|
+
async [getEntity](peer) {
|
|
1451
1416
|
const id = Api.peerToChatId(peer);
|
|
1452
1417
|
const entity = await this.messageStorage.getEntity(id);
|
|
1453
1418
|
if (entity == null && await this.storage.getAccountType() == "bot" && Api.is("peerUser", peer) || Api.is("peerChannel", peer)) {
|
|
@@ -1458,6 +1423,131 @@ export class Client extends Composer {
|
|
|
1458
1423
|
}
|
|
1459
1424
|
return await this.messageStorage.getEntity(id);
|
|
1460
1425
|
}
|
|
1426
|
+
async #handleCtxUpdate(update) {
|
|
1427
|
+
if (this.#disableUpdates && !("authorizationState" in update) && !("connectionState" in update)) {
|
|
1428
|
+
return;
|
|
1429
|
+
}
|
|
1430
|
+
try {
|
|
1431
|
+
await this.middleware()(await this.#constructContext(update), resolve);
|
|
1432
|
+
}
|
|
1433
|
+
catch (err) {
|
|
1434
|
+
this.#L.error("Failed to handle update:", err);
|
|
1435
|
+
throw err;
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
#queueHandleCtxUpdate(update) {
|
|
1439
|
+
this.#updateManager.getHandleUpdateQueue(UpdateManager.MAIN_BOX_ID).add(async () => {
|
|
1440
|
+
await this.#handleCtxUpdate(update);
|
|
1441
|
+
});
|
|
1442
|
+
}
|
|
1443
|
+
async #handleUpdate(update) {
|
|
1444
|
+
const promises = new Array();
|
|
1445
|
+
if (Api.is("updateUserName", update)) {
|
|
1446
|
+
await this.messageStorage.updateUsernames(Number(update.user_id), update.usernames.map((v) => v.username));
|
|
1447
|
+
const peer = { ...update, _: "peerUser" };
|
|
1448
|
+
const entity = await this[getEntity](peer);
|
|
1449
|
+
if (entity != null) {
|
|
1450
|
+
entity.usernames = update.usernames;
|
|
1451
|
+
entity.first_name = update.first_name;
|
|
1452
|
+
entity.last_name = update.last_name;
|
|
1453
|
+
await this.messageStorage.setEntity(entity);
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
if (this.#messageManager.canHandleUpdate(update)) {
|
|
1457
|
+
promises.push(() => this.#messageManager.handleUpdate(update));
|
|
1458
|
+
}
|
|
1459
|
+
if (this.#chatManager.canHandleUpdate(update)) {
|
|
1460
|
+
promises.push(() => this.#chatManager.handleUpdate(update));
|
|
1461
|
+
}
|
|
1462
|
+
if (this.#pollManager.canHandleUpdate(update)) {
|
|
1463
|
+
promises.push(() => this.#pollManager.handleUpdate(update));
|
|
1464
|
+
}
|
|
1465
|
+
if (this.#videoChatManager.canHandleUpdate(update)) {
|
|
1466
|
+
promises.push(() => this.#videoChatManager.handleUpdate(update));
|
|
1467
|
+
}
|
|
1468
|
+
if (this.#callbackQueryManager.canHandleUpdate(update)) {
|
|
1469
|
+
promises.push(() => this.#callbackQueryManager.handleUpdate(update));
|
|
1470
|
+
}
|
|
1471
|
+
if (this.#inlineQueryManager.canHandleUpdate(update)) {
|
|
1472
|
+
promises.push(() => this.#inlineQueryManager.handleUpdate(update));
|
|
1473
|
+
}
|
|
1474
|
+
if (this.#linkPreviewManager.canHandleUpdate(update)) {
|
|
1475
|
+
promises.push(() => this.#linkPreviewManager.handleUpdate(update));
|
|
1476
|
+
}
|
|
1477
|
+
if (this.#reactionManager.canHandleUpdate(update)) {
|
|
1478
|
+
promises.push(() => this.#reactionManager.handleUpdate(update));
|
|
1479
|
+
}
|
|
1480
|
+
if (this.#chatListManager.canHandleUpdate(update)) {
|
|
1481
|
+
promises.push(() => this.#chatListManager.handleUpdate(update));
|
|
1482
|
+
}
|
|
1483
|
+
if (this.#storyManager.canHandleUpdate(update)) {
|
|
1484
|
+
promises.push(() => this.#storyManager.handleUpdate(update));
|
|
1485
|
+
}
|
|
1486
|
+
if (this.#businessConnectionManager.canHandleUpdate(update)) {
|
|
1487
|
+
promises.push(() => this.#businessConnectionManager.handleUpdate(update));
|
|
1488
|
+
}
|
|
1489
|
+
if (this.#storyManager.canHandleUpdate(update)) {
|
|
1490
|
+
promises.push(() => this.#storyManager.handleUpdate(update));
|
|
1491
|
+
}
|
|
1492
|
+
if (this.#paymentManager.canHandleUpdate(update)) {
|
|
1493
|
+
promises.push(() => this.#paymentManager.handleUpdate(update));
|
|
1494
|
+
}
|
|
1495
|
+
if (this.#translationsManager.canHandleUpdate(update)) {
|
|
1496
|
+
promises.push(() => this.#translationsManager.handleUpdate(update));
|
|
1497
|
+
}
|
|
1498
|
+
return () => Promise.resolve().then(async () => {
|
|
1499
|
+
const updates = new Array();
|
|
1500
|
+
for (const promise of promises) {
|
|
1501
|
+
try {
|
|
1502
|
+
const update = await promise();
|
|
1503
|
+
if (update) {
|
|
1504
|
+
updates.push(update);
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
catch (err) {
|
|
1508
|
+
this.#L.error("failed to construct update:", err);
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
for (const update of updates) {
|
|
1512
|
+
try {
|
|
1513
|
+
await this.#handleCtxUpdate(update);
|
|
1514
|
+
}
|
|
1515
|
+
finally {
|
|
1516
|
+
if ("deletedMessages" in update) {
|
|
1517
|
+
for (const { chatId, messageId } of update.deletedMessages) {
|
|
1518
|
+
await this.messageStorage.setMessage(chatId, messageId, null);
|
|
1519
|
+
await this.#chatListManager.reassignChatLastMessage(chatId);
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
});
|
|
1525
|
+
}
|
|
1526
|
+
#lastGetMe = null;
|
|
1527
|
+
async #getMe() {
|
|
1528
|
+
if (this.#lastGetMe != null) {
|
|
1529
|
+
return this.#lastGetMe;
|
|
1530
|
+
}
|
|
1531
|
+
else {
|
|
1532
|
+
const user = await this.getMe();
|
|
1533
|
+
this.#lastGetMe = user;
|
|
1534
|
+
return user;
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
#previouslyConnected = false;
|
|
1538
|
+
#lastConnectionState = false;
|
|
1539
|
+
#onConnectionStateChange(connected) {
|
|
1540
|
+
if (this.#lastConnectionState != connected) {
|
|
1541
|
+
if (connected) {
|
|
1542
|
+
if (this.#previouslyConnected) {
|
|
1543
|
+
drop(this.#updateManager.recoverUpdateGap("reconnect"));
|
|
1544
|
+
}
|
|
1545
|
+
this.#previouslyConnected = true;
|
|
1546
|
+
}
|
|
1547
|
+
const connectionState = connected ? "ready" : "notConnected";
|
|
1548
|
+
this.#queueHandleCtxUpdate({ connectionState });
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1461
1551
|
//
|
|
1462
1552
|
// ========================= ACCOUNT ========================= //
|
|
1463
1553
|
//
|
|
@@ -1467,7 +1557,7 @@ export class Client extends Composer {
|
|
|
1467
1557
|
* @method ac
|
|
1468
1558
|
*/
|
|
1469
1559
|
async getMe() {
|
|
1470
|
-
let user_ = await this[getEntity]({ _: "peerUser", user_id: BigInt(await
|
|
1560
|
+
let user_ = await this[getEntity]({ _: "peerUser", user_id: BigInt(await this.#getSelfId()) });
|
|
1471
1561
|
if (user_ == null) {
|
|
1472
1562
|
const users = await this.invoke({ _: "users.getUsers", id: [{ _: "inputUserSelf" }] });
|
|
1473
1563
|
user_ = Api.as("user", users[0]);
|
|
@@ -1475,7 +1565,7 @@ export class Client extends Composer {
|
|
|
1475
1565
|
await this.storage.setIsPremium(user_.premium ?? false);
|
|
1476
1566
|
}
|
|
1477
1567
|
const user = constructUser(user_);
|
|
1478
|
-
|
|
1568
|
+
this.#lastGetMe = user;
|
|
1479
1569
|
return user;
|
|
1480
1570
|
}
|
|
1481
1571
|
/**
|
|
@@ -1486,7 +1576,7 @@ export class Client extends Composer {
|
|
|
1486
1576
|
* @param username The username to show.
|
|
1487
1577
|
*/
|
|
1488
1578
|
async showUsername(id, username) {
|
|
1489
|
-
await
|
|
1579
|
+
await this.#accountManager.showUsername(id, username);
|
|
1490
1580
|
}
|
|
1491
1581
|
/**
|
|
1492
1582
|
* Hide a username from the current account, a bot account, a supergroup, or a channel's profile. User-only.
|
|
@@ -1496,7 +1586,7 @@ export class Client extends Composer {
|
|
|
1496
1586
|
* @param username The username to hide.
|
|
1497
1587
|
*/
|
|
1498
1588
|
async hideUsername(id, username) {
|
|
1499
|
-
await
|
|
1589
|
+
await this.#accountManager.hideUsername(id, username);
|
|
1500
1590
|
}
|
|
1501
1591
|
/**
|
|
1502
1592
|
* Reorder the usernames of the current account, a bot account, a supergroup, or a channel's profile. User-only.
|
|
@@ -1507,7 +1597,7 @@ export class Client extends Composer {
|
|
|
1507
1597
|
* @returns Whether the order was changed.
|
|
1508
1598
|
*/
|
|
1509
1599
|
async reorderUsernames(id, order) {
|
|
1510
|
-
return await
|
|
1600
|
+
return await this.#accountManager.reorderUsernames(id, order);
|
|
1511
1601
|
}
|
|
1512
1602
|
/**
|
|
1513
1603
|
* Hide all usernames from a supergroup or a channel's profile. User-only.
|
|
@@ -1516,7 +1606,7 @@ export class Client extends Composer {
|
|
|
1516
1606
|
* @param id A supergroup ID or a channel ID.
|
|
1517
1607
|
*/
|
|
1518
1608
|
async hideUsernames(id) {
|
|
1519
|
-
return await
|
|
1609
|
+
return await this.#accountManager.hideUsernames(id);
|
|
1520
1610
|
}
|
|
1521
1611
|
/**
|
|
1522
1612
|
* Get a business connection. Bot-only.
|
|
@@ -1526,7 +1616,7 @@ export class Client extends Composer {
|
|
|
1526
1616
|
* @cache
|
|
1527
1617
|
*/
|
|
1528
1618
|
async getBusinessConnection(id) {
|
|
1529
|
-
return await
|
|
1619
|
+
return await this.#businessConnectionManager.getBusinessConnection(id);
|
|
1530
1620
|
}
|
|
1531
1621
|
/**
|
|
1532
1622
|
* Set the current account's online status. User-only.
|
|
@@ -1535,7 +1625,7 @@ export class Client extends Composer {
|
|
|
1535
1625
|
* @param online The new online status.
|
|
1536
1626
|
*/
|
|
1537
1627
|
async setOnline(online) {
|
|
1538
|
-
await
|
|
1628
|
+
await this.#accountManager.setOnline(online);
|
|
1539
1629
|
}
|
|
1540
1630
|
/**
|
|
1541
1631
|
* Set the current account's emoji status. User-only.
|
|
@@ -1544,7 +1634,7 @@ export class Client extends Composer {
|
|
|
1544
1634
|
* @param id The identifier of the emoji to be used as the new status.
|
|
1545
1635
|
*/
|
|
1546
1636
|
async setEmojiStatus(id, params) {
|
|
1547
|
-
await
|
|
1637
|
+
await this.#accountManager.setEmojiStatus(id, params);
|
|
1548
1638
|
}
|
|
1549
1639
|
/**
|
|
1550
1640
|
* Set the emoji status of a bot's user. Bot-only.
|
|
@@ -1554,7 +1644,7 @@ export class Client extends Composer {
|
|
|
1554
1644
|
* @param id The identifier of the emoji to be used as the new status.
|
|
1555
1645
|
*/
|
|
1556
1646
|
async setUserEmojiStatus(userId, id, params) {
|
|
1557
|
-
await
|
|
1647
|
+
await this.#accountManager.setUserEmojiStatus(userId, id, params);
|
|
1558
1648
|
}
|
|
1559
1649
|
/**
|
|
1560
1650
|
* Update the profile of the current user. At least one parameter must be specified. User-only.
|
|
@@ -1562,7 +1652,7 @@ export class Client extends Composer {
|
|
|
1562
1652
|
* @method ac
|
|
1563
1653
|
*/
|
|
1564
1654
|
async updateProfile(params) {
|
|
1565
|
-
await
|
|
1655
|
+
await this.#accountManager.updateProfile(params);
|
|
1566
1656
|
}
|
|
1567
1657
|
/**
|
|
1568
1658
|
* Set the birthday of the current user. User-only.
|
|
@@ -1570,7 +1660,7 @@ export class Client extends Composer {
|
|
|
1570
1660
|
* @method ac
|
|
1571
1661
|
*/
|
|
1572
1662
|
async setBirthday(params) {
|
|
1573
|
-
await
|
|
1663
|
+
await this.#accountManager.setBirthday(params);
|
|
1574
1664
|
}
|
|
1575
1665
|
/**
|
|
1576
1666
|
* Set the personal channel of the current user. User-only.
|
|
@@ -1578,7 +1668,7 @@ export class Client extends Composer {
|
|
|
1578
1668
|
* @method ac
|
|
1579
1669
|
*/
|
|
1580
1670
|
async setPersonalChannel(params) {
|
|
1581
|
-
await
|
|
1671
|
+
await this.#accountManager.setPersonalChannel(params);
|
|
1582
1672
|
}
|
|
1583
1673
|
/**
|
|
1584
1674
|
* Set the name color of the current user. User-only.
|
|
@@ -1587,7 +1677,7 @@ export class Client extends Composer {
|
|
|
1587
1677
|
* @param color The identifier of the color to set.
|
|
1588
1678
|
*/
|
|
1589
1679
|
async setNameColor(color, params) {
|
|
1590
|
-
await
|
|
1680
|
+
await this.#accountManager.setNameColor(color, params);
|
|
1591
1681
|
}
|
|
1592
1682
|
/**
|
|
1593
1683
|
* Set the profile color of the current user. User-only.
|
|
@@ -1596,7 +1686,7 @@ export class Client extends Composer {
|
|
|
1596
1686
|
* @param color The identifier of the color to set.
|
|
1597
1687
|
*/
|
|
1598
1688
|
async setProfileColor(color, params) {
|
|
1599
|
-
await
|
|
1689
|
+
await this.#accountManager.setProfileColor(color, params);
|
|
1600
1690
|
}
|
|
1601
1691
|
/**
|
|
1602
1692
|
* Set the location of the current user. User-only.
|
|
@@ -1604,7 +1694,7 @@ export class Client extends Composer {
|
|
|
1604
1694
|
* @method ac
|
|
1605
1695
|
*/
|
|
1606
1696
|
async setLocation(params) {
|
|
1607
|
-
await
|
|
1697
|
+
await this.#accountManager.setLocation(params);
|
|
1608
1698
|
}
|
|
1609
1699
|
//
|
|
1610
1700
|
// ========================= MESSAGES ========================= //
|
|
@@ -1618,7 +1708,7 @@ export class Client extends Composer {
|
|
|
1618
1708
|
* @returns The sent text message.
|
|
1619
1709
|
*/
|
|
1620
1710
|
async sendMessage(chatId, text, params) {
|
|
1621
|
-
return await
|
|
1711
|
+
return await this.#messageManager.sendMessage(chatId, text, params);
|
|
1622
1712
|
}
|
|
1623
1713
|
/**
|
|
1624
1714
|
* Send a photo.
|
|
@@ -1629,7 +1719,7 @@ export class Client extends Composer {
|
|
|
1629
1719
|
* @returns The sent photo.
|
|
1630
1720
|
*/
|
|
1631
1721
|
async sendPhoto(chatId, photo, params) {
|
|
1632
|
-
return await
|
|
1722
|
+
return await this.#messageManager.sendPhoto(chatId, photo, params);
|
|
1633
1723
|
}
|
|
1634
1724
|
/**
|
|
1635
1725
|
* Send a document.
|
|
@@ -1640,7 +1730,7 @@ export class Client extends Composer {
|
|
|
1640
1730
|
* @returns The sent document.
|
|
1641
1731
|
*/
|
|
1642
1732
|
async sendDocument(chatId, document, params) {
|
|
1643
|
-
return await
|
|
1733
|
+
return await this.#messageManager.sendDocument(chatId, document, params);
|
|
1644
1734
|
}
|
|
1645
1735
|
/**
|
|
1646
1736
|
* Send a sticker.
|
|
@@ -1651,7 +1741,7 @@ export class Client extends Composer {
|
|
|
1651
1741
|
* @returns The sent sticker.
|
|
1652
1742
|
*/
|
|
1653
1743
|
async sendSticker(chatId, sticker, params) {
|
|
1654
|
-
return await
|
|
1744
|
+
return await this.#messageManager.sendSticker(chatId, sticker, params);
|
|
1655
1745
|
}
|
|
1656
1746
|
/**
|
|
1657
1747
|
* Send a video.
|
|
@@ -1662,7 +1752,7 @@ export class Client extends Composer {
|
|
|
1662
1752
|
* @returns The sent video.
|
|
1663
1753
|
*/
|
|
1664
1754
|
async sendVideo(chatId, video, params) {
|
|
1665
|
-
return await
|
|
1755
|
+
return await this.#messageManager.sendVideo(chatId, video, params);
|
|
1666
1756
|
}
|
|
1667
1757
|
/**
|
|
1668
1758
|
* Send an animation.
|
|
@@ -1673,7 +1763,7 @@ export class Client extends Composer {
|
|
|
1673
1763
|
* @returns The sent animation.
|
|
1674
1764
|
*/
|
|
1675
1765
|
async sendAnimation(chatId, animation, params) {
|
|
1676
|
-
return await
|
|
1766
|
+
return await this.#messageManager.sendAnimation(chatId, animation, params);
|
|
1677
1767
|
}
|
|
1678
1768
|
/**
|
|
1679
1769
|
* Send a voice message.
|
|
@@ -1684,7 +1774,7 @@ export class Client extends Composer {
|
|
|
1684
1774
|
* @returns The sent voice message.
|
|
1685
1775
|
*/
|
|
1686
1776
|
async sendVoice(chatId, voice, params) {
|
|
1687
|
-
return await
|
|
1777
|
+
return await this.#messageManager.sendVoice(chatId, voice, params);
|
|
1688
1778
|
}
|
|
1689
1779
|
/**
|
|
1690
1780
|
* Send an audio file.
|
|
@@ -1695,7 +1785,7 @@ export class Client extends Composer {
|
|
|
1695
1785
|
* @returns The sent audio filr.
|
|
1696
1786
|
*/
|
|
1697
1787
|
async sendAudio(chatId, audio, params) {
|
|
1698
|
-
return await
|
|
1788
|
+
return await this.#messageManager.sendAudio(chatId, audio, params);
|
|
1699
1789
|
}
|
|
1700
1790
|
/**
|
|
1701
1791
|
* Send a media group.
|
|
@@ -1706,7 +1796,7 @@ export class Client extends Composer {
|
|
|
1706
1796
|
* @returns The sent messages.
|
|
1707
1797
|
*/
|
|
1708
1798
|
async sendMediaGroup(chatId, media, params) {
|
|
1709
|
-
return await
|
|
1799
|
+
return await this.#messageManager.sendMediaGroup(chatId, media, params);
|
|
1710
1800
|
}
|
|
1711
1801
|
/**
|
|
1712
1802
|
* Send a video note.
|
|
@@ -1717,7 +1807,7 @@ export class Client extends Composer {
|
|
|
1717
1807
|
* @returns The sent video note.
|
|
1718
1808
|
*/
|
|
1719
1809
|
async sendVideoNote(chatId, videoNote, params) {
|
|
1720
|
-
return await
|
|
1810
|
+
return await this.#messageManager.sendVideoNote(chatId, videoNote, params);
|
|
1721
1811
|
}
|
|
1722
1812
|
/**
|
|
1723
1813
|
* Send a location.
|
|
@@ -1729,7 +1819,7 @@ export class Client extends Composer {
|
|
|
1729
1819
|
* @returns The sent location.
|
|
1730
1820
|
*/
|
|
1731
1821
|
async sendLocation(chatId, latitude, longitude, params) {
|
|
1732
|
-
return await
|
|
1822
|
+
return await this.#messageManager.sendLocation(chatId, latitude, longitude, params);
|
|
1733
1823
|
}
|
|
1734
1824
|
/**
|
|
1735
1825
|
* Send a contact.
|
|
@@ -1741,7 +1831,7 @@ export class Client extends Composer {
|
|
|
1741
1831
|
* @returns The sent contact.
|
|
1742
1832
|
*/
|
|
1743
1833
|
async sendContact(chatId, firstName, number, params) {
|
|
1744
|
-
return await
|
|
1834
|
+
return await this.#messageManager.sendContact(chatId, firstName, number, params);
|
|
1745
1835
|
}
|
|
1746
1836
|
/**
|
|
1747
1837
|
* Send a dice.
|
|
@@ -1751,7 +1841,7 @@ export class Client extends Composer {
|
|
|
1751
1841
|
* @returns The sent dice.
|
|
1752
1842
|
*/
|
|
1753
1843
|
async sendDice(chatId, params) {
|
|
1754
|
-
return await
|
|
1844
|
+
return await this.#messageManager.sendDice(chatId, params);
|
|
1755
1845
|
}
|
|
1756
1846
|
/**
|
|
1757
1847
|
* Send a venue.
|
|
@@ -1765,7 +1855,7 @@ export class Client extends Composer {
|
|
|
1765
1855
|
* @returns The sent venue.
|
|
1766
1856
|
*/
|
|
1767
1857
|
async sendVenue(chatId, latitude, longitude, title, address, params) {
|
|
1768
|
-
return await
|
|
1858
|
+
return await this.#messageManager.sendVenue(chatId, latitude, longitude, title, address, params);
|
|
1769
1859
|
}
|
|
1770
1860
|
/**
|
|
1771
1861
|
* Send a poll.
|
|
@@ -1777,7 +1867,7 @@ export class Client extends Composer {
|
|
|
1777
1867
|
* @returns The sent poll.
|
|
1778
1868
|
*/
|
|
1779
1869
|
async sendPoll(chatId, question, options, params) {
|
|
1780
|
-
return await
|
|
1870
|
+
return await this.#messageManager.sendPoll(chatId, question, options, params);
|
|
1781
1871
|
}
|
|
1782
1872
|
/**
|
|
1783
1873
|
* Send an invoice. Bot-only.
|
|
@@ -1792,7 +1882,7 @@ export class Client extends Composer {
|
|
|
1792
1882
|
* @returns The sent invoice.
|
|
1793
1883
|
*/
|
|
1794
1884
|
async sendInvoice(chatId, title, description, payload, currency, prices, params) {
|
|
1795
|
-
return await
|
|
1885
|
+
return await this.#messageManager.sendInvoice(chatId, title, description, payload, currency, prices, params);
|
|
1796
1886
|
}
|
|
1797
1887
|
/**
|
|
1798
1888
|
* Edit a message's text.
|
|
@@ -1804,7 +1894,7 @@ export class Client extends Composer {
|
|
|
1804
1894
|
* @returns The edited text message.
|
|
1805
1895
|
*/
|
|
1806
1896
|
async editMessageText(chatId, messageId, text, params) {
|
|
1807
|
-
return await
|
|
1897
|
+
return await this.#messageManager.editMessageText(chatId, messageId, text, params);
|
|
1808
1898
|
}
|
|
1809
1899
|
/**
|
|
1810
1900
|
* Edit a message's caption.
|
|
@@ -1816,7 +1906,7 @@ export class Client extends Composer {
|
|
|
1816
1906
|
* @returns The edited message.
|
|
1817
1907
|
*/
|
|
1818
1908
|
async editMessageCaption(chatId, messageId, params) {
|
|
1819
|
-
return await
|
|
1909
|
+
return await this.#messageManager.editMessageCaption(chatId, messageId, params);
|
|
1820
1910
|
}
|
|
1821
1911
|
/**
|
|
1822
1912
|
* Edit a message's media.
|
|
@@ -1828,7 +1918,7 @@ export class Client extends Composer {
|
|
|
1828
1918
|
* @returns The edited message.
|
|
1829
1919
|
*/
|
|
1830
1920
|
async editMessageMedia(chatId, messageId, media, params) {
|
|
1831
|
-
return await
|
|
1921
|
+
return await this.#messageManager.editMessageMedia(chatId, messageId, media, params);
|
|
1832
1922
|
}
|
|
1833
1923
|
/**
|
|
1834
1924
|
* Edit an inline message's media.
|
|
@@ -1838,7 +1928,7 @@ export class Client extends Composer {
|
|
|
1838
1928
|
* @param media The new media of the message.
|
|
1839
1929
|
*/
|
|
1840
1930
|
async editInlineMessageMedia(inlineMessageId, media, params) {
|
|
1841
|
-
await
|
|
1931
|
+
await this.#messageManager.editInlineMessageMedia(inlineMessageId, media, params);
|
|
1842
1932
|
}
|
|
1843
1933
|
/**
|
|
1844
1934
|
* Edit an inline message's text. Bot-only.
|
|
@@ -1848,7 +1938,7 @@ export class Client extends Composer {
|
|
|
1848
1938
|
* @param text The new text of the message.
|
|
1849
1939
|
*/
|
|
1850
1940
|
async editInlineMessageText(inlineMessageId, text, params) {
|
|
1851
|
-
await
|
|
1941
|
+
await this.#messageManager.editInlineMessageText(inlineMessageId, text, params);
|
|
1852
1942
|
}
|
|
1853
1943
|
/**
|
|
1854
1944
|
* Edit an inline message's caption. Bot-only.
|
|
@@ -1857,7 +1947,7 @@ export class Client extends Composer {
|
|
|
1857
1947
|
* @param inlineMessageId The identifier of the inline message.
|
|
1858
1948
|
*/
|
|
1859
1949
|
async editInlineMessageCaption(inlineMessageId, params) {
|
|
1860
|
-
await
|
|
1950
|
+
await this.#messageManager.editInlineMessageCaption(inlineMessageId, params);
|
|
1861
1951
|
}
|
|
1862
1952
|
/**
|
|
1863
1953
|
* Edit a message's reply markup.
|
|
@@ -1868,7 +1958,7 @@ export class Client extends Composer {
|
|
|
1868
1958
|
* @returns The edited message.
|
|
1869
1959
|
*/
|
|
1870
1960
|
async editMessageReplyMarkup(chatId, messageId, params) {
|
|
1871
|
-
return await
|
|
1961
|
+
return await this.#messageManager.editMessageReplyMarkup(chatId, messageId, params);
|
|
1872
1962
|
}
|
|
1873
1963
|
/**
|
|
1874
1964
|
* Edit an inline message's reply markup. Bot-only.
|
|
@@ -1877,7 +1967,7 @@ export class Client extends Composer {
|
|
|
1877
1967
|
* @param inlineMessageId The identifier of the inline message.
|
|
1878
1968
|
*/
|
|
1879
1969
|
async editInlineMessageReplyMarkup(inlineMessageId, params) {
|
|
1880
|
-
await
|
|
1970
|
+
await this.#messageManager.editInlineMessageReplyMarkup(inlineMessageId, params);
|
|
1881
1971
|
}
|
|
1882
1972
|
/**
|
|
1883
1973
|
* Edit a message's live location.
|
|
@@ -1890,7 +1980,7 @@ export class Client extends Composer {
|
|
|
1890
1980
|
* @returns The edited location message.
|
|
1891
1981
|
*/
|
|
1892
1982
|
async editMessageLiveLocation(chatId, messageId, latitude, longitude, params) {
|
|
1893
|
-
return await
|
|
1983
|
+
return await this.#messageManager.editMessageLiveLocation(chatId, messageId, latitude, longitude, params);
|
|
1894
1984
|
}
|
|
1895
1985
|
/**
|
|
1896
1986
|
* Edit an inline message's live location. Bot-only.
|
|
@@ -1902,7 +1992,7 @@ export class Client extends Composer {
|
|
|
1902
1992
|
* @returns The edited location message.
|
|
1903
1993
|
*/
|
|
1904
1994
|
async editInlineMessageLiveLocation(inlineMessageId, latitude, longitude, params) {
|
|
1905
|
-
await
|
|
1995
|
+
await this.#messageManager.editInlineMessageLiveLocation(inlineMessageId, latitude, longitude, params);
|
|
1906
1996
|
}
|
|
1907
1997
|
/**
|
|
1908
1998
|
* Retrieve multiple messages.
|
|
@@ -1917,7 +2007,7 @@ export class Client extends Composer {
|
|
|
1917
2007
|
* @cache
|
|
1918
2008
|
*/
|
|
1919
2009
|
async getMessages(chatId, messageIds) {
|
|
1920
|
-
return await
|
|
2010
|
+
return await this.#messageManager.getMessages(chatId, messageIds);
|
|
1921
2011
|
}
|
|
1922
2012
|
/**
|
|
1923
2013
|
* Retrieve a single message.
|
|
@@ -1932,7 +2022,7 @@ export class Client extends Composer {
|
|
|
1932
2022
|
* @cache
|
|
1933
2023
|
*/
|
|
1934
2024
|
async getMessage(chatId, messageId) {
|
|
1935
|
-
return await
|
|
2025
|
+
return await this.#messageManager.getMessage(chatId, messageId);
|
|
1936
2026
|
}
|
|
1937
2027
|
/**
|
|
1938
2028
|
* Retrieve a message using its link.
|
|
@@ -1945,7 +2035,7 @@ export class Client extends Composer {
|
|
|
1945
2035
|
* @returns The message that was linked to.
|
|
1946
2036
|
*/
|
|
1947
2037
|
async resolveMessageLink(link) {
|
|
1948
|
-
return await
|
|
2038
|
+
return await this.#messageManager.resolveMessageLink(link);
|
|
1949
2039
|
}
|
|
1950
2040
|
/**
|
|
1951
2041
|
* Delete multiple messages.
|
|
@@ -1955,7 +2045,7 @@ export class Client extends Composer {
|
|
|
1955
2045
|
* @param messageIds The identifiers of the messages to delete.
|
|
1956
2046
|
*/
|
|
1957
2047
|
async deleteMessages(chatId, messageIds, params) {
|
|
1958
|
-
await
|
|
2048
|
+
await this.#messageManager.deleteMessages(chatId, messageIds, params);
|
|
1959
2049
|
}
|
|
1960
2050
|
/**
|
|
1961
2051
|
* Delete a single message.
|
|
@@ -1965,7 +2055,7 @@ export class Client extends Composer {
|
|
|
1965
2055
|
* @param messageId The identifier of the message to delete.
|
|
1966
2056
|
*/
|
|
1967
2057
|
async deleteMessage(chatId, messageId, params) {
|
|
1968
|
-
await
|
|
2058
|
+
await this.#messageManager.deleteMessages(chatId, [messageId], params);
|
|
1969
2059
|
}
|
|
1970
2060
|
/**
|
|
1971
2061
|
* Delete all messages sent by a specific member of a chat. User-only.
|
|
@@ -1975,7 +2065,7 @@ export class Client extends Composer {
|
|
|
1975
2065
|
* @param memberId The identifier of the member.
|
|
1976
2066
|
*/
|
|
1977
2067
|
async deleteChatMemberMessages(chatId, memberId) {
|
|
1978
|
-
await
|
|
2068
|
+
await this.#messageManager.deleteChatMemberMessages(chatId, memberId);
|
|
1979
2069
|
}
|
|
1980
2070
|
/**
|
|
1981
2071
|
* Delete multiple scheduled messages.
|
|
@@ -1985,7 +2075,7 @@ export class Client extends Composer {
|
|
|
1985
2075
|
* @param messageIds The identifiers of the scheduled messages to delete.
|
|
1986
2076
|
*/
|
|
1987
2077
|
async deleteScheduledMessages(chatId, messageIds) {
|
|
1988
|
-
await
|
|
2078
|
+
await this.#messageManager.deleteScheduledMessages(chatId, messageIds);
|
|
1989
2079
|
}
|
|
1990
2080
|
/**
|
|
1991
2081
|
* Delete a scheduled message.
|
|
@@ -1995,7 +2085,7 @@ export class Client extends Composer {
|
|
|
1995
2085
|
* @param messageId The identifier of the scheduled message to delete.
|
|
1996
2086
|
*/
|
|
1997
2087
|
async deleteScheduledMessage(chatId, messageId) {
|
|
1998
|
-
await
|
|
2088
|
+
await this.#messageManager.deleteScheduledMessage(chatId, messageId);
|
|
1999
2089
|
}
|
|
2000
2090
|
/**
|
|
2001
2091
|
* Send multiple scheduled messages before their schedule.
|
|
@@ -2005,7 +2095,7 @@ export class Client extends Composer {
|
|
|
2005
2095
|
* @param messageIds The identifiers of the scheduled messages to send.
|
|
2006
2096
|
*/
|
|
2007
2097
|
async sendScheduledMessages(chatId, messageIds) {
|
|
2008
|
-
return await
|
|
2098
|
+
return await this.#messageManager.sendScheduledMessages(chatId, messageIds);
|
|
2009
2099
|
}
|
|
2010
2100
|
/**
|
|
2011
2101
|
* Send a scheduled message before its schedule.
|
|
@@ -2015,7 +2105,7 @@ export class Client extends Composer {
|
|
|
2015
2105
|
* @param messageId The identifier of the scheduled message to send.
|
|
2016
2106
|
*/
|
|
2017
2107
|
async sendScheduledMessage(chatId, messageId) {
|
|
2018
|
-
return await
|
|
2108
|
+
return await this.#messageManager.sendScheduledMessage(chatId, messageId);
|
|
2019
2109
|
}
|
|
2020
2110
|
/**
|
|
2021
2111
|
* Pin a message in a chat.
|
|
@@ -2025,7 +2115,7 @@ export class Client extends Composer {
|
|
|
2025
2115
|
* @param messageId The identifier of the message.
|
|
2026
2116
|
*/
|
|
2027
2117
|
async pinMessage(chatId, messageId, params) {
|
|
2028
|
-
await
|
|
2118
|
+
await this.#messageManager.pinMessage(chatId, messageId, params);
|
|
2029
2119
|
}
|
|
2030
2120
|
/**
|
|
2031
2121
|
* Unpin a pinned message.
|
|
@@ -2035,7 +2125,7 @@ export class Client extends Composer {
|
|
|
2035
2125
|
* @param messageId The identifier of the message.
|
|
2036
2126
|
*/
|
|
2037
2127
|
async unpinMessage(chatId, messageId, params) {
|
|
2038
|
-
await
|
|
2128
|
+
await this.#messageManager.unpinMessage(chatId, messageId, params);
|
|
2039
2129
|
}
|
|
2040
2130
|
/**
|
|
2041
2131
|
* Unpin all pinned messages.
|
|
@@ -2044,7 +2134,7 @@ export class Client extends Composer {
|
|
|
2044
2134
|
* @param chatId The identifier of a chat.
|
|
2045
2135
|
*/
|
|
2046
2136
|
async unpinMessages(chatId) {
|
|
2047
|
-
await
|
|
2137
|
+
await this.#messageManager.unpinMessages(chatId);
|
|
2048
2138
|
}
|
|
2049
2139
|
/**
|
|
2050
2140
|
* Forward multiple messages.
|
|
@@ -2056,7 +2146,7 @@ export class Client extends Composer {
|
|
|
2056
2146
|
* @returns The forwarded messages.
|
|
2057
2147
|
*/
|
|
2058
2148
|
async forwardMessages(from, to, messageIds, params) {
|
|
2059
|
-
return await
|
|
2149
|
+
return await this.#messageManager.forwardMessages(from, to, messageIds, params);
|
|
2060
2150
|
}
|
|
2061
2151
|
/**
|
|
2062
2152
|
* Forward a single message.
|
|
@@ -2079,7 +2169,7 @@ export class Client extends Composer {
|
|
|
2079
2169
|
* @returns The new state of the poll.
|
|
2080
2170
|
*/
|
|
2081
2171
|
async stopPoll(chatId, messageId, params) {
|
|
2082
|
-
return await
|
|
2172
|
+
return await this.#messageManager.stopPoll(chatId, messageId, params);
|
|
2083
2173
|
}
|
|
2084
2174
|
/**
|
|
2085
2175
|
* Send a chat action.
|
|
@@ -2090,7 +2180,7 @@ export class Client extends Composer {
|
|
|
2090
2180
|
* @param messageThreadId The thread to send the chat action to.
|
|
2091
2181
|
*/
|
|
2092
2182
|
async sendChatAction(chatId, action, params) {
|
|
2093
|
-
await
|
|
2183
|
+
await this.#messageManager.sendChatAction(chatId, action, params);
|
|
2094
2184
|
}
|
|
2095
2185
|
/**
|
|
2096
2186
|
* Search the messages of a chat. User-only.
|
|
@@ -2100,7 +2190,7 @@ export class Client extends Composer {
|
|
|
2100
2190
|
* @param query The message search query.
|
|
2101
2191
|
*/
|
|
2102
2192
|
async searchMessages(chatId, query, params) {
|
|
2103
|
-
return await
|
|
2193
|
+
return await this.#messageManager.searchMessages(chatId, query, params);
|
|
2104
2194
|
}
|
|
2105
2195
|
/**
|
|
2106
2196
|
* Mark messages as read. User-only.
|
|
@@ -2110,7 +2200,7 @@ export class Client extends Composer {
|
|
|
2110
2200
|
* @param untilMessageId The identifier of the message that will be marked as read, along with any other unread messages before it.
|
|
2111
2201
|
*/
|
|
2112
2202
|
async readMessages(chatId, untilMessageId) {
|
|
2113
|
-
await
|
|
2203
|
+
await this.#messageManager.readMessages(chatId, untilMessageId);
|
|
2114
2204
|
}
|
|
2115
2205
|
/**
|
|
2116
2206
|
* Start a bot. User-only.
|
|
@@ -2120,7 +2210,7 @@ export class Client extends Composer {
|
|
|
2120
2210
|
* @returns The start message.
|
|
2121
2211
|
*/
|
|
2122
2212
|
async startBot(botId, params) {
|
|
2123
|
-
return await
|
|
2213
|
+
return await this.#messageManager.startBot(botId, params);
|
|
2124
2214
|
}
|
|
2125
2215
|
/**
|
|
2126
2216
|
* Transcribe a voice message. User-only.
|
|
@@ -2131,7 +2221,7 @@ export class Client extends Composer {
|
|
|
2131
2221
|
* @cache
|
|
2132
2222
|
*/
|
|
2133
2223
|
async transcribeVoice(chatId, messageId) {
|
|
2134
|
-
return await
|
|
2224
|
+
return await this.#messageManager.transcribeVoice(chatId, messageId);
|
|
2135
2225
|
}
|
|
2136
2226
|
/**
|
|
2137
2227
|
* Get the link preview for a message that is about to be sent. User-only.
|
|
@@ -2140,7 +2230,7 @@ export class Client extends Composer {
|
|
|
2140
2230
|
* @param text The message's text.
|
|
2141
2231
|
*/
|
|
2142
2232
|
async getLinkPreview(text, params) {
|
|
2143
|
-
return await
|
|
2233
|
+
return await this.#linkPreviewManager.getLinkPreview(text, params);
|
|
2144
2234
|
}
|
|
2145
2235
|
/**
|
|
2146
2236
|
* Open a mini app. User-only.
|
|
@@ -2151,7 +2241,16 @@ export class Client extends Composer {
|
|
|
2151
2241
|
* @cache
|
|
2152
2242
|
*/
|
|
2153
2243
|
async openMiniApp(botId, chatId, params) {
|
|
2154
|
-
return await
|
|
2244
|
+
return await this.#messageManager.openMiniApp(botId, chatId, params);
|
|
2245
|
+
}
|
|
2246
|
+
/**
|
|
2247
|
+
* Get a progress ID that can be passed to relevant send* methods to receive upload progress updates for them.
|
|
2248
|
+
*
|
|
2249
|
+
* @method ms
|
|
2250
|
+
* @cache
|
|
2251
|
+
*/
|
|
2252
|
+
async getProgressId() {
|
|
2253
|
+
return await this.#fileManager.getProgressId();
|
|
2155
2254
|
}
|
|
2156
2255
|
//
|
|
2157
2256
|
// ========================= POLLS ========================= //
|
|
@@ -2165,7 +2264,7 @@ export class Client extends Composer {
|
|
|
2165
2264
|
* @param optionIndexes The indexes of the options to cast for.
|
|
2166
2265
|
*/
|
|
2167
2266
|
async vote(chatId, messageId, optionIndexes) {
|
|
2168
|
-
await
|
|
2267
|
+
await this.#pollManager.vote(chatId, messageId, optionIndexes);
|
|
2169
2268
|
}
|
|
2170
2269
|
/**
|
|
2171
2270
|
* Retract a vote. User-only.
|
|
@@ -2175,7 +2274,7 @@ export class Client extends Composer {
|
|
|
2175
2274
|
* @param messageId The identifier of the message that includes the poll.
|
|
2176
2275
|
*/
|
|
2177
2276
|
async retractVote(chatId, messageId) {
|
|
2178
|
-
await
|
|
2277
|
+
await this.#pollManager.retractVote(chatId, messageId);
|
|
2179
2278
|
}
|
|
2180
2279
|
//
|
|
2181
2280
|
// ========================= FILES ========================= //
|
|
@@ -2194,7 +2293,7 @@ export class Client extends Composer {
|
|
|
2194
2293
|
* @cache file
|
|
2195
2294
|
*/
|
|
2196
2295
|
async *download(fileId, params) {
|
|
2197
|
-
for await (const chunk of
|
|
2296
|
+
for await (const chunk of this.#fileManager.download(fileId, params)) {
|
|
2198
2297
|
yield chunk;
|
|
2199
2298
|
}
|
|
2200
2299
|
}
|
|
@@ -2207,7 +2306,7 @@ export class Client extends Composer {
|
|
|
2207
2306
|
* @cache
|
|
2208
2307
|
*/
|
|
2209
2308
|
async getCustomEmojiStickers(id) {
|
|
2210
|
-
return await
|
|
2309
|
+
return await this.#fileManager.getCustomEmojiStickers(id);
|
|
2211
2310
|
}
|
|
2212
2311
|
//
|
|
2213
2312
|
// ========================= CHATS ========================= //
|
|
@@ -2218,7 +2317,7 @@ export class Client extends Composer {
|
|
|
2218
2317
|
* @method ch
|
|
2219
2318
|
*/
|
|
2220
2319
|
async getChats(params) {
|
|
2221
|
-
return await
|
|
2320
|
+
return await this.#chatListManager.getChats(params?.from, params?.after, params?.limit);
|
|
2222
2321
|
}
|
|
2223
2322
|
/**
|
|
2224
2323
|
* Get a chat.
|
|
@@ -2227,7 +2326,7 @@ export class Client extends Composer {
|
|
|
2227
2326
|
* @cache
|
|
2228
2327
|
*/
|
|
2229
2328
|
async getChat(chatId) {
|
|
2230
|
-
return await
|
|
2329
|
+
return await this.#chatListManager.getChat(chatId);
|
|
2231
2330
|
}
|
|
2232
2331
|
/**
|
|
2233
2332
|
* Get chat history. User-only.
|
|
@@ -2236,7 +2335,7 @@ export class Client extends Composer {
|
|
|
2236
2335
|
* @param chatId The identifier of a chat.
|
|
2237
2336
|
*/
|
|
2238
2337
|
async getHistory(chatId, params) {
|
|
2239
|
-
return await
|
|
2338
|
+
return await this.#messageManager.getHistory(chatId, params);
|
|
2240
2339
|
}
|
|
2241
2340
|
/**
|
|
2242
2341
|
* Set a chat's available reactions. User-only.
|
|
@@ -2246,7 +2345,7 @@ export class Client extends Composer {
|
|
|
2246
2345
|
* @param availableReactions The new available reactions.
|
|
2247
2346
|
*/
|
|
2248
2347
|
async setAvailableReactions(chatId, availableReactions) {
|
|
2249
|
-
await
|
|
2348
|
+
await this.#chatManager.setAvailableReactions(chatId, availableReactions);
|
|
2250
2349
|
}
|
|
2251
2350
|
/**
|
|
2252
2351
|
* Set a chat's photo.
|
|
@@ -2256,7 +2355,7 @@ export class Client extends Composer {
|
|
|
2256
2355
|
* @param photo A photo to set as the chat's photo.
|
|
2257
2356
|
*/
|
|
2258
2357
|
async setChatPhoto(chatId, photo, params) {
|
|
2259
|
-
await
|
|
2358
|
+
await this.#chatManager.setChatPhoto(chatId, photo, params);
|
|
2260
2359
|
}
|
|
2261
2360
|
/**
|
|
2262
2361
|
* Delete a chat's photo.
|
|
@@ -2265,7 +2364,7 @@ export class Client extends Composer {
|
|
|
2265
2364
|
* @param chatId The identifier of a chat.
|
|
2266
2365
|
*/
|
|
2267
2366
|
async deleteChatPhoto(chatId) {
|
|
2268
|
-
await
|
|
2367
|
+
await this.#chatManager.deleteChatPhoto(chatId);
|
|
2269
2368
|
}
|
|
2270
2369
|
/**
|
|
2271
2370
|
* Ban a member from a chat.
|
|
@@ -2275,7 +2374,7 @@ export class Client extends Composer {
|
|
|
2275
2374
|
* @param memberId The identifier of the member.
|
|
2276
2375
|
*/
|
|
2277
2376
|
async banChatMember(chatId, memberId, params) {
|
|
2278
|
-
await
|
|
2377
|
+
await this.#chatManager.banChatMember(chatId, memberId, params);
|
|
2279
2378
|
}
|
|
2280
2379
|
/**
|
|
2281
2380
|
* Unban a member from a chat.
|
|
@@ -2285,7 +2384,7 @@ export class Client extends Composer {
|
|
|
2285
2384
|
* @param memberId The identifier of the member.
|
|
2286
2385
|
*/
|
|
2287
2386
|
async unbanChatMember(chatId, memberId) {
|
|
2288
|
-
await
|
|
2387
|
+
await this.#chatManager.unbanChatMember(chatId, memberId);
|
|
2289
2388
|
}
|
|
2290
2389
|
/**
|
|
2291
2390
|
* Kick a member from a chat. Same as a banChatMember call followed by unbanChatMember.
|
|
@@ -2295,8 +2394,8 @@ export class Client extends Composer {
|
|
|
2295
2394
|
* @param memberId The identifier of the member.
|
|
2296
2395
|
*/
|
|
2297
2396
|
async kickChatMember(chatId, memberId) {
|
|
2298
|
-
await
|
|
2299
|
-
await
|
|
2397
|
+
await this.#chatManager.banChatMember(chatId, memberId);
|
|
2398
|
+
await this.#chatManager.unbanChatMember(chatId, memberId);
|
|
2300
2399
|
}
|
|
2301
2400
|
/**
|
|
2302
2401
|
* Set the rights of a chat member.
|
|
@@ -2306,7 +2405,7 @@ export class Client extends Composer {
|
|
|
2306
2405
|
* @param memberId The identifier of the member.
|
|
2307
2406
|
*/
|
|
2308
2407
|
async setChatMemberRights(chatId, memberId, params) {
|
|
2309
|
-
await
|
|
2408
|
+
await this.#chatManager.setChatMemberRights(chatId, memberId, params);
|
|
2310
2409
|
}
|
|
2311
2410
|
/**
|
|
2312
2411
|
* Get the administrators of a chat.
|
|
@@ -2316,7 +2415,7 @@ export class Client extends Composer {
|
|
|
2316
2415
|
* @returns The chat's administrators.
|
|
2317
2416
|
*/
|
|
2318
2417
|
async getChatAdministrators(chatId) {
|
|
2319
|
-
return await
|
|
2418
|
+
return await this.#chatListManager.getChatAdministrators(chatId);
|
|
2320
2419
|
}
|
|
2321
2420
|
/**
|
|
2322
2421
|
* Enable join requests in a chat. User-only.
|
|
@@ -2325,7 +2424,7 @@ export class Client extends Composer {
|
|
|
2325
2424
|
* @param chatId The identifier of a chat. Must be a channel or a supergroup.
|
|
2326
2425
|
*/
|
|
2327
2426
|
async enableJoinRequests(chatId) {
|
|
2328
|
-
await
|
|
2427
|
+
await this.#chatManager.enableJoinRequests(chatId);
|
|
2329
2428
|
}
|
|
2330
2429
|
/**
|
|
2331
2430
|
* Disable join requests in a chat. User-only.
|
|
@@ -2334,7 +2433,7 @@ export class Client extends Composer {
|
|
|
2334
2433
|
* @param chatId The identifier of a chat. Must be a channel or a supergroup.
|
|
2335
2434
|
*/
|
|
2336
2435
|
async disableJoinRequests(chatId) {
|
|
2337
|
-
await
|
|
2436
|
+
await this.#chatManager.disableJoinRequests(chatId);
|
|
2338
2437
|
}
|
|
2339
2438
|
/**
|
|
2340
2439
|
* Get inactive chats. User-only.
|
|
@@ -2343,7 +2442,7 @@ export class Client extends Composer {
|
|
|
2343
2442
|
* @retuns A list of inactive chats the current user is member of.
|
|
2344
2443
|
*/
|
|
2345
2444
|
async getInactiveChats() {
|
|
2346
|
-
return await
|
|
2445
|
+
return await this.#accountManager.getInactiveChats();
|
|
2347
2446
|
}
|
|
2348
2447
|
/**
|
|
2349
2448
|
* Get the invite links created for a chat. User-only.
|
|
@@ -2353,7 +2452,7 @@ export class Client extends Composer {
|
|
|
2353
2452
|
* @returns The invite links created for the chat. This might be a subset of the results if they were less than `limit`. The parameters `afterDate` and `afterInviteLink` can be used for pagination.
|
|
2354
2453
|
*/
|
|
2355
2454
|
async getCreatedInviteLinks(chatId, params) {
|
|
2356
|
-
return await
|
|
2455
|
+
return await this.#chatManager.getCreatedInviteLinks(chatId, params);
|
|
2357
2456
|
}
|
|
2358
2457
|
/**
|
|
2359
2458
|
* Join a chat. User-only.
|
|
@@ -2362,7 +2461,7 @@ export class Client extends Composer {
|
|
|
2362
2461
|
* @param chatId The identifier of a chat.
|
|
2363
2462
|
*/
|
|
2364
2463
|
async joinChat(chatId) {
|
|
2365
|
-
await
|
|
2464
|
+
await this.#chatManager.joinChat(chatId);
|
|
2366
2465
|
}
|
|
2367
2466
|
/**
|
|
2368
2467
|
* Leave a chat.
|
|
@@ -2371,7 +2470,7 @@ export class Client extends Composer {
|
|
|
2371
2470
|
* @param chatId The identifier of a chat.
|
|
2372
2471
|
*/
|
|
2373
2472
|
async leaveChat(chatId) {
|
|
2374
|
-
await
|
|
2473
|
+
await this.#chatManager.leaveChat(chatId);
|
|
2375
2474
|
}
|
|
2376
2475
|
/**
|
|
2377
2476
|
* Get information on a user's chat membership.
|
|
@@ -2381,7 +2480,7 @@ export class Client extends Composer {
|
|
|
2381
2480
|
* @param userId The identifier of the user.
|
|
2382
2481
|
*/
|
|
2383
2482
|
async getChatMember(chatId, userId) {
|
|
2384
|
-
return await
|
|
2483
|
+
return await this.#chatListManager.getChatMember(chatId, userId);
|
|
2385
2484
|
}
|
|
2386
2485
|
/**
|
|
2387
2486
|
* Get the members of a chat.
|
|
@@ -2390,7 +2489,7 @@ export class Client extends Composer {
|
|
|
2390
2489
|
* @param chatId The identifier of a chat.
|
|
2391
2490
|
*/
|
|
2392
2491
|
async getChatMembers(chatId, params) {
|
|
2393
|
-
return await
|
|
2492
|
+
return await this.#chatListManager.getChatMembers(chatId, params);
|
|
2394
2493
|
}
|
|
2395
2494
|
/**
|
|
2396
2495
|
* Set a chat's sticker set.
|
|
@@ -2400,7 +2499,7 @@ export class Client extends Composer {
|
|
|
2400
2499
|
* @param setName The name of the set.
|
|
2401
2500
|
*/
|
|
2402
2501
|
async setChatStickerSet(chatId, setName) {
|
|
2403
|
-
await
|
|
2502
|
+
await this.#messageManager.setChatStickerSet(chatId, setName);
|
|
2404
2503
|
}
|
|
2405
2504
|
/**
|
|
2406
2505
|
* Delete a chat's sticker set.
|
|
@@ -2409,7 +2508,7 @@ export class Client extends Composer {
|
|
|
2409
2508
|
* @param chatId The identifier of a chat. Must be a supergroup.
|
|
2410
2509
|
*/
|
|
2411
2510
|
async deleteChatStickerSet(chatId) {
|
|
2412
|
-
await
|
|
2511
|
+
await this.#messageManager.deleteChatStickerSet(chatId);
|
|
2413
2512
|
}
|
|
2414
2513
|
/**
|
|
2415
2514
|
* Set the number of boosts required to circument a chat's default restrictions. User-only.
|
|
@@ -2419,7 +2518,7 @@ export class Client extends Composer {
|
|
|
2419
2518
|
* @param boosts The number of boosts required to circumvent its restrictions.
|
|
2420
2519
|
*/
|
|
2421
2520
|
async setBoostsRequiredToCircumventRestrictions(chatId, boosts) {
|
|
2422
|
-
await
|
|
2521
|
+
await this.#chatManager.setBoostsRequiredToCircumventRestrictions(chatId, boosts);
|
|
2423
2522
|
}
|
|
2424
2523
|
/**
|
|
2425
2524
|
* Create an invite link.
|
|
@@ -2429,7 +2528,7 @@ export class Client extends Composer {
|
|
|
2429
2528
|
* @returns The newly created invite link.
|
|
2430
2529
|
*/
|
|
2431
2530
|
async createInviteLink(chatId, params) {
|
|
2432
|
-
return await
|
|
2531
|
+
return await this.#chatManager.createInviteLink(chatId, params);
|
|
2433
2532
|
}
|
|
2434
2533
|
/**
|
|
2435
2534
|
* Approve a join request.
|
|
@@ -2439,7 +2538,7 @@ export class Client extends Composer {
|
|
|
2439
2538
|
* @param userId The user who made the join request.
|
|
2440
2539
|
*/
|
|
2441
2540
|
async approveJoinRequest(chatId, userId) {
|
|
2442
|
-
await
|
|
2541
|
+
await this.#chatManager.approveJoinRequest(chatId, userId);
|
|
2443
2542
|
}
|
|
2444
2543
|
/**
|
|
2445
2544
|
* Decline a join request.
|
|
@@ -2449,7 +2548,7 @@ export class Client extends Composer {
|
|
|
2449
2548
|
* @param userId The user who made the join request.
|
|
2450
2549
|
*/
|
|
2451
2550
|
async declineJoinRequest(chatId, userId) {
|
|
2452
|
-
await
|
|
2551
|
+
await this.#chatManager.declineJoinRequest(chatId, userId);
|
|
2453
2552
|
}
|
|
2454
2553
|
/**
|
|
2455
2554
|
* Approve all join requests. User-only.
|
|
@@ -2458,7 +2557,7 @@ export class Client extends Composer {
|
|
|
2458
2557
|
* @param chatId The identifier of a chat with the join requests.
|
|
2459
2558
|
*/
|
|
2460
2559
|
async approveJoinRequests(chatId, params) {
|
|
2461
|
-
await
|
|
2560
|
+
await this.#chatManager.approveJoinRequests(chatId, params);
|
|
2462
2561
|
}
|
|
2463
2562
|
/**
|
|
2464
2563
|
* Decline all join requests. User-only.
|
|
@@ -2467,7 +2566,7 @@ export class Client extends Composer {
|
|
|
2467
2566
|
* @param chatId The identifier of a chat with the join requests.
|
|
2468
2567
|
*/
|
|
2469
2568
|
async declineJoinRequests(chatId, params) {
|
|
2470
|
-
await
|
|
2569
|
+
await this.#chatManager.declineJoinRequests(chatId, params);
|
|
2471
2570
|
}
|
|
2472
2571
|
/**
|
|
2473
2572
|
* Get pending join requests in a chat. User-only.
|
|
@@ -2476,7 +2575,7 @@ export class Client extends Composer {
|
|
|
2476
2575
|
* @param chatId The identifier of a chat with the join requests.
|
|
2477
2576
|
*/
|
|
2478
2577
|
async getJoinRequests(chatId, params) {
|
|
2479
|
-
return await
|
|
2578
|
+
return await this.#chatManager.getJoinRequests(chatId, params);
|
|
2480
2579
|
}
|
|
2481
2580
|
/**
|
|
2482
2581
|
* Add a single user to a chat.
|
|
@@ -2487,7 +2586,7 @@ export class Client extends Composer {
|
|
|
2487
2586
|
* @returns An array of FailedInvitation that has at most a length of 1. If empty, it means that the user was added.
|
|
2488
2587
|
*/
|
|
2489
2588
|
async addChatMember(chatId, userId, params) {
|
|
2490
|
-
return await
|
|
2589
|
+
return await this.#chatManager.addChatMember(chatId, userId, params);
|
|
2491
2590
|
}
|
|
2492
2591
|
/**
|
|
2493
2592
|
* Add multiple users at once to a channel or a supergroup.
|
|
@@ -2497,7 +2596,7 @@ export class Client extends Composer {
|
|
|
2497
2596
|
* @param userId The identifiers of the users to add to the channel or supergroup.
|
|
2498
2597
|
*/
|
|
2499
2598
|
async addChatMembers(chatId, userIds) {
|
|
2500
|
-
return await
|
|
2599
|
+
return await this.#chatManager.addChatMembers(chatId, userIds);
|
|
2501
2600
|
}
|
|
2502
2601
|
/**
|
|
2503
2602
|
* Open a chat.
|
|
@@ -2506,7 +2605,7 @@ export class Client extends Composer {
|
|
|
2506
2605
|
* @param chatId The identifier of a chat to open.
|
|
2507
2606
|
*/
|
|
2508
2607
|
async openChat(chatId) {
|
|
2509
|
-
await
|
|
2608
|
+
await this.#updateManager.openChat(chatId);
|
|
2510
2609
|
}
|
|
2511
2610
|
/**
|
|
2512
2611
|
* Close a chat previously opened by openChat.
|
|
@@ -2515,7 +2614,7 @@ export class Client extends Composer {
|
|
|
2515
2614
|
* @param chatId The identifier of a chat to close.
|
|
2516
2615
|
*/
|
|
2517
2616
|
async closeChat(chatId) {
|
|
2518
|
-
await
|
|
2617
|
+
await this.#updateManager.closeChat(chatId);
|
|
2519
2618
|
}
|
|
2520
2619
|
/**
|
|
2521
2620
|
* Create a group. User-only.
|
|
@@ -2525,7 +2624,7 @@ export class Client extends Composer {
|
|
|
2525
2624
|
* @returns The created group.
|
|
2526
2625
|
*/
|
|
2527
2626
|
async createGroup(title, params) {
|
|
2528
|
-
return await
|
|
2627
|
+
return await this.#chatListManager.createGroup(title, params);
|
|
2529
2628
|
}
|
|
2530
2629
|
/**
|
|
2531
2630
|
* Create a supergroup. User-only.
|
|
@@ -2535,7 +2634,7 @@ export class Client extends Composer {
|
|
|
2535
2634
|
* @returns The created supergroup.
|
|
2536
2635
|
*/
|
|
2537
2636
|
async createSupergroup(title, params) {
|
|
2538
|
-
return await
|
|
2637
|
+
return await this.#chatListManager.createSupergroup(title, params);
|
|
2539
2638
|
}
|
|
2540
2639
|
/**
|
|
2541
2640
|
* Create a channel. User-only.
|
|
@@ -2545,7 +2644,7 @@ export class Client extends Composer {
|
|
|
2545
2644
|
* @returns The created channel.
|
|
2546
2645
|
*/
|
|
2547
2646
|
async createChannel(title, params) {
|
|
2548
|
-
return await
|
|
2647
|
+
return await this.#chatListManager.createChannel(title, params);
|
|
2549
2648
|
}
|
|
2550
2649
|
/**
|
|
2551
2650
|
* Set the time to live of the messages of a chat. User-only.
|
|
@@ -2555,7 +2654,7 @@ export class Client extends Composer {
|
|
|
2555
2654
|
* @param messageTtl The time to live of the messages in seconds.
|
|
2556
2655
|
*/
|
|
2557
2656
|
async setMessageTtl(chatId, messageTtl) {
|
|
2558
|
-
await
|
|
2657
|
+
await this.#chatListManager.setMessageTtl(chatId, messageTtl);
|
|
2559
2658
|
}
|
|
2560
2659
|
/**
|
|
2561
2660
|
* Archive multiple chats. User-only.
|
|
@@ -2564,7 +2663,7 @@ export class Client extends Composer {
|
|
|
2564
2663
|
* @param chatIds The identifiers of the chats to archive.
|
|
2565
2664
|
*/
|
|
2566
2665
|
async archiveChats(chatIds) {
|
|
2567
|
-
await
|
|
2666
|
+
await this.#chatListManager.archiveChats(chatIds);
|
|
2568
2667
|
}
|
|
2569
2668
|
/**
|
|
2570
2669
|
* Archive a single chat. User-only.
|
|
@@ -2573,7 +2672,7 @@ export class Client extends Composer {
|
|
|
2573
2672
|
* @param chatId The identifier of a chat.
|
|
2574
2673
|
*/
|
|
2575
2674
|
async archiveChat(chatId) {
|
|
2576
|
-
await
|
|
2675
|
+
await this.#chatListManager.archiveChat(chatId);
|
|
2577
2676
|
}
|
|
2578
2677
|
/**
|
|
2579
2678
|
* Unarchive multiple chats. User-only.
|
|
@@ -2582,7 +2681,7 @@ export class Client extends Composer {
|
|
|
2582
2681
|
* @param chatIds The identifiers of the chats to unarchive.
|
|
2583
2682
|
*/
|
|
2584
2683
|
async unarchiveChats(chatIds) {
|
|
2585
|
-
await
|
|
2684
|
+
await this.#chatListManager.unarchiveChats(chatIds);
|
|
2586
2685
|
}
|
|
2587
2686
|
/**
|
|
2588
2687
|
* Unarchive a single chat. User-only.
|
|
@@ -2591,7 +2690,7 @@ export class Client extends Composer {
|
|
|
2591
2690
|
* @param chatId The identifier of a chat.
|
|
2592
2691
|
*/
|
|
2593
2692
|
async unarchiveChat(chatId) {
|
|
2594
|
-
await
|
|
2693
|
+
await this.#chatListManager.unarchiveChat(chatId);
|
|
2595
2694
|
}
|
|
2596
2695
|
/**
|
|
2597
2696
|
* Get common chats between a user and the current one. User-only.
|
|
@@ -2600,7 +2699,7 @@ export class Client extends Composer {
|
|
|
2600
2699
|
* @param userId The identifier of the user to get the common chats with them.
|
|
2601
2700
|
*/
|
|
2602
2701
|
async getCommonChats(userId, params) {
|
|
2603
|
-
return await
|
|
2702
|
+
return await this.#chatListManager.getCommonChats(userId, params);
|
|
2604
2703
|
}
|
|
2605
2704
|
/**
|
|
2606
2705
|
* Get the settings of a chat. User-only.
|
|
@@ -2609,7 +2708,7 @@ export class Client extends Composer {
|
|
|
2609
2708
|
* @param chatId The identifier of a chat.
|
|
2610
2709
|
*/
|
|
2611
2710
|
async getChatSettings(chatId) {
|
|
2612
|
-
return await
|
|
2711
|
+
return await this.#chatListManager.getChatSettings(chatId);
|
|
2613
2712
|
}
|
|
2614
2713
|
/**
|
|
2615
2714
|
* Disable business bots in a private chat. User-only.
|
|
@@ -2618,7 +2717,7 @@ export class Client extends Composer {
|
|
|
2618
2717
|
* @param chatId The identifier of the private chat to disable business bots in.
|
|
2619
2718
|
*/
|
|
2620
2719
|
async disableBusinessBots(chatId) {
|
|
2621
|
-
await
|
|
2720
|
+
await this.#chatListManager.disableBusinessBots(chatId);
|
|
2622
2721
|
}
|
|
2623
2722
|
/**
|
|
2624
2723
|
* Enable business bots in a private chat. User-only.
|
|
@@ -2627,7 +2726,7 @@ export class Client extends Composer {
|
|
|
2627
2726
|
* @param chatId The identifier of the private chat to enable business bots in.
|
|
2628
2727
|
*/
|
|
2629
2728
|
async enableBusinessBots(chatId) {
|
|
2630
|
-
await
|
|
2729
|
+
await this.#chatListManager.enableBusinessBots(chatId);
|
|
2631
2730
|
}
|
|
2632
2731
|
/**
|
|
2633
2732
|
* Disable slow mode in a group. User-only.
|
|
@@ -2636,7 +2735,7 @@ export class Client extends Composer {
|
|
|
2636
2735
|
* @param chatId The identifier of the group to disable slow mode in.
|
|
2637
2736
|
*/
|
|
2638
2737
|
async disableSlowMode(chatId) {
|
|
2639
|
-
await
|
|
2738
|
+
await this.#chatManager.disableSlowMode(chatId);
|
|
2640
2739
|
}
|
|
2641
2740
|
/**
|
|
2642
2741
|
* Change slow mode in a group. User-only.
|
|
@@ -2646,7 +2745,7 @@ export class Client extends Composer {
|
|
|
2646
2745
|
* @param duration New slow mode duration.
|
|
2647
2746
|
*/
|
|
2648
2747
|
async setSlowMode(chatId, duration) {
|
|
2649
|
-
await
|
|
2748
|
+
await this.#chatManager.setSlowMode(chatId, duration);
|
|
2650
2749
|
}
|
|
2651
2750
|
/**
|
|
2652
2751
|
* Change the title of a chat.
|
|
@@ -2656,7 +2755,7 @@ export class Client extends Composer {
|
|
|
2656
2755
|
* @param title The new title.
|
|
2657
2756
|
*/
|
|
2658
2757
|
async setChatTitle(chatId, title) {
|
|
2659
|
-
await
|
|
2758
|
+
await this.#chatManager.setChatTitle(chatId, title);
|
|
2660
2759
|
}
|
|
2661
2760
|
/**
|
|
2662
2761
|
* Change the description of a chat.
|
|
@@ -2666,7 +2765,7 @@ export class Client extends Composer {
|
|
|
2666
2765
|
* @param description The new description.
|
|
2667
2766
|
*/
|
|
2668
2767
|
async setChatDescription(chatId, description) {
|
|
2669
|
-
await
|
|
2768
|
+
await this.#chatManager.setChatDescription(chatId, description);
|
|
2670
2769
|
}
|
|
2671
2770
|
/**
|
|
2672
2771
|
* Hide or show the member list of a group to non-admins. User-only.
|
|
@@ -2676,7 +2775,7 @@ export class Client extends Composer {
|
|
|
2676
2775
|
* @param visible Whether the member list of the group should be visible.
|
|
2677
2776
|
*/
|
|
2678
2777
|
async setMemberListVisibility(chatId, visible) {
|
|
2679
|
-
await
|
|
2778
|
+
await this.#chatManager.setMemberListVisibility(chatId, visible);
|
|
2680
2779
|
}
|
|
2681
2780
|
/**
|
|
2682
2781
|
* Enable or disable topics in a group. User-only.
|
|
@@ -2686,7 +2785,7 @@ export class Client extends Composer {
|
|
|
2686
2785
|
* @param enabled Whether topics should be enabled in the group.
|
|
2687
2786
|
*/
|
|
2688
2787
|
async setTopicsEnabled(chatId, enabled) {
|
|
2689
|
-
await
|
|
2788
|
+
await this.#chatManager.setTopicsEnabled(chatId, enabled);
|
|
2690
2789
|
}
|
|
2691
2790
|
/**
|
|
2692
2791
|
* Enable or disable automatic anti-spam in a group. User-only.
|
|
@@ -2696,7 +2795,7 @@ export class Client extends Composer {
|
|
|
2696
2795
|
* @param enabled Whether automatic anti-spam should be enabled in the group.
|
|
2697
2796
|
*/
|
|
2698
2797
|
async setAntispamEnabled(chatId, enabled) {
|
|
2699
|
-
await
|
|
2798
|
+
await this.#chatManager.setAntispamEnabled(chatId, enabled);
|
|
2700
2799
|
}
|
|
2701
2800
|
/**
|
|
2702
2801
|
* Enable or disable post signatures in a channel. User-only.
|
|
@@ -2706,7 +2805,7 @@ export class Client extends Composer {
|
|
|
2706
2805
|
* @param enabled Whether post signatures should be enabled in the channel.
|
|
2707
2806
|
*/
|
|
2708
2807
|
async setSignaturesEnabled(chatId, enabled, params) {
|
|
2709
|
-
await
|
|
2808
|
+
await this.#chatManager.setSignaturesEnabled(chatId, enabled, params);
|
|
2710
2809
|
}
|
|
2711
2810
|
/**
|
|
2712
2811
|
* Delete a chat. User-only.
|
|
@@ -2715,7 +2814,7 @@ export class Client extends Composer {
|
|
|
2715
2814
|
* @param chatId The identifier of a chat.
|
|
2716
2815
|
*/
|
|
2717
2816
|
async deleteChat(chatId) {
|
|
2718
|
-
await
|
|
2817
|
+
await this.#chatManager.deleteChat(chatId);
|
|
2719
2818
|
}
|
|
2720
2819
|
/**
|
|
2721
2820
|
* Get discussion chat suggestions. User-only.
|
|
@@ -2723,7 +2822,7 @@ export class Client extends Composer {
|
|
|
2723
2822
|
* @method ch
|
|
2724
2823
|
*/
|
|
2725
2824
|
async getDiscussionChatSuggestions() {
|
|
2726
|
-
return await
|
|
2825
|
+
return await this.#chatManager.getDiscussionChatSuggestions();
|
|
2727
2826
|
}
|
|
2728
2827
|
/**
|
|
2729
2828
|
* Set a channel's discussion chat. User-only.
|
|
@@ -2733,7 +2832,7 @@ export class Client extends Composer {
|
|
|
2733
2832
|
* @param discussionChatId The identifier of a chat to use as discussion for the channel.
|
|
2734
2833
|
*/
|
|
2735
2834
|
async setDiscussionChat(chatId, discussionChatId) {
|
|
2736
|
-
await
|
|
2835
|
+
await this.#chatManager.setDiscussionChat(chatId, discussionChatId);
|
|
2737
2836
|
}
|
|
2738
2837
|
/**
|
|
2739
2838
|
* Transfer the ownership of a chat. User-only.
|
|
@@ -2744,7 +2843,7 @@ export class Client extends Composer {
|
|
|
2744
2843
|
* @param password The password of the current account.
|
|
2745
2844
|
*/
|
|
2746
2845
|
async transferChatOwnership(chatId, userId, password) {
|
|
2747
|
-
await
|
|
2846
|
+
await this.#chatManager.transferChatOwnership(chatId, userId, password);
|
|
2748
2847
|
}
|
|
2749
2848
|
/**
|
|
2750
2849
|
* Create a forum topic.
|
|
@@ -2755,7 +2854,7 @@ export class Client extends Composer {
|
|
|
2755
2854
|
* @returns The created topic.
|
|
2756
2855
|
*/
|
|
2757
2856
|
async createTopic(chatId, title, params) {
|
|
2758
|
-
return await
|
|
2857
|
+
return await this.#forumManager.createTopic(chatId, title, params);
|
|
2759
2858
|
}
|
|
2760
2859
|
/**
|
|
2761
2860
|
* Edit a forum topic.
|
|
@@ -2767,7 +2866,7 @@ export class Client extends Composer {
|
|
|
2767
2866
|
* @returns The new topic.
|
|
2768
2867
|
*/
|
|
2769
2868
|
async editTopic(chatId, topicId, title, params) {
|
|
2770
|
-
return await
|
|
2869
|
+
return await this.#forumManager.editTopic(chatId, topicId, title, params);
|
|
2771
2870
|
}
|
|
2772
2871
|
/**
|
|
2773
2872
|
* Hide the general forum topic.
|
|
@@ -2776,7 +2875,7 @@ export class Client extends Composer {
|
|
|
2776
2875
|
* @param chatId The identifier of a chat.
|
|
2777
2876
|
*/
|
|
2778
2877
|
async hideGeneralTopic(chatId) {
|
|
2779
|
-
await
|
|
2878
|
+
await this.#forumManager.hideGeneralTopic(chatId);
|
|
2780
2879
|
}
|
|
2781
2880
|
/**
|
|
2782
2881
|
* Show the general forum topic.
|
|
@@ -2785,7 +2884,7 @@ export class Client extends Composer {
|
|
|
2785
2884
|
* @param chatId The identifier of a chat.
|
|
2786
2885
|
*/
|
|
2787
2886
|
async showGeneralTopic(chatId) {
|
|
2788
|
-
await
|
|
2887
|
+
await this.#forumManager.showGeneralTopic(chatId);
|
|
2789
2888
|
}
|
|
2790
2889
|
/**
|
|
2791
2890
|
* Close a forum topic.
|
|
@@ -2795,7 +2894,7 @@ export class Client extends Composer {
|
|
|
2795
2894
|
* @param topicId The identifier of the topic.
|
|
2796
2895
|
*/
|
|
2797
2896
|
async closeTopic(chatId, topicId) {
|
|
2798
|
-
await
|
|
2897
|
+
await this.#forumManager.closeTopic(chatId, topicId);
|
|
2799
2898
|
}
|
|
2800
2899
|
/**
|
|
2801
2900
|
* Reopen a forum topic.
|
|
@@ -2805,7 +2904,7 @@ export class Client extends Composer {
|
|
|
2805
2904
|
* @param topicId The identifier of the topic.
|
|
2806
2905
|
*/
|
|
2807
2906
|
async reopenTopic(chatId, topicId) {
|
|
2808
|
-
await
|
|
2907
|
+
await this.#forumManager.reopenTopic(chatId, topicId);
|
|
2809
2908
|
}
|
|
2810
2909
|
/**
|
|
2811
2910
|
* Pin a forum topic.
|
|
@@ -2815,7 +2914,7 @@ export class Client extends Composer {
|
|
|
2815
2914
|
* @param topicId The identifier of the topic.
|
|
2816
2915
|
*/
|
|
2817
2916
|
async pinTopic(chatId, topicId) {
|
|
2818
|
-
await
|
|
2917
|
+
await this.#forumManager.pinTopic(chatId, topicId);
|
|
2819
2918
|
}
|
|
2820
2919
|
/**
|
|
2821
2920
|
* Unpin a forum topic.
|
|
@@ -2825,7 +2924,7 @@ export class Client extends Composer {
|
|
|
2825
2924
|
* @param topicId The identifier of the topic.
|
|
2826
2925
|
*/
|
|
2827
2926
|
async unpinTopic(chatId, topicId) {
|
|
2828
|
-
await
|
|
2927
|
+
await this.#forumManager.unpinTopic(chatId, topicId);
|
|
2829
2928
|
}
|
|
2830
2929
|
//
|
|
2831
2930
|
// ========================= CALLBACK QUERIES ========================= //
|
|
@@ -2841,7 +2940,7 @@ export class Client extends Composer {
|
|
|
2841
2940
|
* @cache
|
|
2842
2941
|
*/
|
|
2843
2942
|
async sendCallbackQuery(botId, messageId, question) {
|
|
2844
|
-
return await
|
|
2943
|
+
return await this.#callbackQueryManager.sendCallbackQuery(botId, messageId, question);
|
|
2845
2944
|
}
|
|
2846
2945
|
/**
|
|
2847
2946
|
* Answer a callback query. Bot-only.
|
|
@@ -2850,7 +2949,7 @@ export class Client extends Composer {
|
|
|
2850
2949
|
* @param id ID of the callback query to answer.
|
|
2851
2950
|
*/
|
|
2852
2951
|
async answerCallbackQuery(id, params) {
|
|
2853
|
-
await
|
|
2952
|
+
await this.#callbackQueryManager.answerCallbackQuery(id, params);
|
|
2854
2953
|
}
|
|
2855
2954
|
//
|
|
2856
2955
|
// ========================= INLINE QUERIES ========================= //
|
|
@@ -2865,7 +2964,7 @@ export class Client extends Composer {
|
|
|
2865
2964
|
* @cache
|
|
2866
2965
|
*/
|
|
2867
2966
|
async sendInlineQuery(botId, chatId, params) {
|
|
2868
|
-
return await
|
|
2967
|
+
return await this.#inlineQueryManager.sendInlineQuery(botId, chatId, params);
|
|
2869
2968
|
}
|
|
2870
2969
|
/**
|
|
2871
2970
|
* Answer an inline query. Bot-only.
|
|
@@ -2875,7 +2974,7 @@ export class Client extends Composer {
|
|
|
2875
2974
|
* @param results The results to answer with.
|
|
2876
2975
|
*/
|
|
2877
2976
|
async answerInlineQuery(id, results, params) {
|
|
2878
|
-
await
|
|
2977
|
+
await this.#inlineQueryManager.answerInlineQuery(id, results, params);
|
|
2879
2978
|
}
|
|
2880
2979
|
//
|
|
2881
2980
|
// ========================= BOTS ========================= //
|
|
@@ -2886,7 +2985,7 @@ export class Client extends Composer {
|
|
|
2886
2985
|
* @method bs
|
|
2887
2986
|
*/
|
|
2888
2987
|
async setMyDescription(params) {
|
|
2889
|
-
await
|
|
2988
|
+
await this.#botInfoManager.setMyDescription(params);
|
|
2890
2989
|
}
|
|
2891
2990
|
/**
|
|
2892
2991
|
* Set the bot's name in the given language. Bot-only.
|
|
@@ -2894,7 +2993,7 @@ export class Client extends Composer {
|
|
|
2894
2993
|
* @method bs
|
|
2895
2994
|
*/
|
|
2896
2995
|
async setMyName(params) {
|
|
2897
|
-
await
|
|
2996
|
+
await this.#botInfoManager.setMyName(params);
|
|
2898
2997
|
}
|
|
2899
2998
|
/**
|
|
2900
2999
|
* Set the bot's short description in the given language. Bot-only.
|
|
@@ -2902,7 +3001,7 @@ export class Client extends Composer {
|
|
|
2902
3001
|
* @method bs
|
|
2903
3002
|
*/
|
|
2904
3003
|
async setMyShortDescription(params) {
|
|
2905
|
-
await
|
|
3004
|
+
await this.#botInfoManager.setMyShortDescription(params);
|
|
2906
3005
|
}
|
|
2907
3006
|
/**
|
|
2908
3007
|
* Get the bot's description in the given language. Bot-only.
|
|
@@ -2911,7 +3010,7 @@ export class Client extends Composer {
|
|
|
2911
3010
|
* @returns The current bot's description in the specified language.
|
|
2912
3011
|
*/
|
|
2913
3012
|
async getMyDescription(params) {
|
|
2914
|
-
return await
|
|
3013
|
+
return await this.#botInfoManager.getMyDescription(params);
|
|
2915
3014
|
}
|
|
2916
3015
|
/**
|
|
2917
3016
|
* Get the bot's name in the given language. Bot-only.
|
|
@@ -2920,7 +3019,7 @@ export class Client extends Composer {
|
|
|
2920
3019
|
* @returns The current bot's name in the specified language.
|
|
2921
3020
|
*/
|
|
2922
3021
|
async getMyName(params) {
|
|
2923
|
-
return await
|
|
3022
|
+
return await this.#botInfoManager.getMyName(params);
|
|
2924
3023
|
}
|
|
2925
3024
|
/**
|
|
2926
3025
|
* Get the bot's short description in the given language. Bot-only.
|
|
@@ -2929,7 +3028,7 @@ export class Client extends Composer {
|
|
|
2929
3028
|
* @returns The current bot's short description in the specified language.
|
|
2930
3029
|
*/
|
|
2931
3030
|
async getMyShortDescription(params) {
|
|
2932
|
-
return await
|
|
3031
|
+
return await this.#botInfoManager.getMyShortDescription(params);
|
|
2933
3032
|
}
|
|
2934
3033
|
/**
|
|
2935
3034
|
* Set the bot's commands in the given scope and/or language. Bot-only.
|
|
@@ -2938,7 +3037,7 @@ export class Client extends Composer {
|
|
|
2938
3037
|
* @param commands The commands to set.
|
|
2939
3038
|
*/
|
|
2940
3039
|
async setMyCommands(commands, params) {
|
|
2941
|
-
await
|
|
3040
|
+
await this.#botInfoManager.setMyCommands(commands, params);
|
|
2942
3041
|
}
|
|
2943
3042
|
/**
|
|
2944
3043
|
* Get the bot's commands in the given scope and/or language. Bot-only.
|
|
@@ -2947,7 +3046,7 @@ export class Client extends Composer {
|
|
|
2947
3046
|
* @returns The current bot's commands in the specified language.
|
|
2948
3047
|
*/
|
|
2949
3048
|
async getMyCommands(params) {
|
|
2950
|
-
return await
|
|
3049
|
+
return await this.#botInfoManager.getMyCommands(params);
|
|
2951
3050
|
}
|
|
2952
3051
|
//
|
|
2953
3052
|
// ========================= REACTIONS ========================= //
|
|
@@ -2961,7 +3060,7 @@ export class Client extends Composer {
|
|
|
2961
3060
|
* @param reactions The new reactions.
|
|
2962
3061
|
*/
|
|
2963
3062
|
async setReactions(chatId, messageId, reactions, params) {
|
|
2964
|
-
await
|
|
3063
|
+
await this.#messageManager.setReactions(chatId, messageId, reactions, params);
|
|
2965
3064
|
}
|
|
2966
3065
|
/**
|
|
2967
3066
|
* Make a reaction to a message.
|
|
@@ -2972,7 +3071,7 @@ export class Client extends Composer {
|
|
|
2972
3071
|
* @param reaction The reaction to add.
|
|
2973
3072
|
*/
|
|
2974
3073
|
async addReaction(chatId, messageId, reaction, params) {
|
|
2975
|
-
await
|
|
3074
|
+
await this.#messageManager.addReaction(chatId, messageId, reaction, params);
|
|
2976
3075
|
}
|
|
2977
3076
|
/**
|
|
2978
3077
|
* Undo a reaction made to a message.
|
|
@@ -2983,7 +3082,7 @@ export class Client extends Composer {
|
|
|
2983
3082
|
* @param reaction The reaction to remove.
|
|
2984
3083
|
*/
|
|
2985
3084
|
async removeReaction(chatId, messageId, reaction) {
|
|
2986
|
-
await
|
|
3085
|
+
await this.#messageManager.removeReaction(chatId, messageId, reaction);
|
|
2987
3086
|
}
|
|
2988
3087
|
//
|
|
2989
3088
|
// ========================= STORIES ========================= //
|
|
@@ -2996,7 +3095,7 @@ export class Client extends Composer {
|
|
|
2996
3095
|
* @returns The created story.
|
|
2997
3096
|
*/
|
|
2998
3097
|
async createStory(chatId, content, params) {
|
|
2999
|
-
return await
|
|
3098
|
+
return await this.#storyManager.createStory(chatId, content, params);
|
|
3000
3099
|
}
|
|
3001
3100
|
/**
|
|
3002
3101
|
* Retrieve multiple stories. User-only.
|
|
@@ -3010,7 +3109,7 @@ export class Client extends Composer {
|
|
|
3010
3109
|
if (!storyIds.length) {
|
|
3011
3110
|
return [];
|
|
3012
3111
|
}
|
|
3013
|
-
return await
|
|
3112
|
+
return await this.#storyManager.getStories(chatId, storyIds);
|
|
3014
3113
|
}
|
|
3015
3114
|
/**
|
|
3016
3115
|
* Retrieve a single story. User-only.
|
|
@@ -3021,7 +3120,7 @@ export class Client extends Composer {
|
|
|
3021
3120
|
* @returns The retrieved story.
|
|
3022
3121
|
*/
|
|
3023
3122
|
async getStory(chatId, storyId) {
|
|
3024
|
-
return await
|
|
3123
|
+
return await this.#storyManager.getStory(chatId, storyId);
|
|
3025
3124
|
}
|
|
3026
3125
|
/**
|
|
3027
3126
|
* Delete multiple stories. User-only.
|
|
@@ -3031,7 +3130,7 @@ export class Client extends Composer {
|
|
|
3031
3130
|
* @param storyIds The identifiers of the stories to delete.
|
|
3032
3131
|
*/
|
|
3033
3132
|
async deleteStories(chatId, storyIds) {
|
|
3034
|
-
await
|
|
3133
|
+
await this.#storyManager.deleteStories(chatId, storyIds);
|
|
3035
3134
|
}
|
|
3036
3135
|
/**
|
|
3037
3136
|
* Delete a single story. User-only.
|
|
@@ -3041,7 +3140,7 @@ export class Client extends Composer {
|
|
|
3041
3140
|
* @param storyId The identifier of the story to delete.
|
|
3042
3141
|
*/
|
|
3043
3142
|
async deleteStory(chatId, storyId) {
|
|
3044
|
-
await
|
|
3143
|
+
await this.#storyManager.deleteStory(chatId, storyId);
|
|
3045
3144
|
}
|
|
3046
3145
|
/**
|
|
3047
3146
|
* Add multiple stories to highlights. User-only.
|
|
@@ -3051,7 +3150,7 @@ export class Client extends Composer {
|
|
|
3051
3150
|
* @param storyIds The identifiers of the stories to add to highlights.
|
|
3052
3151
|
*/
|
|
3053
3152
|
async addStoriesToHighlights(chatId, storyIds) {
|
|
3054
|
-
await
|
|
3153
|
+
await this.#storyManager.addStoriesToHighlights(chatId, storyIds);
|
|
3055
3154
|
}
|
|
3056
3155
|
/**
|
|
3057
3156
|
* Add a single story to highlights. User-only.
|
|
@@ -3061,7 +3160,7 @@ export class Client extends Composer {
|
|
|
3061
3160
|
* @param storyId The identifier of the story to add to highlights.
|
|
3062
3161
|
*/
|
|
3063
3162
|
async addStoryToHighlights(chatId, storyId) {
|
|
3064
|
-
await
|
|
3163
|
+
await this.#storyManager.addStoryToHighlights(chatId, storyId);
|
|
3065
3164
|
}
|
|
3066
3165
|
/**
|
|
3067
3166
|
* Remove multiple stories from highlights. User-only.
|
|
@@ -3071,7 +3170,7 @@ export class Client extends Composer {
|
|
|
3071
3170
|
* @param storyIds The identifiers of the stories to remove from highlights.
|
|
3072
3171
|
*/
|
|
3073
3172
|
async removeStoriesFromHighlights(chatId, storyIds) {
|
|
3074
|
-
await
|
|
3173
|
+
await this.#storyManager.removeStoriesFromHighlights(chatId, storyIds);
|
|
3075
3174
|
}
|
|
3076
3175
|
/**
|
|
3077
3176
|
* Remove a single story from highlights. User-only.
|
|
@@ -3081,7 +3180,7 @@ export class Client extends Composer {
|
|
|
3081
3180
|
* @param storyId The identifier of the story to remove from highlights.
|
|
3082
3181
|
*/
|
|
3083
3182
|
async removeStoryFromHighlights(chatId, storyId) {
|
|
3084
|
-
await
|
|
3183
|
+
await this.#storyManager.removeStoryFromHighlights(chatId, storyId);
|
|
3085
3184
|
}
|
|
3086
3185
|
//
|
|
3087
3186
|
// ========================= MISC ========================= //
|
|
@@ -3092,7 +3191,7 @@ export class Client extends Composer {
|
|
|
3092
3191
|
* @method mc
|
|
3093
3192
|
*/
|
|
3094
3193
|
async getNetworkStatistics() {
|
|
3095
|
-
return await
|
|
3194
|
+
return await this.#networkStatisticsManager.getNetworkStatistics();
|
|
3096
3195
|
}
|
|
3097
3196
|
/**
|
|
3098
3197
|
* Block a user. User-only.
|
|
@@ -3101,7 +3200,7 @@ export class Client extends Composer {
|
|
|
3101
3200
|
* @param userId The identifier of the user to block.
|
|
3102
3201
|
*/
|
|
3103
3202
|
async blockUser(userId) {
|
|
3104
|
-
await
|
|
3203
|
+
await this.#messageManager.blockUser(userId);
|
|
3105
3204
|
}
|
|
3106
3205
|
/**
|
|
3107
3206
|
* Unblock a user. User-only.
|
|
@@ -3110,7 +3209,7 @@ export class Client extends Composer {
|
|
|
3110
3209
|
* @param userId The identifier of the user to unblock.
|
|
3111
3210
|
*/
|
|
3112
3211
|
async unblockUser(userId) {
|
|
3113
|
-
await
|
|
3212
|
+
await this.#messageManager.unblockUser(userId);
|
|
3114
3213
|
}
|
|
3115
3214
|
//
|
|
3116
3215
|
// ========================= VIDEO CHATS ========================= //
|
|
@@ -3123,7 +3222,7 @@ export class Client extends Composer {
|
|
|
3123
3222
|
* @returns The started video chat.
|
|
3124
3223
|
*/
|
|
3125
3224
|
async startVideoChat(chatId, params) {
|
|
3126
|
-
return await
|
|
3225
|
+
return await this.#videoChatManager.startVideoChat(chatId, params);
|
|
3127
3226
|
}
|
|
3128
3227
|
/**
|
|
3129
3228
|
* Schedule a video chat. User-only.
|
|
@@ -3134,7 +3233,7 @@ export class Client extends Composer {
|
|
|
3134
3233
|
* @returns The scheduled video chat.
|
|
3135
3234
|
*/
|
|
3136
3235
|
async scheduleVideoChat(chatId, startAt, params) {
|
|
3137
|
-
return await
|
|
3236
|
+
return await this.#videoChatManager.scheduleVideoChat(chatId, startAt, params);
|
|
3138
3237
|
}
|
|
3139
3238
|
/**
|
|
3140
3239
|
* Join a video chat. User-only.
|
|
@@ -3145,7 +3244,7 @@ export class Client extends Composer {
|
|
|
3145
3244
|
* @returns Parameters to be passed to the used WebRTC library.
|
|
3146
3245
|
*/
|
|
3147
3246
|
async joinVideoChat(id, params_, params) {
|
|
3148
|
-
return await
|
|
3247
|
+
return await this.#videoChatManager.joinVideoChat(id, params_, params);
|
|
3149
3248
|
}
|
|
3150
3249
|
/**
|
|
3151
3250
|
* Leave a video chat. User-only.
|
|
@@ -3154,7 +3253,7 @@ export class Client extends Composer {
|
|
|
3154
3253
|
* @param id The identifier of a video chat retrieved from getChat, startVideoChat, or scheduleVideoChat.
|
|
3155
3254
|
*/
|
|
3156
3255
|
async leaveVideoChat(id) {
|
|
3157
|
-
await
|
|
3256
|
+
await this.#videoChatManager.leaveVideoChat(id);
|
|
3158
3257
|
}
|
|
3159
3258
|
/**
|
|
3160
3259
|
* Join a live stream. User-only.
|
|
@@ -3163,7 +3262,7 @@ export class Client extends Composer {
|
|
|
3163
3262
|
* @param id The identifier of a video chat retrieved from getChat, startVideoChat, or scheduleVideoChat.
|
|
3164
3263
|
*/
|
|
3165
3264
|
async joinLiveStream(id) {
|
|
3166
|
-
await
|
|
3265
|
+
await this.#videoChatManager.joinLiveStream(id);
|
|
3167
3266
|
}
|
|
3168
3267
|
/**
|
|
3169
3268
|
* Get a video chat. User-only.
|
|
@@ -3173,7 +3272,7 @@ export class Client extends Composer {
|
|
|
3173
3272
|
* @cache
|
|
3174
3273
|
*/
|
|
3175
3274
|
async getVideoChat(id) {
|
|
3176
|
-
return await
|
|
3275
|
+
return await this.#videoChatManager.getVideoChat(id);
|
|
3177
3276
|
}
|
|
3178
3277
|
/**
|
|
3179
3278
|
* Get live stream channels. User-only.
|
|
@@ -3182,7 +3281,7 @@ export class Client extends Composer {
|
|
|
3182
3281
|
* @param id The identifier of a video chat retrieved from getChat, startVideoChat, or scheduleVideoChat.
|
|
3183
3282
|
*/
|
|
3184
3283
|
async getLiveStreamChannels(id) {
|
|
3185
|
-
return await
|
|
3284
|
+
return await this.#videoChatManager.getLiveStreamChannels(id);
|
|
3186
3285
|
}
|
|
3187
3286
|
/**
|
|
3188
3287
|
* Download a live stream chunk. User-only.
|
|
@@ -3194,7 +3293,7 @@ export class Client extends Composer {
|
|
|
3194
3293
|
* @param timestamp Millisecond timestamp of the chunk to download.
|
|
3195
3294
|
*/
|
|
3196
3295
|
async *downloadLiveStreamChunk(id, channelId, scale, timestamp, params) {
|
|
3197
|
-
yield*
|
|
3296
|
+
yield* this.#videoChatManager.downloadLiveStreamChunk(id, channelId, scale, timestamp, params);
|
|
3198
3297
|
}
|
|
3199
3298
|
//
|
|
3200
3299
|
// ========================= PAYMENTS ========================= //
|
|
@@ -3207,7 +3306,7 @@ export class Client extends Composer {
|
|
|
3207
3306
|
* @param ok Whether the checkout is going to be processed.
|
|
3208
3307
|
*/
|
|
3209
3308
|
async answerPreCheckoutQuery(preCheckoutQueryId, ok, params) {
|
|
3210
|
-
await
|
|
3309
|
+
await this.#paymentManager.answerPreCheckoutQuery(preCheckoutQueryId, ok, params);
|
|
3211
3310
|
}
|
|
3212
3311
|
/**
|
|
3213
3312
|
* Refund a star payment. Bot-only.
|
|
@@ -3217,7 +3316,7 @@ export class Client extends Composer {
|
|
|
3217
3316
|
* @param telegramPaymentChargeId The identifier of the charge.
|
|
3218
3317
|
*/
|
|
3219
3318
|
async refundStarPayment(userId, telegramPaymentChargeId) {
|
|
3220
|
-
await
|
|
3319
|
+
await this.#paymentManager.refundStarPayment(userId, telegramPaymentChargeId);
|
|
3221
3320
|
}
|
|
3222
3321
|
//
|
|
3223
3322
|
// ========================= CONTACTS ========================= //
|
|
@@ -3228,7 +3327,7 @@ export class Client extends Composer {
|
|
|
3228
3327
|
* @method co
|
|
3229
3328
|
*/
|
|
3230
3329
|
async getContacts() {
|
|
3231
|
-
return await
|
|
3330
|
+
return await this.#accountManager.getContacts();
|
|
3232
3331
|
}
|
|
3233
3332
|
/**
|
|
3234
3333
|
* Delete multiple contacts. User-only.
|
|
@@ -3237,7 +3336,7 @@ export class Client extends Composer {
|
|
|
3237
3336
|
* @param userIds The identifiers of contacts to delete.
|
|
3238
3337
|
*/
|
|
3239
3338
|
async deleteContacts(userIds) {
|
|
3240
|
-
await
|
|
3339
|
+
await this.#accountManager.deleteContacts(userIds);
|
|
3241
3340
|
}
|
|
3242
3341
|
/**
|
|
3243
3342
|
* Delete a single contact. User-only.
|
|
@@ -3246,7 +3345,7 @@ export class Client extends Composer {
|
|
|
3246
3345
|
* @param userId The identifier of the contact to delete.
|
|
3247
3346
|
*/
|
|
3248
3347
|
async deleteContact(userId) {
|
|
3249
|
-
await
|
|
3348
|
+
await this.#accountManager.deleteContact(userId);
|
|
3250
3349
|
}
|
|
3251
3350
|
/**
|
|
3252
3351
|
* Add a contact. User-only.
|
|
@@ -3255,7 +3354,7 @@ export class Client extends Composer {
|
|
|
3255
3354
|
* @param userId The identifier of the user to add as contact.
|
|
3256
3355
|
*/
|
|
3257
3356
|
async addContact(userId, params) {
|
|
3258
|
-
await
|
|
3357
|
+
await this.#accountManager.addContact(userId, params);
|
|
3259
3358
|
}
|
|
3260
3359
|
//
|
|
3261
3360
|
// ========================= TRANSLATIONS ========================= //
|
|
@@ -3267,7 +3366,7 @@ export class Client extends Composer {
|
|
|
3267
3366
|
* @cache
|
|
3268
3367
|
*/
|
|
3269
3368
|
async getTranslations(params) {
|
|
3270
|
-
return await
|
|
3369
|
+
return await this.#translationsManager.getTranslations(params);
|
|
3271
3370
|
}
|
|
3272
3371
|
//
|
|
3273
3372
|
// ========================= GIFTS ========================= //
|
|
@@ -3278,7 +3377,7 @@ export class Client extends Composer {
|
|
|
3278
3377
|
* @method gf
|
|
3279
3378
|
*/
|
|
3280
3379
|
async getGifts() {
|
|
3281
|
-
return await
|
|
3380
|
+
return await this.#giftManager.getGifts();
|
|
3282
3381
|
}
|
|
3283
3382
|
/**
|
|
3284
3383
|
* Get gifts claimed by a user or a channel. User-only.
|
|
@@ -3287,7 +3386,7 @@ export class Client extends Composer {
|
|
|
3287
3386
|
* @param chatId The identifier of a user or a channel to get gifts for.
|
|
3288
3387
|
*/
|
|
3289
3388
|
async getClaimedGifts(chatId, params) {
|
|
3290
|
-
return await
|
|
3389
|
+
return await this.#giftManager.getClaimedGifts(chatId, params);
|
|
3291
3390
|
}
|
|
3292
3391
|
/**
|
|
3293
3392
|
* Send a gift.
|
|
@@ -3297,7 +3396,7 @@ export class Client extends Composer {
|
|
|
3297
3396
|
* @param giftId The identifier of the gift to send.
|
|
3298
3397
|
*/
|
|
3299
3398
|
async sendGift(chatId, giftId, params) {
|
|
3300
|
-
await
|
|
3399
|
+
await this.#giftManager.sendGift(chatId, giftId, params);
|
|
3301
3400
|
}
|
|
3302
3401
|
/**
|
|
3303
3402
|
* Sell a gift.
|
|
@@ -3307,7 +3406,7 @@ export class Client extends Composer {
|
|
|
3307
3406
|
* @param messageId The identifier of the service message announcing the receival of the gift.
|
|
3308
3407
|
*/
|
|
3309
3408
|
async sellGift(userId, messageId) {
|
|
3310
|
-
await
|
|
3409
|
+
await this.#giftManager.sellGift(userId, messageId);
|
|
3311
3410
|
}
|
|
3312
3411
|
/**
|
|
3313
3412
|
* Get a gift using its slug.
|
|
@@ -3316,124 +3415,6 @@ export class Client extends Composer {
|
|
|
3316
3415
|
* @param slug The slug of a gift.
|
|
3317
3416
|
*/
|
|
3318
3417
|
async getGift(slug) {
|
|
3319
|
-
return await
|
|
3418
|
+
return await this.#giftManager.getGift(slug);
|
|
3320
3419
|
}
|
|
3321
3420
|
}
|
|
3322
|
-
_Client_handleCtxUpdate = async function _Client_handleCtxUpdate(update) {
|
|
3323
|
-
if (__classPrivateFieldGet(this, _Client_disableUpdates, "f") && !("authorizationState" in update) && !("connectionState" in update)) {
|
|
3324
|
-
return;
|
|
3325
|
-
}
|
|
3326
|
-
try {
|
|
3327
|
-
await this.middleware()(await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, update), resolve);
|
|
3328
|
-
}
|
|
3329
|
-
catch (err) {
|
|
3330
|
-
__classPrivateFieldGet(this, _Client_L, "f").error("Failed to handle update:", err);
|
|
3331
|
-
throw err;
|
|
3332
|
-
}
|
|
3333
|
-
}, _Client_queueHandleCtxUpdate = function _Client_queueHandleCtxUpdate(update) {
|
|
3334
|
-
__classPrivateFieldGet(this, _Client_updateManager, "f").getHandleUpdateQueue(UpdateManager.MAIN_BOX_ID).add(async () => {
|
|
3335
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, update);
|
|
3336
|
-
});
|
|
3337
|
-
}, _Client_handleUpdate = async function _Client_handleUpdate(update) {
|
|
3338
|
-
const promises = new Array();
|
|
3339
|
-
if (Api.is("updateUserName", update)) {
|
|
3340
|
-
await this.messageStorage.updateUsernames(Number(update.user_id), update.usernames.map((v) => v.username));
|
|
3341
|
-
const peer = { ...update, _: "peerUser" };
|
|
3342
|
-
const entity = await this[getEntity](peer);
|
|
3343
|
-
if (entity != null) {
|
|
3344
|
-
entity.usernames = update.usernames;
|
|
3345
|
-
entity.first_name = update.first_name;
|
|
3346
|
-
entity.last_name = update.last_name;
|
|
3347
|
-
await this.messageStorage.setEntity(entity);
|
|
3348
|
-
}
|
|
3349
|
-
}
|
|
3350
|
-
if (__classPrivateFieldGet(this, _Client_messageManager, "f").canHandleUpdate(update)) {
|
|
3351
|
-
promises.push(() => __classPrivateFieldGet(this, _Client_messageManager, "f").handleUpdate(update));
|
|
3352
|
-
}
|
|
3353
|
-
if (__classPrivateFieldGet(this, _Client_chatManager, "f").canHandleUpdate(update)) {
|
|
3354
|
-
promises.push(() => __classPrivateFieldGet(this, _Client_chatManager, "f").handleUpdate(update));
|
|
3355
|
-
}
|
|
3356
|
-
if (__classPrivateFieldGet(this, _Client_pollManager, "f").canHandleUpdate(update)) {
|
|
3357
|
-
promises.push(() => __classPrivateFieldGet(this, _Client_pollManager, "f").handleUpdate(update));
|
|
3358
|
-
}
|
|
3359
|
-
if (__classPrivateFieldGet(this, _Client_videoChatManager, "f").canHandleUpdate(update)) {
|
|
3360
|
-
promises.push(() => __classPrivateFieldGet(this, _Client_videoChatManager, "f").handleUpdate(update));
|
|
3361
|
-
}
|
|
3362
|
-
if (__classPrivateFieldGet(this, _Client_callbackQueryManager, "f").canHandleUpdate(update)) {
|
|
3363
|
-
promises.push(() => __classPrivateFieldGet(this, _Client_callbackQueryManager, "f").handleUpdate(update));
|
|
3364
|
-
}
|
|
3365
|
-
if (__classPrivateFieldGet(this, _Client_inlineQueryManager, "f").canHandleUpdate(update)) {
|
|
3366
|
-
promises.push(() => __classPrivateFieldGet(this, _Client_inlineQueryManager, "f").handleUpdate(update));
|
|
3367
|
-
}
|
|
3368
|
-
if (__classPrivateFieldGet(this, _Client_linkPreviewManager, "f").canHandleUpdate(update)) {
|
|
3369
|
-
promises.push(() => __classPrivateFieldGet(this, _Client_linkPreviewManager, "f").handleUpdate(update));
|
|
3370
|
-
}
|
|
3371
|
-
if (__classPrivateFieldGet(this, _Client_reactionManager, "f").canHandleUpdate(update)) {
|
|
3372
|
-
promises.push(() => __classPrivateFieldGet(this, _Client_reactionManager, "f").handleUpdate(update));
|
|
3373
|
-
}
|
|
3374
|
-
if (__classPrivateFieldGet(this, _Client_chatListManager, "f").canHandleUpdate(update)) {
|
|
3375
|
-
promises.push(() => __classPrivateFieldGet(this, _Client_chatListManager, "f").handleUpdate(update));
|
|
3376
|
-
}
|
|
3377
|
-
if (__classPrivateFieldGet(this, _Client_storyManager, "f").canHandleUpdate(update)) {
|
|
3378
|
-
promises.push(() => __classPrivateFieldGet(this, _Client_storyManager, "f").handleUpdate(update));
|
|
3379
|
-
}
|
|
3380
|
-
if (__classPrivateFieldGet(this, _Client_businessConnectionManager, "f").canHandleUpdate(update)) {
|
|
3381
|
-
promises.push(() => __classPrivateFieldGet(this, _Client_businessConnectionManager, "f").handleUpdate(update));
|
|
3382
|
-
}
|
|
3383
|
-
if (__classPrivateFieldGet(this, _Client_storyManager, "f").canHandleUpdate(update)) {
|
|
3384
|
-
promises.push(() => __classPrivateFieldGet(this, _Client_storyManager, "f").handleUpdate(update));
|
|
3385
|
-
}
|
|
3386
|
-
if (__classPrivateFieldGet(this, _Client_paymentManager, "f").canHandleUpdate(update)) {
|
|
3387
|
-
promises.push(() => __classPrivateFieldGet(this, _Client_paymentManager, "f").handleUpdate(update));
|
|
3388
|
-
}
|
|
3389
|
-
if (__classPrivateFieldGet(this, _Client_translationsManager, "f").canHandleUpdate(update)) {
|
|
3390
|
-
promises.push(() => __classPrivateFieldGet(this, _Client_translationsManager, "f").handleUpdate(update));
|
|
3391
|
-
}
|
|
3392
|
-
return () => Promise.resolve().then(async () => {
|
|
3393
|
-
const updates = new Array();
|
|
3394
|
-
for (const promise of promises) {
|
|
3395
|
-
try {
|
|
3396
|
-
const update = await promise();
|
|
3397
|
-
if (update) {
|
|
3398
|
-
updates.push(update);
|
|
3399
|
-
}
|
|
3400
|
-
}
|
|
3401
|
-
catch (err) {
|
|
3402
|
-
__classPrivateFieldGet(this, _Client_L, "f").error("failed to construct update:", err);
|
|
3403
|
-
}
|
|
3404
|
-
}
|
|
3405
|
-
for (const update of updates) {
|
|
3406
|
-
try {
|
|
3407
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, update);
|
|
3408
|
-
}
|
|
3409
|
-
finally {
|
|
3410
|
-
if ("deletedMessages" in update) {
|
|
3411
|
-
for (const { chatId, messageId } of update.deletedMessages) {
|
|
3412
|
-
await this.messageStorage.setMessage(chatId, messageId, null);
|
|
3413
|
-
await __classPrivateFieldGet(this, _Client_chatListManager, "f").reassignChatLastMessage(chatId);
|
|
3414
|
-
}
|
|
3415
|
-
}
|
|
3416
|
-
}
|
|
3417
|
-
}
|
|
3418
|
-
});
|
|
3419
|
-
}, _Client_getMe = async function _Client_getMe() {
|
|
3420
|
-
if (__classPrivateFieldGet(this, _Client_lastGetMe, "f") != null) {
|
|
3421
|
-
return __classPrivateFieldGet(this, _Client_lastGetMe, "f");
|
|
3422
|
-
}
|
|
3423
|
-
else {
|
|
3424
|
-
const user = await this.getMe();
|
|
3425
|
-
__classPrivateFieldSet(this, _Client_lastGetMe, user, "f");
|
|
3426
|
-
return user;
|
|
3427
|
-
}
|
|
3428
|
-
}, _Client_onConnectionStateChange = function _Client_onConnectionStateChange(connected) {
|
|
3429
|
-
if (__classPrivateFieldGet(this, _Client_lastConnectionState, "f") != connected) {
|
|
3430
|
-
if (connected) {
|
|
3431
|
-
if (__classPrivateFieldGet(this, _Client_previouslyConnected, "f")) {
|
|
3432
|
-
drop(__classPrivateFieldGet(this, _Client_updateManager, "f").recoverUpdateGap("reconnect"));
|
|
3433
|
-
}
|
|
3434
|
-
__classPrivateFieldSet(this, _Client_previouslyConnected, true, "f");
|
|
3435
|
-
}
|
|
3436
|
-
const connectionState = connected ? "ready" : "notConnected";
|
|
3437
|
-
__classPrivateFieldGet(this, _Client_instances, "m", _Client_queueHandleCtxUpdate).call(this, { connectionState });
|
|
3438
|
-
}
|
|
3439
|
-
};
|