@mtkruto/node 0.1.138 → 0.1.140
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/3_types.d.ts +10 -36
- package/esm/3_types.js +10 -36
- package/esm/4_constants.d.ts +1 -1
- package/esm/4_constants.js +1 -1
- package/esm/5_client.d.ts +1 -1
- package/esm/5_client.js +1 -1
- package/esm/_dnt.polyfills.d.ts +6 -0
- package/esm/client/0_filters.d.ts +60 -0
- package/esm/client/0_filters.js +27 -0
- package/esm/client/0_message.js +2 -2
- package/esm/client/{3_params.d.ts → 0_params.d.ts} +30 -33
- package/esm/client/0_types.d.ts +39 -0
- package/esm/client/0_types.js +2 -0
- package/esm/client/0_utilities.d.ts +1 -47
- package/esm/client/0_utilities.js +0 -27
- package/esm/client/1_composer.d.ts +1 -1
- package/esm/client/1_composer.js +1 -1
- package/esm/client/1_file_manager.d.ts +10 -0
- package/esm/client/1_file_manager.js +241 -0
- package/esm/client/1_update_manager.d.ts +18 -0
- package/esm/client/1_update_manager.js +553 -0
- package/esm/client/2_message_manager.d.ts +40 -0
- package/esm/client/2_message_manager.js +621 -0
- package/esm/client/3_chat_list_manager.d.ts +21 -0
- package/esm/client/3_chat_list_manager.js +353 -0
- package/esm/client/3_reaction_manager.d.ts +16 -0
- package/esm/client/3_reaction_manager.js +61 -0
- package/esm/client/4_client.d.ts +187 -60
- package/esm/client/4_client.js +492 -1699
- package/esm/connection/1_connection_web_socket.js +6 -6
- package/esm/deps/raw.githubusercontent.com/MTKruto/debug/main/deps.d.ts +1 -1
- package/esm/deps/raw.githubusercontent.com/MTKruto/debug/main/deps.js +1 -1
- package/esm/deps/raw.githubusercontent.com/MTKruto/object-inspect/main/index.d.ts +1 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/object-inspect/main/index.js +524 -0
- package/esm/mod.d.ts +1 -0
- package/esm/mod.js +1 -0
- package/esm/storage/0_storage.d.ts +5 -3
- package/esm/storage/0_storage.js +14 -4
- package/esm/tl/1_tl_object.d.ts +1 -0
- package/esm/tl/1_tl_object.js +24 -0
- package/esm/types/0_bot_command.d.ts +1 -0
- package/esm/types/0_chat_member_rights.d.ts +37 -0
- package/esm/types/0_chat_photo.d.ts +4 -4
- package/esm/types/0_file_source.d.ts +5 -0
- package/esm/types/0_giveaway_parameters.js +2 -1
- package/esm/types/0_id.d.ts +4 -0
- package/esm/types/0_message_entity.d.ts +20 -20
- package/esm/types/1__getters.d.ts +2 -2
- package/esm/types/1_animation.d.ts +1 -1
- package/esm/types/1_bot_command_scope.d.ts +5 -4
- package/esm/types/1_chat_p.d.ts +5 -6
- package/esm/types/1_document.d.ts +1 -0
- package/esm/types/1_input_message_content.d.ts +88 -0
- package/esm/types/1_photo.d.ts +1 -1
- package/esm/types/1_sticker.d.ts +1 -1
- package/esm/types/1_user.d.ts +1 -1
- package/esm/types/1_video.d.ts +1 -1
- package/esm/types/1_video_note.d.ts +1 -1
- package/esm/types/2_inline_keyboard_button.d.ts +10 -10
- package/esm/types/2_message_reaction_count.d.ts +3 -0
- package/esm/types/2_message_reaction_count.js +17 -1
- package/esm/types/2_message_reactions.d.ts +15 -0
- package/esm/types/2_message_reactions.js +37 -0
- package/esm/types/3_reply_markup.d.ts +42 -0
- package/esm/types/3_reply_markup.js +117 -0
- package/esm/types/4_inline_query_result.d.ts +193 -0
- package/esm/types/{5_inline_query_result.js → 4_inline_query_result.js} +2 -2
- package/esm/types/4_message.d.ts +36 -39
- package/esm/types/4_message.js +7 -24
- package/esm/types/5_callback_query.d.ts +2 -1
- package/esm/types/5_chat.d.ts +8 -5
- package/esm/types/6_update.d.ts +12 -2
- package/esm/utilities/0_buffer.js +9 -6
- package/esm/utilities/0_object.d.ts +1 -1
- package/esm/utilities/0_object.js +1 -6
- package/esm/utilities/1_misc.d.ts +2 -0
- package/esm/utilities/1_misc.js +6 -0
- package/package.json +1 -2
- package/script/3_types.d.ts +10 -36
- package/script/3_types.js +10 -36
- package/script/4_constants.d.ts +1 -1
- package/script/4_constants.js +1 -1
- package/script/5_client.d.ts +1 -1
- package/script/5_client.js +1 -1
- package/script/_dnt.polyfills.d.ts +6 -0
- package/script/client/0_filters.d.ts +60 -0
- package/script/client/0_filters.js +31 -0
- package/script/client/0_message.js +1 -1
- package/script/client/{3_params.d.ts → 0_params.d.ts} +30 -33
- package/script/client/0_types.d.ts +39 -0
- package/script/client/0_types.js +6 -0
- package/script/client/0_utilities.d.ts +1 -47
- package/script/client/0_utilities.js +1 -29
- package/script/client/1_composer.d.ts +1 -1
- package/script/client/1_composer.js +2 -2
- package/script/client/1_file_manager.d.ts +10 -0
- package/script/client/1_file_manager.js +245 -0
- package/script/client/1_update_manager.d.ts +18 -0
- package/script/client/1_update_manager.js +557 -0
- package/script/client/2_message_manager.d.ts +40 -0
- package/script/client/2_message_manager.js +625 -0
- package/script/client/3_chat_list_manager.d.ts +21 -0
- package/script/client/3_chat_list_manager.js +357 -0
- package/script/client/3_reaction_manager.d.ts +16 -0
- package/script/client/3_reaction_manager.js +65 -0
- package/script/client/4_client.d.ts +187 -60
- package/script/client/4_client.js +491 -1699
- package/script/connection/1_connection_web_socket.js +5 -5
- package/script/deps/raw.githubusercontent.com/MTKruto/debug/main/deps.d.ts +1 -1
- package/script/deps/raw.githubusercontent.com/MTKruto/debug/main/deps.js +2 -2
- package/script/deps/raw.githubusercontent.com/MTKruto/object-inspect/main/index.d.ts +1 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/object-inspect/main/index.js +550 -0
- package/script/mod.d.ts +1 -0
- package/script/mod.js +1 -0
- package/script/storage/0_storage.d.ts +5 -3
- package/script/storage/0_storage.js +14 -4
- package/script/tl/1_tl_object.d.ts +1 -0
- package/script/tl/1_tl_object.js +24 -0
- package/script/types/0_bot_command.d.ts +1 -0
- package/script/types/0_chat_member_rights.d.ts +37 -0
- package/script/types/0_chat_photo.d.ts +4 -4
- package/script/types/0_file_source.d.ts +5 -0
- package/script/types/0_giveaway_parameters.js +2 -1
- package/script/types/0_id.d.ts +4 -0
- package/script/types/0_message_entity.d.ts +20 -20
- package/script/types/1__getters.d.ts +2 -2
- package/script/types/1_animation.d.ts +1 -1
- package/script/types/1_bot_command_scope.d.ts +5 -4
- package/script/types/1_chat_p.d.ts +5 -6
- package/script/types/1_document.d.ts +1 -0
- package/script/types/1_input_message_content.d.ts +88 -0
- package/script/types/1_photo.d.ts +1 -1
- package/script/types/1_sticker.d.ts +1 -1
- package/script/types/1_user.d.ts +1 -1
- package/script/types/1_video.d.ts +1 -1
- package/script/types/1_video_note.d.ts +1 -1
- package/script/types/2_inline_keyboard_button.d.ts +10 -10
- package/script/types/2_message_reaction_count.d.ts +3 -0
- package/script/types/2_message_reaction_count.js +19 -0
- package/script/types/2_message_reactions.d.ts +15 -0
- package/script/types/2_message_reactions.js +41 -0
- package/script/types/3_reply_markup.d.ts +42 -0
- package/script/types/3_reply_markup.js +122 -0
- package/script/types/4_inline_query_result.d.ts +193 -0
- package/script/types/{5_inline_query_result.js → 4_inline_query_result.js} +3 -3
- package/script/types/4_message.d.ts +36 -39
- package/script/types/4_message.js +6 -23
- package/script/types/5_callback_query.d.ts +2 -1
- package/script/types/5_chat.d.ts +8 -5
- package/script/types/6_update.d.ts +12 -2
- package/script/utilities/0_buffer.js +9 -6
- package/script/utilities/0_object.d.ts +1 -1
- package/script/utilities/0_object.js +1 -6
- package/script/utilities/1_misc.d.ts +2 -0
- package/script/utilities/1_misc.js +9 -1
- package/esm/types/0_chat_id.d.ts +0 -4
- package/esm/types/0_force_reply.d.ts +0 -12
- package/esm/types/0_force_reply.js +0 -17
- package/esm/types/0_input_contact_message_content.d.ts +0 -11
- package/esm/types/0_input_location_message_content.d.ts +0 -15
- package/esm/types/0_input_venue_message_content.d.ts +0 -19
- package/esm/types/0_reply_keyboard_remove.d.ts +0 -10
- package/esm/types/0_reply_keyboard_remove.js +0 -8
- package/esm/types/1_input_invoice_message_content.d.ts +0 -23
- package/esm/types/1_input_text_message_content.d.ts +0 -8
- package/esm/types/1_input_text_message_content.js +0 -1
- package/esm/types/2_input_message_content.d.ts +0 -6
- package/esm/types/2_input_message_content.js +0 -1
- package/esm/types/2_reply_keyboard_markup.d.ts +0 -12
- package/esm/types/2_reply_keyboard_markup.js +0 -37
- package/esm/types/3_inline_keyboard_markup.d.ts +0 -8
- package/esm/types/3_inline_keyboard_markup.js +0 -24
- package/esm/types/4_inline_query_result_article.d.ts +0 -15
- package/esm/types/4_inline_query_result_article.js +0 -1
- package/esm/types/4_inline_query_result_audio.d.ts +0 -17
- package/esm/types/4_inline_query_result_audio.js +0 -1
- package/esm/types/4_inline_query_result_cached_audio.d.ts +0 -14
- package/esm/types/4_inline_query_result_cached_audio.js +0 -1
- package/esm/types/4_inline_query_result_cached_document.d.ts +0 -15
- package/esm/types/4_inline_query_result_cached_document.js +0 -1
- package/esm/types/4_inline_query_result_cached_gif.d.ts +0 -15
- package/esm/types/4_inline_query_result_cached_gif.js +0 -1
- package/esm/types/4_inline_query_result_cached_mpeg4_gif.d.ts +0 -15
- package/esm/types/4_inline_query_result_cached_mpeg4_gif.js +0 -1
- package/esm/types/4_inline_query_result_cached_photo.d.ts +0 -16
- package/esm/types/4_inline_query_result_cached_photo.js +0 -1
- package/esm/types/4_inline_query_result_cached_sticker.d.ts +0 -9
- package/esm/types/4_inline_query_result_cached_sticker.js +0 -1
- package/esm/types/4_inline_query_result_cached_video.d.ts +0 -16
- package/esm/types/4_inline_query_result_cached_video.js +0 -1
- package/esm/types/4_inline_query_result_cached_voice.d.ts +0 -15
- package/esm/types/4_inline_query_result_cached_voice.js +0 -1
- package/esm/types/4_inline_query_result_contact.d.ts +0 -15
- package/esm/types/4_inline_query_result_contact.js +0 -1
- package/esm/types/4_inline_query_result_document.d.ts +0 -18
- package/esm/types/4_inline_query_result_document.js +0 -1
- package/esm/types/4_inline_query_result_game.d.ts +0 -7
- package/esm/types/4_inline_query_result_game.js +0 -1
- package/esm/types/4_inline_query_result_gif.d.ts +0 -20
- package/esm/types/4_inline_query_result_gif.js +0 -1
- package/esm/types/4_inline_query_result_location.d.ts +0 -18
- package/esm/types/4_inline_query_result_location.js +0 -1
- package/esm/types/4_inline_query_result_mpeg4_gif.d.ts +0 -20
- package/esm/types/4_inline_query_result_mpeg4_gif.js +0 -1
- package/esm/types/4_inline_query_result_photo.d.ts +0 -19
- package/esm/types/4_inline_query_result_photo.js +0 -1
- package/esm/types/4_inline_query_result_venue.d.ts +0 -19
- package/esm/types/4_inline_query_result_venue.js +0 -1
- package/esm/types/4_inline_query_result_video.d.ts +0 -21
- package/esm/types/4_inline_query_result_video.js +0 -1
- package/esm/types/4_inline_query_result_voice.d.ts +0 -16
- package/esm/types/4_inline_query_result_voice.js +0 -1
- package/esm/types/4_reply_markup.d.ts +0 -7
- package/esm/types/4_reply_markup.js +0 -22
- package/esm/types/5_inline_query_result.d.ts +0 -28
- package/script/types/0_chat_id.d.ts +0 -4
- package/script/types/0_force_reply.d.ts +0 -12
- package/script/types/0_force_reply.js +0 -22
- package/script/types/0_input_contact_message_content.d.ts +0 -11
- package/script/types/0_input_location_message_content.d.ts +0 -15
- package/script/types/0_input_venue_message_content.d.ts +0 -19
- package/script/types/0_reply_keyboard_remove.d.ts +0 -10
- package/script/types/0_reply_keyboard_remove.js +0 -13
- package/script/types/1_input_invoice_message_content.d.ts +0 -23
- package/script/types/1_input_text_message_content.d.ts +0 -8
- package/script/types/1_input_text_message_content.js +0 -2
- package/script/types/2_input_message_content.d.ts +0 -6
- package/script/types/2_input_message_content.js +0 -2
- package/script/types/2_reply_keyboard_markup.d.ts +0 -12
- package/script/types/2_reply_keyboard_markup.js +0 -42
- package/script/types/3_inline_keyboard_markup.d.ts +0 -8
- package/script/types/3_inline_keyboard_markup.js +0 -29
- package/script/types/4_inline_query_result_article.d.ts +0 -15
- package/script/types/4_inline_query_result_article.js +0 -2
- package/script/types/4_inline_query_result_audio.d.ts +0 -17
- package/script/types/4_inline_query_result_audio.js +0 -2
- package/script/types/4_inline_query_result_cached_audio.d.ts +0 -14
- package/script/types/4_inline_query_result_cached_audio.js +0 -2
- package/script/types/4_inline_query_result_cached_document.d.ts +0 -15
- package/script/types/4_inline_query_result_cached_document.js +0 -2
- package/script/types/4_inline_query_result_cached_gif.d.ts +0 -15
- package/script/types/4_inline_query_result_cached_gif.js +0 -2
- package/script/types/4_inline_query_result_cached_mpeg4_gif.d.ts +0 -15
- package/script/types/4_inline_query_result_cached_mpeg4_gif.js +0 -2
- package/script/types/4_inline_query_result_cached_photo.d.ts +0 -16
- package/script/types/4_inline_query_result_cached_photo.js +0 -2
- package/script/types/4_inline_query_result_cached_sticker.d.ts +0 -9
- package/script/types/4_inline_query_result_cached_sticker.js +0 -2
- package/script/types/4_inline_query_result_cached_video.d.ts +0 -16
- package/script/types/4_inline_query_result_cached_video.js +0 -2
- package/script/types/4_inline_query_result_cached_voice.d.ts +0 -15
- package/script/types/4_inline_query_result_cached_voice.js +0 -2
- package/script/types/4_inline_query_result_contact.d.ts +0 -15
- package/script/types/4_inline_query_result_contact.js +0 -2
- package/script/types/4_inline_query_result_document.d.ts +0 -18
- package/script/types/4_inline_query_result_document.js +0 -2
- package/script/types/4_inline_query_result_game.d.ts +0 -7
- package/script/types/4_inline_query_result_game.js +0 -2
- package/script/types/4_inline_query_result_gif.d.ts +0 -20
- package/script/types/4_inline_query_result_gif.js +0 -2
- package/script/types/4_inline_query_result_location.d.ts +0 -18
- package/script/types/4_inline_query_result_location.js +0 -2
- package/script/types/4_inline_query_result_mpeg4_gif.d.ts +0 -20
- package/script/types/4_inline_query_result_mpeg4_gif.js +0 -2
- package/script/types/4_inline_query_result_photo.d.ts +0 -19
- package/script/types/4_inline_query_result_photo.js +0 -2
- package/script/types/4_inline_query_result_venue.d.ts +0 -19
- package/script/types/4_inline_query_result_venue.js +0 -2
- package/script/types/4_inline_query_result_video.d.ts +0 -21
- package/script/types/4_inline_query_result_video.js +0 -2
- package/script/types/4_inline_query_result_voice.d.ts +0 -16
- package/script/types/4_inline_query_result_voice.js +0 -2
- package/script/types/4_reply_markup.d.ts +0 -7
- package/script/types/4_reply_markup.js +0 -26
- package/script/types/5_inline_query_result.d.ts +0 -28
- /package/esm/{client/3_params.js → _dnt.polyfills.js} +0 -0
- /package/esm/{types/0_chat_id.js → client/0_params.js} +0 -0
- /package/esm/types/{0_input_contact_message_content.js → 0_chat_member_rights.js} +0 -0
- /package/esm/types/{0_input_location_message_content.js → 0_file_source.js} +0 -0
- /package/esm/types/{0_input_venue_message_content.js → 0_id.js} +0 -0
- /package/esm/types/{1_input_invoice_message_content.js → 1_input_message_content.js} +0 -0
- /package/script/{client/3_params.js → _dnt.polyfills.js} +0 -0
- /package/script/{types/0_chat_id.js → client/0_params.js} +0 -0
- /package/script/types/{0_input_contact_message_content.js → 0_chat_member_rights.js} +0 -0
- /package/script/types/{0_input_location_message_content.js → 0_file_source.js} +0 -0
- /package/script/types/{0_input_venue_message_content.js → 0_id.js} +0 -0
- /package/script/types/{1_input_invoice_message_content.js → 1_input_message_content.js} +0 -0
package/esm/client/4_client.js
CHANGED
|
@@ -9,38 +9,38 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
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");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _Client_instances,
|
|
13
|
-
import {
|
|
14
|
-
import { bigIntFromBuffer, cleanObject, drop, getRandomBigInt, getRandomId,
|
|
15
|
-
import { as, functions, getChannelChatId,
|
|
12
|
+
var _Client_instances, _Client_auth, _Client_sessionId, _Client_state, _Client_promises, _Client_toAcknowledge, _Client_guaranteeUpdateDelivery, _Client_updateManager, _Client_fileManager, _Client_messageManager, _Client_chatListManager, _Client_reactionManager, _Client_parseMode, _Client_publicKeys, _Client_autoStart, _Client_ignoreOutgoing, _Client_prefixes, _Client_namespaceProxies, _Client_constructContext, _Client_propagateConnectionState, _Client_lastPropagatedConnectionState, _Client_storageInited, _Client_setAuth, _Client_authKeyWasCreated, _Client_connectMutex, _Client_connectionInited, _Client_initConnection, _Client_lastPropagatedAuthorizationState, _Client_propagateAuthorizationState, _Client_selfId, _Client_getSelfId, _Client_receiveLoop, _Client_pingLoopAbortSignal, _Client_pingInterval, _Client_lastUpdates, _Client_pingLoop, _Client_pingLoopStarted, _Client_autoStarted, _Client_lastMsgId, _Client_invoke, _Client_handleInvokeError, _Client_getUserAccessHash, _Client_getChannelAccessHash, _Client_getInputPeerInner, _Client_parseText, _Client_lastGetMe, _Client_getMe, _Client_handleCtxUpdate, _Client_queueHandleCtxUpdate, _Client_handleUpdate, _Client_usernameResolver, _Client_handle, _Client_setMyInfo, _Client_getMyInfo;
|
|
13
|
+
import { debug, gunzip, Mutex } from "../0_deps.js";
|
|
14
|
+
import { bigIntFromBuffer, cleanObject, drop, getRandomBigInt, getRandomId, mustPrompt, mustPromptOneOf, sha1, toUnixTimestamp, UNREACHABLE, ZERO_CHANNEL_ID } from "../1_utilities.js";
|
|
15
|
+
import { as, functions, getChannelChatId, Message_, MessageContainer, name, peerToChatId, RPCResult, TLError, TLReader, types } from "../2_tl.js";
|
|
16
16
|
import { StorageMemory } from "../3_storage.js";
|
|
17
|
-
import {
|
|
18
|
-
import { ACK_THRESHOLD, APP_VERSION,
|
|
17
|
+
import { botCommandScopeToTlObject, constructCallbackQuery, constructChat2, constructChat3, constructChosenInlineResult, constructInlineQuery, constructMessageReaction, constructMessageReactionCount, constructMessageReactions, constructUser, inlineQueryResultToTlObject, messageEntityToTlObject } from "../3_types.js";
|
|
18
|
+
import { ACK_THRESHOLD, APP_VERSION, DEVICE_MODEL, LANG_CODE, LANG_PACK, LAYER, MAX_CHANNEL_ID, MAX_CHAT_ID, SYSTEM_LANG_CODE, SYSTEM_VERSION, USERNAME_TTL } from "../4_constants.js";
|
|
19
19
|
import { AuthKeyUnregistered, FloodWait, Migrate, PasswordHashInvalid, PhoneNumberInvalid, SessionPasswordNeeded, upgradeInstance } from "../4_errors.js";
|
|
20
20
|
import { ClientAbstract } from "./0_client_abstract.js";
|
|
21
|
+
import { match } from "./0_filters.js";
|
|
21
22
|
import { parseHtml } from "./0_html.js";
|
|
22
23
|
import { decryptMessage, encryptMessage, getMessageId } from "./0_message.js";
|
|
23
24
|
import { checkPassword } from "./0_password.js";
|
|
24
|
-
import {
|
|
25
|
+
import { ConnectionError } from "./0_types.js";
|
|
26
|
+
import { getFileContents, getUsername, resolve } from "./0_utilities.js";
|
|
25
27
|
import { Composer, concat, flatten, skip } from "./1_composer.js";
|
|
28
|
+
import { FileManager } from "./1_file_manager.js";
|
|
29
|
+
import { UpdateManager } from "./1_update_manager.js";
|
|
26
30
|
import { ClientPlain } from "./2_client_plain.js";
|
|
31
|
+
import { MessageManager } from "./2_message_manager.js";
|
|
32
|
+
import { ChatListManager } from "./3_chat_list_manager.js";
|
|
33
|
+
import { ReactionManager } from "./3_reaction_manager.js";
|
|
27
34
|
const d = debug("Client");
|
|
28
|
-
const dGap = debug("Client/recoverUpdateGap");
|
|
29
|
-
const dGapC = debug("Client/recoverChannelUpdateGap");
|
|
30
35
|
const dAuth = debug("Client/authorize");
|
|
31
36
|
const dRecv = debug("Client/receiveLoop");
|
|
32
|
-
const dUpload = debug("Client/upload");
|
|
33
37
|
const getEntity = Symbol();
|
|
34
|
-
const getStickerSetName = Symbol();
|
|
35
38
|
export const handleMigrationError = Symbol();
|
|
36
|
-
const getMessageWithReply = Symbol();
|
|
37
39
|
const functionNamespaces = Object.entries(functions).filter(([, v]) => !(v instanceof Function)).map(([k]) => k);
|
|
38
40
|
export function skipInvoke() {
|
|
39
41
|
return (_ctx, next) => next();
|
|
40
42
|
}
|
|
41
43
|
export const restartAuth = Symbol();
|
|
42
|
-
export class ConnectionError extends Error {
|
|
43
|
-
}
|
|
44
44
|
export class Client extends ClientAbstract {
|
|
45
45
|
/**
|
|
46
46
|
* Constructs the client.
|
|
@@ -69,20 +69,19 @@ export class Client extends ClientAbstract {
|
|
|
69
69
|
_Client_state.set(this, { salt: 0n, seqNo: 0 });
|
|
70
70
|
_Client_promises.set(this, new Map());
|
|
71
71
|
_Client_toAcknowledge.set(this, new Set());
|
|
72
|
-
_Client_updateState.set(this, void 0);
|
|
73
72
|
_Client_guaranteeUpdateDelivery.set(this, void 0);
|
|
73
|
+
_Client_updateManager.set(this, void 0);
|
|
74
|
+
_Client_fileManager.set(this, void 0);
|
|
75
|
+
_Client_messageManager.set(this, void 0);
|
|
76
|
+
_Client_chatListManager.set(this, void 0);
|
|
77
|
+
_Client_reactionManager.set(this, void 0);
|
|
74
78
|
Object.defineProperty(this, "storage", {
|
|
75
79
|
enumerable: true,
|
|
76
80
|
configurable: true,
|
|
77
81
|
writable: true,
|
|
78
82
|
value: void 0
|
|
79
83
|
});
|
|
80
|
-
|
|
81
|
-
enumerable: true,
|
|
82
|
-
configurable: true,
|
|
83
|
-
writable: true,
|
|
84
|
-
value: void 0
|
|
85
|
-
});
|
|
84
|
+
_Client_parseMode.set(this, void 0);
|
|
86
85
|
Object.defineProperty(this, "appVersion", {
|
|
87
86
|
enumerable: true,
|
|
88
87
|
configurable: true,
|
|
@@ -184,7 +183,7 @@ export class Client extends ClientAbstract {
|
|
|
184
183
|
const reactions = "messageInteractions" in update ? update.messageInteractions : undefined;
|
|
185
184
|
const mustGetMsg = () => {
|
|
186
185
|
if (msg !== undefined) {
|
|
187
|
-
return { chatId: msg.chat.id, messageId: msg.id };
|
|
186
|
+
return { chatId: msg.chat.id, messageId: msg.id, senderId: (msg.from ?? msg.senderChat)?.id };
|
|
188
187
|
}
|
|
189
188
|
else if (reactions !== undefined) {
|
|
190
189
|
return { chatId: reactions.chatId, messageId: reactions.messageId };
|
|
@@ -193,7 +192,8 @@ export class Client extends ClientAbstract {
|
|
|
193
192
|
UNREACHABLE();
|
|
194
193
|
}
|
|
195
194
|
};
|
|
196
|
-
const
|
|
195
|
+
const chat_ = "messageReactions" in update ? update.messageReactions.chat : "messageReactionCount" in update ? update.messageReactionCount.chat : undefined;
|
|
196
|
+
const chat = chat_ ?? msg?.chat;
|
|
197
197
|
const from = "callbackQuery" in update ? update.callbackQuery.from : "inlineQuery" in update ? update.inlineQuery.from : "message" in update ? update.message.from : "editedMessage" in update ? update.editedMessage?.from : undefined;
|
|
198
198
|
const senderChat = msg?.senderChat;
|
|
199
199
|
const getReplyToMessageId = (quote, chatId, messageId) => {
|
|
@@ -287,6 +287,35 @@ export class Client extends ClientAbstract {
|
|
|
287
287
|
const { chatId, messageId } = mustGetMsg();
|
|
288
288
|
return this.forwardMessage(chatId, to, messageId, params);
|
|
289
289
|
},
|
|
290
|
+
pin: (params) => {
|
|
291
|
+
const { chatId, messageId } = mustGetMsg();
|
|
292
|
+
return this.pinMessage(chatId, messageId, params);
|
|
293
|
+
},
|
|
294
|
+
unpin: () => {
|
|
295
|
+
const { chatId, messageId } = mustGetMsg();
|
|
296
|
+
return this.unpinMessage(chatId, messageId);
|
|
297
|
+
},
|
|
298
|
+
banSender: (params) => {
|
|
299
|
+
const { chatId, senderId } = mustGetMsg();
|
|
300
|
+
if (!senderId) {
|
|
301
|
+
UNREACHABLE();
|
|
302
|
+
}
|
|
303
|
+
return this.banChatMember(chatId, senderId, params);
|
|
304
|
+
},
|
|
305
|
+
kickSender: () => {
|
|
306
|
+
const { chatId, senderId } = mustGetMsg();
|
|
307
|
+
if (!senderId) {
|
|
308
|
+
UNREACHABLE();
|
|
309
|
+
}
|
|
310
|
+
return this.kickChatMember(chatId, senderId);
|
|
311
|
+
},
|
|
312
|
+
setSenderRights: (params) => {
|
|
313
|
+
const { chatId, senderId } = mustGetMsg();
|
|
314
|
+
if (!senderId) {
|
|
315
|
+
UNREACHABLE();
|
|
316
|
+
}
|
|
317
|
+
return this.setChatMemberRights(chatId, senderId, params);
|
|
318
|
+
},
|
|
290
319
|
react: (reactions, params) => {
|
|
291
320
|
const { chatId, messageId } = mustGetMsg();
|
|
292
321
|
return this.setReactions(chatId, messageId, reactions, params);
|
|
@@ -311,6 +340,10 @@ export class Client extends ClientAbstract {
|
|
|
311
340
|
const { chatId } = mustGetMsg();
|
|
312
341
|
return this.editMessageText(chatId, messageId, text, params);
|
|
313
342
|
},
|
|
343
|
+
editMessageReplyMarkup: (messageId, params) => {
|
|
344
|
+
const { chatId } = mustGetMsg();
|
|
345
|
+
return this.editMessageReplyMarkup(chatId, messageId, params);
|
|
346
|
+
},
|
|
314
347
|
getMessage: (messageId) => {
|
|
315
348
|
const { chatId } = mustGetMsg();
|
|
316
349
|
return this.getMessage(chatId, messageId);
|
|
@@ -335,6 +368,18 @@ export class Client extends ClientAbstract {
|
|
|
335
368
|
const { chatId } = mustGetMsg();
|
|
336
369
|
return this.deleteMessages(chatId, messageIds, params);
|
|
337
370
|
},
|
|
371
|
+
pinMessage: (messageId, params) => {
|
|
372
|
+
const { chatId } = mustGetMsg();
|
|
373
|
+
return this.pinMessage(chatId, messageId, params);
|
|
374
|
+
},
|
|
375
|
+
unpinMessage: (messageId) => {
|
|
376
|
+
const { chatId } = mustGetMsg();
|
|
377
|
+
return this.unpinMessage(chatId, messageId);
|
|
378
|
+
},
|
|
379
|
+
unpinMessages: () => {
|
|
380
|
+
const { chatId } = mustGetMsg();
|
|
381
|
+
return this.unpinMessages(chatId);
|
|
382
|
+
},
|
|
338
383
|
setAvailableReactions: (availableReactions) => {
|
|
339
384
|
const { chatId } = mustGetMsg();
|
|
340
385
|
return this.setAvailableReactions(chatId, availableReactions);
|
|
@@ -351,8 +396,36 @@ export class Client extends ClientAbstract {
|
|
|
351
396
|
const { chatId } = mustGetMsg();
|
|
352
397
|
return this.setReactions(chatId, messageId, reactions, params);
|
|
353
398
|
},
|
|
399
|
+
setChatPhoto: (photo, params) => {
|
|
400
|
+
const { chatId } = mustGetMsg();
|
|
401
|
+
return this.setChatPhoto(chatId, photo, params);
|
|
402
|
+
},
|
|
403
|
+
deleteChatPhoto: () => {
|
|
404
|
+
const { chatId } = mustGetMsg();
|
|
405
|
+
return this.deleteChatPhoto(chatId);
|
|
406
|
+
},
|
|
407
|
+
banChatMember: (memberId, params) => {
|
|
408
|
+
const { chatId } = mustGetMsg();
|
|
409
|
+
return this.banChatMember(chatId, memberId, params);
|
|
410
|
+
},
|
|
411
|
+
unbanChatMember: (memberId) => {
|
|
412
|
+
const { chatId } = mustGetMsg();
|
|
413
|
+
return this.unbanChatMember(chatId, memberId);
|
|
414
|
+
},
|
|
415
|
+
kickChatMember: (memberId) => {
|
|
416
|
+
const { chatId } = mustGetMsg();
|
|
417
|
+
return this.kickChatMember(chatId, memberId);
|
|
418
|
+
},
|
|
419
|
+
setChatMemberRights: (memberId, params) => {
|
|
420
|
+
const { chatId } = mustGetMsg();
|
|
421
|
+
return this.setChatMemberRights(chatId, memberId, params);
|
|
422
|
+
},
|
|
423
|
+
deleteChatMemberMessages: (userId) => {
|
|
424
|
+
const { chatId } = mustGetMsg();
|
|
425
|
+
return this.deleteChatMemberMessages(chatId, userId);
|
|
426
|
+
},
|
|
354
427
|
};
|
|
355
|
-
return cleanObject(context
|
|
428
|
+
return cleanObject(context);
|
|
356
429
|
});
|
|
357
430
|
_Client_lastPropagatedConnectionState.set(this, null);
|
|
358
431
|
Object.defineProperty(this, "stateChangeHandler", {
|
|
@@ -381,6 +454,7 @@ export class Client extends ClientAbstract {
|
|
|
381
454
|
_Client_selfId.set(this, null);
|
|
382
455
|
_Client_pingLoopAbortSignal.set(this, null);
|
|
383
456
|
_Client_pingInterval.set(this, 60 * 1000); // 60 seconds
|
|
457
|
+
_Client_lastUpdates.set(this, new Date());
|
|
384
458
|
_Client_pingLoopStarted.set(this, false);
|
|
385
459
|
_Client_autoStarted.set(this, false);
|
|
386
460
|
_Client_lastMsgId.set(this, 0n);
|
|
@@ -410,29 +484,15 @@ export class Client extends ClientAbstract {
|
|
|
410
484
|
},
|
|
411
485
|
})
|
|
412
486
|
});
|
|
413
|
-
_Client_handleUpdateQueues.set(this, new Map());
|
|
414
|
-
_Client_processUpdatesQueue.set(this, new Queue("processUpdates"));
|
|
415
|
-
_Client_channelUpdateQueues.set(this, new Map());
|
|
416
|
-
_Client_mainBoxId.set(this, 0n);
|
|
417
|
-
_Client_ptsUpdateQueue.set(this, new Queue("ptsUpdate"));
|
|
418
|
-
_Client_lastUpdates.set(this, new Date());
|
|
419
487
|
_Client_lastGetMe.set(this, null);
|
|
420
|
-
_Client_handleUpdatesSet.set(this, new Set());
|
|
421
488
|
_Client_usernameResolver.set(this, async (v) => {
|
|
422
489
|
const inputPeer = await this.getInputPeer(v).then((v) => v[as](types.InputPeerUser));
|
|
423
490
|
return new types.InputUser(inputPeer);
|
|
424
491
|
});
|
|
425
492
|
//#region Composer
|
|
426
493
|
_Client_handle.set(this, skip);
|
|
427
|
-
_Client_chats.set(this, new Map());
|
|
428
|
-
_Client_archivedChats.set(this, new Map());
|
|
429
|
-
_Client_chatsLoadedFromStorage.set(this, false);
|
|
430
|
-
_Client_pinnedChats.set(this, new Array());
|
|
431
|
-
_Client_pinnedArchiveChats.set(this, new Array());
|
|
432
|
-
_Client_storageHadPinnedChats.set(this, false);
|
|
433
|
-
_Client_pinnedChatsLoaded.set(this, false);
|
|
434
494
|
this.storage = storage ?? new StorageMemory();
|
|
435
|
-
this
|
|
495
|
+
__classPrivateFieldSet(this, _Client_parseMode, params?.parseMode ?? null, "f");
|
|
436
496
|
this.appVersion = params?.appVersion ?? APP_VERSION;
|
|
437
497
|
this.deviceModel = params?.deviceModel ?? DEVICE_MODEL;
|
|
438
498
|
this.langCode = params?.langCode ?? LANG_CODE;
|
|
@@ -444,6 +504,67 @@ export class Client extends ClientAbstract {
|
|
|
444
504
|
__classPrivateFieldSet(this, _Client_ignoreOutgoing, params?.ignoreOutgoing ?? null, "f");
|
|
445
505
|
__classPrivateFieldSet(this, _Client_prefixes, params?.prefixes, "f");
|
|
446
506
|
__classPrivateFieldSet(this, _Client_guaranteeUpdateDelivery, params?.guaranteeUpdateDelivery ?? false, "f");
|
|
507
|
+
const c = {
|
|
508
|
+
api: this.api,
|
|
509
|
+
storage: this.storage,
|
|
510
|
+
guaranteeUpdateDelivery: __classPrivateFieldGet(this, _Client_guaranteeUpdateDelivery, "f"),
|
|
511
|
+
setConnectionState: __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateConnectionState).bind(this),
|
|
512
|
+
resetConnectionState: () => this.stateChangeHandler(this.connected),
|
|
513
|
+
getSelfId: __classPrivateFieldGet(this, _Client_instances, "m", _Client_getSelfId).bind(this),
|
|
514
|
+
getInputPeer: this.getInputPeer.bind(this),
|
|
515
|
+
getEntity: this[getEntity].bind(this),
|
|
516
|
+
handleUpdate: __classPrivateFieldGet(this, _Client_instances, "m", _Client_queueHandleCtxUpdate).bind(this),
|
|
517
|
+
parseMode: __classPrivateFieldGet(this, _Client_parseMode, "f"),
|
|
518
|
+
apiFactory: (dcId) => {
|
|
519
|
+
const client = new Client((!dcId || dcId == this.dcId) ? this.storage : this.storage.branch(`download_client_${dcId}`), this.apiId, this.apiHash, {
|
|
520
|
+
transportProvider: this.transportProvider,
|
|
521
|
+
appVersion: this.appVersion,
|
|
522
|
+
deviceModel: this.deviceModel,
|
|
523
|
+
langCode: this.langCode,
|
|
524
|
+
langPack: this.langPack,
|
|
525
|
+
systemLangCode: this.systemLangCode,
|
|
526
|
+
systemVersion: this.systemVersion,
|
|
527
|
+
cdn: true,
|
|
528
|
+
});
|
|
529
|
+
__classPrivateFieldGet(client, _Client_state, "f").salt = __classPrivateFieldGet(this, _Client_state, "f").salt;
|
|
530
|
+
client.invoke.use(async (ctx, next) => {
|
|
531
|
+
if (ctx.error instanceof AuthKeyUnregistered && dcId) {
|
|
532
|
+
try {
|
|
533
|
+
const exportedAuth = await this.api.auth.exportAuthorization({ dc_id: dcId });
|
|
534
|
+
await client.authorize(exportedAuth);
|
|
535
|
+
return true;
|
|
536
|
+
}
|
|
537
|
+
catch (err) {
|
|
538
|
+
throw err;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
else {
|
|
542
|
+
return await next();
|
|
543
|
+
}
|
|
544
|
+
});
|
|
545
|
+
return {
|
|
546
|
+
api: client.api,
|
|
547
|
+
connect: async () => {
|
|
548
|
+
await client.connect();
|
|
549
|
+
if (dcId != this.dcId) {
|
|
550
|
+
let dc = String(dcId);
|
|
551
|
+
if (this.dcId < 0) {
|
|
552
|
+
dc += "-test";
|
|
553
|
+
}
|
|
554
|
+
await client.setDc(dc);
|
|
555
|
+
}
|
|
556
|
+
await __classPrivateFieldGet(client, _Client_instances, "m", _Client_initConnection).call(client);
|
|
557
|
+
},
|
|
558
|
+
disconnect: client.disconnect.bind(client),
|
|
559
|
+
};
|
|
560
|
+
},
|
|
561
|
+
};
|
|
562
|
+
__classPrivateFieldSet(this, _Client_updateManager, new UpdateManager(c), "f");
|
|
563
|
+
__classPrivateFieldSet(this, _Client_fileManager, new FileManager(c), "f");
|
|
564
|
+
__classPrivateFieldSet(this, _Client_messageManager, new MessageManager({ ...c, fileManager: __classPrivateFieldGet(this, _Client_fileManager, "f") }), "f");
|
|
565
|
+
__classPrivateFieldSet(this, _Client_chatListManager, new ChatListManager({ ...c, messageManager: __classPrivateFieldGet(this, _Client_messageManager, "f") }), "f");
|
|
566
|
+
__classPrivateFieldSet(this, _Client_reactionManager, new ReactionManager({ ...c, messageManager: __classPrivateFieldGet(this, _Client_messageManager, "f") }), "f");
|
|
567
|
+
__classPrivateFieldGet(this, _Client_updateManager, "f").setUpdateHandler(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleUpdate).bind(this));
|
|
447
568
|
const transportProvider = this.transportProvider;
|
|
448
569
|
this.transportProvider = (params) => {
|
|
449
570
|
const transport = transportProvider(params);
|
|
@@ -473,7 +594,7 @@ export class Client extends ClientAbstract {
|
|
|
473
594
|
try {
|
|
474
595
|
await this.connect();
|
|
475
596
|
d("reconnected");
|
|
476
|
-
drop(__classPrivateFieldGet(this,
|
|
597
|
+
drop(__classPrivateFieldGet(this, _Client_updateManager, "f").recoverUpdateGap("reconnect"));
|
|
477
598
|
break;
|
|
478
599
|
}
|
|
479
600
|
catch (err) {
|
|
@@ -576,27 +697,13 @@ export class Client extends ClientAbstract {
|
|
|
576
697
|
release();
|
|
577
698
|
}
|
|
578
699
|
}
|
|
579
|
-
async [(_Client_auth = new WeakMap(), _Client_sessionId = new WeakMap(), _Client_state = new WeakMap(), _Client_promises = new WeakMap(), _Client_toAcknowledge = new WeakMap(),
|
|
580
|
-
__classPrivateFieldGet(this, _Client_instances, "m",
|
|
581
|
-
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { connectionState }), resolve);
|
|
582
|
-
});
|
|
700
|
+
async [(_Client_auth = new WeakMap(), _Client_sessionId = new WeakMap(), _Client_state = new WeakMap(), _Client_promises = new WeakMap(), _Client_toAcknowledge = new WeakMap(), _Client_guaranteeUpdateDelivery = new WeakMap(), _Client_updateManager = new WeakMap(), _Client_fileManager = new WeakMap(), _Client_messageManager = new WeakMap(), _Client_chatListManager = new WeakMap(), _Client_reactionManager = new WeakMap(), _Client_parseMode = new WeakMap(), _Client_publicKeys = new WeakMap(), _Client_autoStart = new WeakMap(), _Client_ignoreOutgoing = new WeakMap(), _Client_prefixes = new WeakMap(), _Client_namespaceProxies = new WeakMap(), _Client_constructContext = new WeakMap(), _Client_lastPropagatedConnectionState = new WeakMap(), _Client_storageInited = new WeakMap(), _Client_authKeyWasCreated = new WeakMap(), _Client_connectMutex = new WeakMap(), _Client_connectionInited = new WeakMap(), _Client_lastPropagatedAuthorizationState = new WeakMap(), _Client_selfId = new WeakMap(), _Client_pingLoopAbortSignal = new WeakMap(), _Client_pingInterval = new WeakMap(), _Client_lastUpdates = new WeakMap(), _Client_pingLoopStarted = new WeakMap(), _Client_autoStarted = new WeakMap(), _Client_lastMsgId = new WeakMap(), _Client_handleInvokeError = new WeakMap(), _Client_lastGetMe = new WeakMap(), _Client_usernameResolver = new WeakMap(), _Client_handle = new WeakMap(), _Client_instances = new WeakSet(), _Client_propagateConnectionState = function _Client_propagateConnectionState(connectionState) {
|
|
701
|
+
__classPrivateFieldGet(this, _Client_instances, "m", _Client_queueHandleCtxUpdate).call(this, { connectionState });
|
|
583
702
|
__classPrivateFieldSet(this, _Client_lastPropagatedConnectionState, connectionState, "f");
|
|
584
703
|
}, _Client_setAuth = async function _Client_setAuth(key) {
|
|
585
704
|
const hash = await sha1(key);
|
|
586
705
|
const id = bigIntFromBuffer(hash.slice(-8), true, false);
|
|
587
706
|
__classPrivateFieldSet(this, _Client_auth, { key, id }, "f");
|
|
588
|
-
}, _Client_assertUser = async function _Client_assertUser(source) {
|
|
589
|
-
if (await this.storage.getAccountType() != "user") {
|
|
590
|
-
throw new Error(`${source}: not user a client`);
|
|
591
|
-
}
|
|
592
|
-
}, _Client_assertBot = async function _Client_assertBot(source) {
|
|
593
|
-
if (await this.storage.getAccountType() != "bot") {
|
|
594
|
-
throw new Error(`${source}: not a bot client`);
|
|
595
|
-
}
|
|
596
|
-
}, _Client_fetchState = async function _Client_fetchState(source) {
|
|
597
|
-
const state = await this.api.updates.getState();
|
|
598
|
-
__classPrivateFieldSet(this, _Client_updateState, state, "f");
|
|
599
|
-
d("state fetched [%s]", source);
|
|
600
707
|
}, handleMigrationError)](err) {
|
|
601
708
|
let newDc = String(err.dc);
|
|
602
709
|
if (Math.abs(this.dcId) >= 10000) {
|
|
@@ -646,9 +753,9 @@ export class Client extends ClientAbstract {
|
|
|
646
753
|
dAuth("authorizing with %s", typeof params === "string" ? "bot token" : params instanceof types.auth.ExportedAuthorization ? "exported authorization" : "AuthorizeUserParams");
|
|
647
754
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_initConnection).call(this);
|
|
648
755
|
try {
|
|
649
|
-
await __classPrivateFieldGet(this,
|
|
756
|
+
await __classPrivateFieldGet(this, _Client_updateManager, "f").fetchState("authorize");
|
|
650
757
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateAuthorizationState).call(this, true);
|
|
651
|
-
drop(__classPrivateFieldGet(this,
|
|
758
|
+
drop(__classPrivateFieldGet(this, _Client_updateManager, "f").recoverUpdateGap("authorize"));
|
|
652
759
|
d("already authorized");
|
|
653
760
|
return;
|
|
654
761
|
}
|
|
@@ -678,7 +785,7 @@ export class Client extends ClientAbstract {
|
|
|
678
785
|
}
|
|
679
786
|
dAuth("authorized as bot");
|
|
680
787
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateAuthorizationState).call(this, true);
|
|
681
|
-
await __classPrivateFieldGet(this,
|
|
788
|
+
await __classPrivateFieldGet(this, _Client_updateManager, "f").fetchState("authorize");
|
|
682
789
|
return;
|
|
683
790
|
}
|
|
684
791
|
if (params instanceof types.auth.ExportedAuthorization) {
|
|
@@ -737,7 +844,7 @@ export class Client extends ClientAbstract {
|
|
|
737
844
|
await this.storage.setAccountType("user");
|
|
738
845
|
dAuth("authorized as user");
|
|
739
846
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateAuthorizationState).call(this, true);
|
|
740
|
-
await __classPrivateFieldGet(this,
|
|
847
|
+
await __classPrivateFieldGet(this, _Client_updateManager, "f").fetchState("authorize");
|
|
741
848
|
return;
|
|
742
849
|
}
|
|
743
850
|
catch (err_) {
|
|
@@ -766,7 +873,7 @@ export class Client extends ClientAbstract {
|
|
|
766
873
|
await this.storage.setAccountType("user");
|
|
767
874
|
dAuth("authorized as user");
|
|
768
875
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateAuthorizationState).call(this, true);
|
|
769
|
-
await __classPrivateFieldGet(this,
|
|
876
|
+
await __classPrivateFieldGet(this, _Client_updateManager, "f").fetchState("authorize");
|
|
770
877
|
return;
|
|
771
878
|
}
|
|
772
879
|
catch (err) {
|
|
@@ -796,8 +903,8 @@ export class Client extends ClientAbstract {
|
|
|
796
903
|
await this.connect();
|
|
797
904
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_initConnection).call(this);
|
|
798
905
|
if (!__classPrivateFieldGet(this, _Client_authKeyWasCreated, "f")) {
|
|
799
|
-
drop(__classPrivateFieldGet(this,
|
|
800
|
-
drop(__classPrivateFieldGet(this,
|
|
906
|
+
drop(__classPrivateFieldGet(this, _Client_updateManager, "f").fetchState("start"));
|
|
907
|
+
drop(__classPrivateFieldGet(this, _Client_updateManager, "f").recoverUpdateGap("start"));
|
|
801
908
|
return;
|
|
802
909
|
}
|
|
803
910
|
await this.authorize(params);
|
|
@@ -808,10 +915,6 @@ export class Client extends ClientAbstract {
|
|
|
808
915
|
send(function_) {
|
|
809
916
|
return this.invoke(function_, true);
|
|
810
917
|
}
|
|
811
|
-
async getUserAccessHash(userId) {
|
|
812
|
-
const users = await this.api.users.getUsers({ id: [new types.InputUser({ user_id: userId, access_hash: 0n })] });
|
|
813
|
-
return users[0]?.[as](types.User).access_hash ?? 0n;
|
|
814
|
-
}
|
|
815
918
|
async getInputPeer(id) {
|
|
816
919
|
const inputPeer = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getInputPeerInner).call(this, id);
|
|
817
920
|
if ((inputPeer instanceof types.InputPeerUser || inputPeer instanceof types.InputPeerChannel && inputPeer.access_hash == 0n) && await this.storage.getAccountType() == "bot") {
|
|
@@ -819,7 +922,7 @@ export class Client extends ClientAbstract {
|
|
|
819
922
|
inputPeer.access_hash = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChannelAccessHash).call(this, inputPeer.channel_id);
|
|
820
923
|
}
|
|
821
924
|
else {
|
|
822
|
-
inputPeer.access_hash = await this.
|
|
925
|
+
inputPeer.access_hash = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getUserAccessHash).call(this, inputPeer.user_id);
|
|
823
926
|
await this.storage.setUserAccessHash(inputPeer.user_id, inputPeer.access_hash);
|
|
824
927
|
}
|
|
825
928
|
}
|
|
@@ -878,7 +981,7 @@ export class Client extends ClientAbstract {
|
|
|
878
981
|
//
|
|
879
982
|
}
|
|
880
983
|
await this.connect();
|
|
881
|
-
await __classPrivateFieldGet(this,
|
|
984
|
+
await __classPrivateFieldGet(this, _Client_updateManager, "f").recoverUpdateGap("decryption");
|
|
882
985
|
})());
|
|
883
986
|
continue;
|
|
884
987
|
}
|
|
@@ -890,7 +993,7 @@ export class Client extends ClientAbstract {
|
|
|
890
993
|
}
|
|
891
994
|
dRecv("received %s", (typeof body === "object" && name in body) ? body[name] : body.constructor.name);
|
|
892
995
|
if (body instanceof types._Updates || body instanceof types._Update) {
|
|
893
|
-
__classPrivateFieldGet(this,
|
|
996
|
+
__classPrivateFieldGet(this, _Client_updateManager, "f").processUpdates(body, true);
|
|
894
997
|
}
|
|
895
998
|
else if (body instanceof types.New_session_created) {
|
|
896
999
|
__classPrivateFieldGet(this, _Client_state, "f").salt = body.server_salt;
|
|
@@ -921,13 +1024,10 @@ export class Client extends ClientAbstract {
|
|
|
921
1024
|
}
|
|
922
1025
|
};
|
|
923
1026
|
if (result instanceof types._Updates || result instanceof types._Update) {
|
|
924
|
-
__classPrivateFieldGet(this,
|
|
925
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, result, true, promise?.call);
|
|
926
|
-
resolvePromise();
|
|
927
|
-
});
|
|
1027
|
+
__classPrivateFieldGet(this, _Client_updateManager, "f").processUpdates(result, true, promise?.call, resolvePromise);
|
|
928
1028
|
}
|
|
929
1029
|
else {
|
|
930
|
-
await this.processResult(result);
|
|
1030
|
+
await __classPrivateFieldGet(this, _Client_updateManager, "f").processResult(result);
|
|
931
1031
|
resolvePromise();
|
|
932
1032
|
}
|
|
933
1033
|
}
|
|
@@ -957,7 +1057,7 @@ export class Client extends ClientAbstract {
|
|
|
957
1057
|
}
|
|
958
1058
|
else if (err instanceof TLError) {
|
|
959
1059
|
dRecv("failed to deserialize: %o", err);
|
|
960
|
-
drop(__classPrivateFieldGet(this,
|
|
1060
|
+
drop(__classPrivateFieldGet(this, _Client_updateManager, "f").recoverUpdateGap("deserialize"));
|
|
961
1061
|
}
|
|
962
1062
|
else {
|
|
963
1063
|
dRecv("uncaught error: %o", err);
|
|
@@ -984,7 +1084,7 @@ export class Client extends ClientAbstract {
|
|
|
984
1084
|
});
|
|
985
1085
|
await this.api.ping_delay_disconnect({ ping_id: getRandomId(), disconnect_delay: __classPrivateFieldGet(this, _Client_pingInterval, "f") / 1000 + 15 });
|
|
986
1086
|
if (Date.now() - __classPrivateFieldGet(this, _Client_lastUpdates, "f").getTime() >= 15 * 60 * 1000) {
|
|
987
|
-
drop(__classPrivateFieldGet(this,
|
|
1087
|
+
drop(__classPrivateFieldGet(this, _Client_updateManager, "f").recoverUpdateGap("lastUpdates"));
|
|
988
1088
|
}
|
|
989
1089
|
}
|
|
990
1090
|
catch (err) {
|
|
@@ -1059,409 +1159,9 @@ export class Client extends ClientAbstract {
|
|
|
1059
1159
|
}
|
|
1060
1160
|
}
|
|
1061
1161
|
}
|
|
1062
|
-
},
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
await this.storage.setEntity(chat);
|
|
1066
|
-
await this.storage.setChannelAccessHash(chat.id, chat.access_hash);
|
|
1067
|
-
if (chat.username) {
|
|
1068
|
-
await this.storage.updateUsernames("channel", chat.id, [chat.username]);
|
|
1069
|
-
}
|
|
1070
|
-
if (chat.usernames) {
|
|
1071
|
-
await this.storage.updateUsernames("channel", chat.id, chat.usernames.map((v) => v.username));
|
|
1072
|
-
}
|
|
1073
|
-
}
|
|
1074
|
-
else if (chat instanceof types.Chat) {
|
|
1075
|
-
await this.storage.setEntity(chat);
|
|
1076
|
-
}
|
|
1077
|
-
else if (chat instanceof types.ChannelForbidden || chat instanceof types.ChatForbidden) {
|
|
1078
|
-
await this.storage.removeEntity(chat);
|
|
1079
|
-
}
|
|
1080
|
-
}
|
|
1081
|
-
}, _Client_processUsers = async function _Client_processUsers(users) {
|
|
1082
|
-
for (const user of users) {
|
|
1083
|
-
if (user instanceof types.User && user.access_hash) {
|
|
1084
|
-
await this.storage.setEntity(user);
|
|
1085
|
-
await this.storage.setUserAccessHash(user.id, user.access_hash);
|
|
1086
|
-
if (user.username) {
|
|
1087
|
-
await this.storage.updateUsernames("user", user.id, [user.username]);
|
|
1088
|
-
}
|
|
1089
|
-
if (user.usernames) {
|
|
1090
|
-
await this.storage.updateUsernames("user", user.id, user.usernames.map((v) => v.username));
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
}
|
|
1094
|
-
}, _Client_getHandleUpdateQueue = function _Client_getHandleUpdateQueue(boxId) {
|
|
1095
|
-
let queue = __classPrivateFieldGet(this, _Client_handleUpdateQueues, "f").get(boxId);
|
|
1096
|
-
if (queue !== undefined) {
|
|
1097
|
-
return queue;
|
|
1098
|
-
}
|
|
1099
|
-
else {
|
|
1100
|
-
queue = new Queue(`handleUpdate-${boxId}`);
|
|
1101
|
-
return queue;
|
|
1102
|
-
}
|
|
1103
|
-
}, _Client_checkGap = async function _Client_checkGap(pts, ptsCount) {
|
|
1104
|
-
const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
|
|
1105
|
-
if (localState.pts + ptsCount < pts) {
|
|
1106
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverUpdateGap).call(this, "processUpdates");
|
|
1107
|
-
}
|
|
1108
|
-
}, _Client_checkChannelGap = async function _Client_checkChannelGap(channelId, pts, ptsCount) {
|
|
1109
|
-
let localPts = await this.storage.getChannelPts(channelId);
|
|
1110
|
-
if (!localPts) {
|
|
1111
|
-
localPts = pts - ptsCount;
|
|
1112
|
-
}
|
|
1113
|
-
if (localPts + ptsCount < pts) {
|
|
1114
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverChannelUpdateGap).call(this, channelId, "processUpdates");
|
|
1115
|
-
}
|
|
1116
|
-
}, _Client_processChannelPtsUpdateInner = async function _Client_processChannelPtsUpdateInner(update, checkGap) {
|
|
1117
|
-
const channelId = update instanceof types.UpdateNewChannelMessage || update instanceof types.UpdateEditChannelMessage ? update.message.peer_id[as](types.PeerChannel).channel_id : update.channel_id;
|
|
1118
|
-
if (update instanceof types.UpdateChannelTooLong) {
|
|
1119
|
-
if (update.pts != undefined) {
|
|
1120
|
-
await this.storage.setChannelPts(channelId, update.pts);
|
|
1121
|
-
}
|
|
1122
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverChannelUpdateGap).call(this, channelId, "updateChannelTooLong");
|
|
1123
|
-
return;
|
|
1124
|
-
}
|
|
1125
|
-
if (update.pts != 0) {
|
|
1126
|
-
const ptsCount = update.pts_count;
|
|
1127
|
-
if (checkGap) {
|
|
1128
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_checkChannelGap).call(this, channelId, update.pts, ptsCount);
|
|
1129
|
-
}
|
|
1130
|
-
let currentPts = await this.storage.getChannelPts(channelId);
|
|
1131
|
-
currentPts ??= update.pts - ptsCount;
|
|
1132
|
-
if (currentPts + ptsCount > update.pts) {
|
|
1133
|
-
return;
|
|
1134
|
-
}
|
|
1135
|
-
}
|
|
1136
|
-
if (__classPrivateFieldGet(this, _Client_guaranteeUpdateDelivery, "f")) {
|
|
1137
|
-
await this.storage.setUpdate(channelId, update);
|
|
1138
|
-
}
|
|
1139
|
-
if (update.pts != 0) {
|
|
1140
|
-
await this.storage.setChannelPts(channelId, update.pts);
|
|
1141
|
-
}
|
|
1142
|
-
__classPrivateFieldGet(this, _Client_instances, "m", _Client_queueUpdate).call(this, update, channelId, true);
|
|
1143
|
-
}, _Client_queueUpdate = function _Client_queueUpdate(update, boxId, pts) {
|
|
1144
|
-
__classPrivateFieldGet(this, _Client_instances, "m", _Client_getHandleUpdateQueue).call(this, boxId).add(async () => {
|
|
1145
|
-
if (__classPrivateFieldGet(this, _Client_guaranteeUpdateDelivery, "f") && pts) {
|
|
1146
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleStoredUpdates).call(this, boxId);
|
|
1147
|
-
}
|
|
1148
|
-
else {
|
|
1149
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleUpdate).call(this, update);
|
|
1150
|
-
}
|
|
1151
|
-
});
|
|
1152
|
-
}, _Client_processChannelPtsUpdate = function _Client_processChannelPtsUpdate(update, checkGap) {
|
|
1153
|
-
const channelId = update instanceof types.UpdateNewChannelMessage || update instanceof types.UpdateEditChannelMessage ? update.message.peer_id[as](types.PeerChannel).channel_id : update.channel_id;
|
|
1154
|
-
let queue = __classPrivateFieldGet(this, _Client_channelUpdateQueues, "f").get(channelId);
|
|
1155
|
-
if (queue == undefined) {
|
|
1156
|
-
queue = new Queue(`channelUpdates-${channelId}`);
|
|
1157
|
-
__classPrivateFieldGet(this, _Client_channelUpdateQueues, "f").set(channelId, queue);
|
|
1158
|
-
}
|
|
1159
|
-
queue.add(async () => {
|
|
1160
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChannelPtsUpdateInner).call(this, update, checkGap);
|
|
1161
|
-
});
|
|
1162
|
-
}, _Client_processPtsUpdateInner = async function _Client_processPtsUpdateInner(update, checkGap) {
|
|
1163
|
-
const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
|
|
1164
|
-
if (update.pts != 0) {
|
|
1165
|
-
if (checkGap) {
|
|
1166
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_checkGap).call(this, update.pts, update.pts_count);
|
|
1167
|
-
}
|
|
1168
|
-
if (localState.pts + update.pts_count > update.pts) {
|
|
1169
|
-
return;
|
|
1170
|
-
}
|
|
1171
|
-
}
|
|
1172
|
-
if (__classPrivateFieldGet(this, _Client_guaranteeUpdateDelivery, "f")) {
|
|
1173
|
-
await this.storage.setUpdate(__classPrivateFieldGet(this, _Client_mainBoxId, "f"), update);
|
|
1174
|
-
}
|
|
1175
|
-
console.log("set pts to", update.pts, "from", update);
|
|
1176
|
-
if (update.pts != 0) {
|
|
1177
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdatePts).call(this, update.pts);
|
|
1178
|
-
}
|
|
1179
|
-
__classPrivateFieldGet(this, _Client_instances, "m", _Client_queueUpdate).call(this, update, 0n, true);
|
|
1180
|
-
}, _Client_processPtsUpdate = function _Client_processPtsUpdate(update, checkGap) {
|
|
1181
|
-
__classPrivateFieldGet(this, _Client_ptsUpdateQueue, "f").add(async () => {
|
|
1182
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processPtsUpdateInner).call(this, update, checkGap);
|
|
1183
|
-
});
|
|
1184
|
-
}, _Client_processUpdates = async function _Client_processUpdates(updates_, checkGap, call = null) {
|
|
1185
|
-
__classPrivateFieldSet(this, _Client_lastUpdates, new Date(), "f");
|
|
1186
|
-
/// First, individual updates (Update[1]) are extracted from Updates.[2]
|
|
1187
|
-
///
|
|
1188
|
-
/// If an updatesTooLong[3] was received, an update gap recovery is initiated and no further action will be taken.
|
|
1189
|
-
///
|
|
1190
|
-
/// [1]: https://core.telegram.org/type/Update
|
|
1191
|
-
/// [2]: https://core.telegram.org/type/Updates
|
|
1192
|
-
/// [3]: https://core.telegram.org/constructor/updatesTooLong
|
|
1193
|
-
let updates;
|
|
1194
|
-
if (updates_ instanceof types.UpdatesCombined || updates_ instanceof types.Updates) {
|
|
1195
|
-
updates = updates_.updates;
|
|
1196
|
-
const seq = updates_.seq;
|
|
1197
|
-
const seqStart = "seq_start" in updates_ ? updates_.seq_start : updates_.seq;
|
|
1198
|
-
if (checkGap) {
|
|
1199
|
-
if (seqStart == 0) {
|
|
1200
|
-
checkGap = false;
|
|
1201
|
-
d("seqStart=0");
|
|
1202
|
-
}
|
|
1203
|
-
else {
|
|
1204
|
-
const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
|
|
1205
|
-
const localSeq = localState.seq;
|
|
1206
|
-
if (localSeq + 1 == seqStart) {
|
|
1207
|
-
// The update sequence can be applied.
|
|
1208
|
-
localState.seq = seq;
|
|
1209
|
-
localState.date = updates_.date;
|
|
1210
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdateStateDate).call(this, updates_.date);
|
|
1211
|
-
await this.storage.setState(localState);
|
|
1212
|
-
}
|
|
1213
|
-
else if (localSeq + 1 > seqStart) {
|
|
1214
|
-
// The update sequence was already applied, and must be ignored.
|
|
1215
|
-
d("localSeq + 1 > seqStart");
|
|
1216
|
-
return;
|
|
1217
|
-
}
|
|
1218
|
-
else if (localSeq + 1 < seqStart) {
|
|
1219
|
-
// There's an updates gap that must be filled.
|
|
1220
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverUpdateGap).call(this, "localSeq + 1 < seqStart");
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
else if (updates_ instanceof types.UpdateShort) {
|
|
1226
|
-
updates = [updates_.update];
|
|
1227
|
-
}
|
|
1228
|
-
else if (updates_ instanceof types.UpdateShortMessage) {
|
|
1229
|
-
updates = [
|
|
1230
|
-
new types.UpdateNewMessage({
|
|
1231
|
-
message: new types.Message({
|
|
1232
|
-
out: updates_.out,
|
|
1233
|
-
mentioned: updates_.mentioned,
|
|
1234
|
-
media_unread: updates_.media_unread,
|
|
1235
|
-
silent: updates_.silent,
|
|
1236
|
-
id: updates_.id,
|
|
1237
|
-
from_id: updates_.out ? new types.PeerUser({ user_id: await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getSelfId).call(this).then(BigInt) }) : new types.PeerUser({ user_id: updates_.user_id }),
|
|
1238
|
-
peer_id: new types.PeerUser({ user_id: updates_.user_id }),
|
|
1239
|
-
message: updates_.message,
|
|
1240
|
-
date: updates_.date,
|
|
1241
|
-
fwd_from: updates_.fwd_from,
|
|
1242
|
-
via_bot_id: updates_.via_bot_id,
|
|
1243
|
-
reply_to: updates_.reply_to,
|
|
1244
|
-
entities: updates_.entities,
|
|
1245
|
-
ttl_period: updates_.ttl_period,
|
|
1246
|
-
}),
|
|
1247
|
-
pts: updates_.pts,
|
|
1248
|
-
pts_count: updates_.pts_count,
|
|
1249
|
-
}),
|
|
1250
|
-
];
|
|
1251
|
-
}
|
|
1252
|
-
else if (updates_ instanceof types.UpdateShortChatMessage) {
|
|
1253
|
-
updates = [
|
|
1254
|
-
new types.UpdateNewMessage({
|
|
1255
|
-
message: new types.Message({
|
|
1256
|
-
out: updates_.out,
|
|
1257
|
-
mentioned: updates_.mentioned,
|
|
1258
|
-
media_unread: updates_.media_unread,
|
|
1259
|
-
silent: updates_.silent,
|
|
1260
|
-
id: updates_.id,
|
|
1261
|
-
from_id: new types.PeerUser({ user_id: updates_.from_id }),
|
|
1262
|
-
peer_id: new types.PeerChat({ chat_id: updates_.chat_id }),
|
|
1263
|
-
fwd_from: updates_.fwd_from,
|
|
1264
|
-
via_bot_id: updates_.via_bot_id,
|
|
1265
|
-
reply_to: updates_.reply_to,
|
|
1266
|
-
date: updates_.date,
|
|
1267
|
-
message: updates_.message,
|
|
1268
|
-
entities: updates_.entities,
|
|
1269
|
-
ttl_period: updates_.ttl_period,
|
|
1270
|
-
}),
|
|
1271
|
-
pts: updates_.pts,
|
|
1272
|
-
pts_count: updates_.pts_count,
|
|
1273
|
-
}),
|
|
1274
|
-
];
|
|
1275
|
-
}
|
|
1276
|
-
else if (updates_ instanceof types.UpdateShortSentMessage) {
|
|
1277
|
-
if (!(call instanceof functions.messages.sendMessage)) {
|
|
1278
|
-
UNREACHABLE();
|
|
1279
|
-
}
|
|
1280
|
-
updates = [
|
|
1281
|
-
new types.UpdateNewMessage({
|
|
1282
|
-
message: new types.Message({
|
|
1283
|
-
out: updates_.out,
|
|
1284
|
-
silent: call.silent,
|
|
1285
|
-
id: updates_.id,
|
|
1286
|
-
from_id: new types.PeerUser({ user_id: await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getSelfId).call(this).then(BigInt) }),
|
|
1287
|
-
peer_id: inputPeerToPeer(call.peer),
|
|
1288
|
-
message: call.message,
|
|
1289
|
-
media: updates_.media,
|
|
1290
|
-
date: updates_.date,
|
|
1291
|
-
// reply_to: call.reply_to, // TODO?
|
|
1292
|
-
entities: updates_.entities,
|
|
1293
|
-
ttl_period: updates_.ttl_period,
|
|
1294
|
-
}),
|
|
1295
|
-
pts: updates_.pts,
|
|
1296
|
-
pts_count: updates_.pts_count,
|
|
1297
|
-
}),
|
|
1298
|
-
];
|
|
1299
|
-
}
|
|
1300
|
-
else if (updates_ instanceof types.UpdatesTooLong) {
|
|
1301
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverUpdateGap).call(this, "updatesTooLong");
|
|
1302
|
-
return;
|
|
1303
|
-
}
|
|
1304
|
-
else if (updates_ instanceof types._Update) {
|
|
1305
|
-
updates = [updates_];
|
|
1306
|
-
}
|
|
1307
|
-
else {
|
|
1308
|
-
UNREACHABLE();
|
|
1309
|
-
}
|
|
1310
|
-
/// We process the updates when we are sure there is no gap.
|
|
1311
|
-
if (updates_ instanceof types.Updates || updates_ instanceof types.UpdatesCombined) {
|
|
1312
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, updates_.chats);
|
|
1313
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, updates_.users);
|
|
1314
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdateStateDate).call(this, updates_.date);
|
|
1315
|
-
}
|
|
1316
|
-
else if (updates_ instanceof types.UpdateShort ||
|
|
1317
|
-
updates_ instanceof types.UpdateShortMessage ||
|
|
1318
|
-
updates_ instanceof types.UpdateShortChatMessage ||
|
|
1319
|
-
updates_ instanceof types.UpdateShortSentMessage) {
|
|
1320
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdateStateDate).call(this, updates_.date);
|
|
1321
|
-
}
|
|
1322
|
-
for (const update of updates) {
|
|
1323
|
-
if (update instanceof types.UpdatePtsChanged) {
|
|
1324
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchState).call(this, "updatePtsChanged");
|
|
1325
|
-
if (__classPrivateFieldGet(this, _Client_updateState, "f")) {
|
|
1326
|
-
await this.storage.setState(__classPrivateFieldGet(this, _Client_updateState, "f"));
|
|
1327
|
-
}
|
|
1328
|
-
else {
|
|
1329
|
-
UNREACHABLE();
|
|
1330
|
-
}
|
|
1331
|
-
}
|
|
1332
|
-
else if (isPtsUpdate(update)) {
|
|
1333
|
-
__classPrivateFieldGet(this, _Client_instances, "m", _Client_processPtsUpdate).call(this, update, checkGap);
|
|
1334
|
-
}
|
|
1335
|
-
else if (isChannelPtsUpdate(update)) {
|
|
1336
|
-
__classPrivateFieldGet(this, _Client_instances, "m", _Client_processChannelPtsUpdate).call(this, update, checkGap);
|
|
1337
|
-
}
|
|
1338
|
-
else {
|
|
1339
|
-
__classPrivateFieldGet(this, _Client_instances, "m", _Client_queueUpdate).call(this, update, 0n, false);
|
|
1340
|
-
}
|
|
1341
|
-
}
|
|
1342
|
-
}, _Client_setUpdateStateDate = async function _Client_setUpdateStateDate(date) {
|
|
1343
|
-
const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
|
|
1344
|
-
localState.date = date;
|
|
1345
|
-
await this.storage.setState(localState);
|
|
1346
|
-
}, _Client_setUpdatePts = async function _Client_setUpdatePts(pts) {
|
|
1347
|
-
const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
|
|
1348
|
-
localState.pts = pts;
|
|
1349
|
-
await this.storage.setState(localState);
|
|
1350
|
-
}, _Client_getLocalState = async function _Client_getLocalState() {
|
|
1351
|
-
let localState = await this.storage.getState();
|
|
1352
|
-
if (!localState) {
|
|
1353
|
-
if (__classPrivateFieldGet(this, _Client_updateState, "f")) {
|
|
1354
|
-
localState = __classPrivateFieldGet(this, _Client_updateState, "f");
|
|
1355
|
-
await this.storage.setState(localState);
|
|
1356
|
-
}
|
|
1357
|
-
else {
|
|
1358
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchState).call(this, "getLocalState");
|
|
1359
|
-
if (__classPrivateFieldGet(this, _Client_updateState, "f")) {
|
|
1360
|
-
localState = __classPrivateFieldGet(this, _Client_updateState, "f");
|
|
1361
|
-
await this.storage.setState(localState);
|
|
1362
|
-
}
|
|
1363
|
-
else {
|
|
1364
|
-
UNREACHABLE();
|
|
1365
|
-
}
|
|
1366
|
-
}
|
|
1367
|
-
}
|
|
1368
|
-
return localState;
|
|
1369
|
-
}, _Client_recoverUpdateGap = async function _Client_recoverUpdateGap(source) {
|
|
1370
|
-
dGap("recovering from update gap [%s]", source);
|
|
1371
|
-
__classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateConnectionState).call(this, "updating");
|
|
1372
|
-
try {
|
|
1373
|
-
let state = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
|
|
1374
|
-
while (true) {
|
|
1375
|
-
const difference = await this.api.updates.getDifference({ pts: state.pts, date: state.date, qts: state.qts ?? 0 });
|
|
1376
|
-
if (difference instanceof types.updates.Difference || difference instanceof types.updates.DifferenceSlice) {
|
|
1377
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, difference.chats);
|
|
1378
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, difference.users);
|
|
1379
|
-
for (const message of difference.new_messages) {
|
|
1380
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, new types.UpdateNewMessage({ message, pts: 0, pts_count: 0 }), false);
|
|
1381
|
-
}
|
|
1382
|
-
for (const update of difference.other_updates) {
|
|
1383
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, update, false);
|
|
1384
|
-
}
|
|
1385
|
-
if (difference instanceof types.updates.Difference) {
|
|
1386
|
-
await this.storage.setState(difference.state);
|
|
1387
|
-
dGap("recovered from update gap");
|
|
1388
|
-
break;
|
|
1389
|
-
}
|
|
1390
|
-
else if (difference instanceof types.updates.DifferenceSlice) {
|
|
1391
|
-
state = difference.intermediate_state;
|
|
1392
|
-
}
|
|
1393
|
-
else {
|
|
1394
|
-
UNREACHABLE();
|
|
1395
|
-
}
|
|
1396
|
-
}
|
|
1397
|
-
else if (difference instanceof types.updates.DifferenceTooLong) {
|
|
1398
|
-
await this.storage.deleteMessages();
|
|
1399
|
-
await this.storage.removeChats(0);
|
|
1400
|
-
await this.storage.removeChats(1);
|
|
1401
|
-
state.pts = difference.pts;
|
|
1402
|
-
dGap("received differenceTooLong");
|
|
1403
|
-
}
|
|
1404
|
-
else if (difference instanceof types.updates.DifferenceEmpty) {
|
|
1405
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdateStateDate).call(this, difference.date);
|
|
1406
|
-
dGap("there was no update gap");
|
|
1407
|
-
break;
|
|
1408
|
-
}
|
|
1409
|
-
else {
|
|
1410
|
-
UNREACHABLE();
|
|
1411
|
-
}
|
|
1412
|
-
}
|
|
1413
|
-
}
|
|
1414
|
-
finally {
|
|
1415
|
-
this.stateChangeHandler(this.connected);
|
|
1416
|
-
__classPrivateFieldSet(this, _Client_lastUpdates, new Date(), "f");
|
|
1417
|
-
}
|
|
1418
|
-
}, _Client_recoverChannelUpdateGap = async function _Client_recoverChannelUpdateGap(channelId, source) {
|
|
1419
|
-
dGapC("recovering channel update gap [%o, %s]", channelId, source);
|
|
1420
|
-
const pts_ = await this.storage.getChannelPts(channelId);
|
|
1421
|
-
let pts = pts_ == null ? 1 : pts_;
|
|
1422
|
-
while (true) {
|
|
1423
|
-
const { access_hash } = await this.getInputPeer(ZERO_CHANNEL_ID + -Number(channelId)).then((v) => v[as](types.InputPeerChannel));
|
|
1424
|
-
const difference = await this.api.updates.getChannelDifference({
|
|
1425
|
-
pts,
|
|
1426
|
-
channel: new types.InputChannel({ channel_id: channelId, access_hash }),
|
|
1427
|
-
filter: new types.ChannelMessagesFilterEmpty(),
|
|
1428
|
-
limit: await this.storage.getAccountType() == "user" ? CHANNEL_DIFFERENCE_LIMIT_USER : CHANNEL_DIFFERENCE_LIMIT_BOT,
|
|
1429
|
-
});
|
|
1430
|
-
if (difference instanceof types.updates.ChannelDifference) {
|
|
1431
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, difference.chats);
|
|
1432
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, difference.users);
|
|
1433
|
-
for (const message of difference.new_messages) {
|
|
1434
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, new types.UpdateNewChannelMessage({ message, pts: 0, pts_count: 0 }), false);
|
|
1435
|
-
}
|
|
1436
|
-
for (const update of difference.other_updates) {
|
|
1437
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, update, false);
|
|
1438
|
-
}
|
|
1439
|
-
await this.storage.setChannelPts(channelId, difference.pts);
|
|
1440
|
-
dGapC("recovered from update gap [%o, %s]", channelId, source);
|
|
1441
|
-
break;
|
|
1442
|
-
}
|
|
1443
|
-
else if (difference instanceof types.updates.ChannelDifferenceTooLong) {
|
|
1444
|
-
// TODO: invalidate messages
|
|
1445
|
-
dGapC("received channelDifferenceTooLong");
|
|
1446
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, difference.chats);
|
|
1447
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, difference.users);
|
|
1448
|
-
for (const message of difference.messages) {
|
|
1449
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, new types.UpdateNewChannelMessage({ message, pts: 0, pts_count: 0 }), false);
|
|
1450
|
-
}
|
|
1451
|
-
const pts_ = difference.dialog[as](types.Dialog).pts;
|
|
1452
|
-
if (pts_ != undefined) {
|
|
1453
|
-
pts = pts_;
|
|
1454
|
-
}
|
|
1455
|
-
else {
|
|
1456
|
-
UNREACHABLE();
|
|
1457
|
-
}
|
|
1458
|
-
dGapC("processed channelDifferenceTooLong");
|
|
1459
|
-
}
|
|
1460
|
-
else if (difference instanceof types.updates.ChannelDifferenceEmpty) {
|
|
1461
|
-
dGapC("there was no update gap");
|
|
1462
|
-
break;
|
|
1463
|
-
}
|
|
1464
|
-
}
|
|
1162
|
+
}, _Client_getUserAccessHash = async function _Client_getUserAccessHash(userId) {
|
|
1163
|
+
const users = await this.api.users.getUsers({ id: [new types.InputUser({ user_id: userId, access_hash: 0n })] });
|
|
1164
|
+
return users[0]?.[as](types.User).access_hash ?? 0n;
|
|
1465
1165
|
}, _Client_getChannelAccessHash = async function _Client_getChannelAccessHash(channelId) {
|
|
1466
1166
|
const channels = await this.api.channels.getChannels({ id: [new types.InputChannel({ channel_id: channelId, access_hash: 0n })] });
|
|
1467
1167
|
return channels.chats[0][as](types.Channel).access_hash ?? 0n;
|
|
@@ -1482,8 +1182,8 @@ export class Client extends ClientAbstract {
|
|
|
1482
1182
|
}
|
|
1483
1183
|
else {
|
|
1484
1184
|
const resolved = await this.api.contacts.resolveUsername({ username: id });
|
|
1485
|
-
await __classPrivateFieldGet(this,
|
|
1486
|
-
await __classPrivateFieldGet(this,
|
|
1185
|
+
await __classPrivateFieldGet(this, _Client_updateManager, "f").processChats(resolved.chats);
|
|
1186
|
+
await __classPrivateFieldGet(this, _Client_updateManager, "f").processUsers(resolved.users);
|
|
1487
1187
|
if (resolved.peer instanceof types.PeerUser) {
|
|
1488
1188
|
userId = resolved.peer.user_id;
|
|
1489
1189
|
}
|
|
@@ -1527,63 +1227,6 @@ export class Client extends ClientAbstract {
|
|
|
1527
1227
|
const id = peer instanceof types.PeerUser ? peer.user_id : peer instanceof types.PeerChat ? peer.chat_id : peer instanceof types.PeerChannel ? peer.channel_id : UNREACHABLE();
|
|
1528
1228
|
return this.storage.getEntity(type, id);
|
|
1529
1229
|
}
|
|
1530
|
-
async processResult(result) {
|
|
1531
|
-
if (result instanceof types.messages.Dialogs ||
|
|
1532
|
-
result instanceof types.messages.DialogsSlice ||
|
|
1533
|
-
result instanceof types.messages.Messages ||
|
|
1534
|
-
result instanceof types.messages.MessagesSlice ||
|
|
1535
|
-
result instanceof types.messages.ChannelMessages ||
|
|
1536
|
-
result instanceof types.messages.ChatFull ||
|
|
1537
|
-
result instanceof types.contacts.Found ||
|
|
1538
|
-
result instanceof types.account.PrivacyRules ||
|
|
1539
|
-
result instanceof types.contacts.ResolvedPeer ||
|
|
1540
|
-
result instanceof types.channels.ChannelParticipants ||
|
|
1541
|
-
result instanceof types.channels.ChannelParticipant ||
|
|
1542
|
-
result instanceof types.messages.PeerDialogs ||
|
|
1543
|
-
result instanceof types.contacts.TopPeers ||
|
|
1544
|
-
result instanceof types.channels.AdminLogResults ||
|
|
1545
|
-
result instanceof types.help.RecentMeUrls ||
|
|
1546
|
-
result instanceof types.messages.InactiveChats ||
|
|
1547
|
-
result instanceof types.help.PromoData ||
|
|
1548
|
-
result instanceof types.messages.MessageViews ||
|
|
1549
|
-
result instanceof types.messages.DiscussionMessage ||
|
|
1550
|
-
result instanceof types.phone.GroupCall ||
|
|
1551
|
-
result instanceof types.phone.GroupParticipants ||
|
|
1552
|
-
result instanceof types.phone.JoinAsPeers ||
|
|
1553
|
-
result instanceof types.messages.SponsoredMessages ||
|
|
1554
|
-
result instanceof types.messages.SearchResultsCalendar ||
|
|
1555
|
-
result instanceof types.channels.SendAsPeers ||
|
|
1556
|
-
result instanceof types.users.UserFull ||
|
|
1557
|
-
result instanceof types.messages.PeerSettings ||
|
|
1558
|
-
result instanceof types.messages.MessageReactionsList ||
|
|
1559
|
-
result instanceof types.messages.ForumTopics ||
|
|
1560
|
-
result instanceof types.account.AutoSaveSettings ||
|
|
1561
|
-
result instanceof types.chatlists.ExportedInvites ||
|
|
1562
|
-
result instanceof types.chatlists.ChatlistInviteAlready ||
|
|
1563
|
-
result instanceof types.chatlists.ChatlistInvite ||
|
|
1564
|
-
result instanceof types.chatlists.ChatlistUpdates ||
|
|
1565
|
-
result instanceof types.messages.Chats ||
|
|
1566
|
-
result instanceof types.messages.ChatsSlice) {
|
|
1567
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, result.chats);
|
|
1568
|
-
if ("users" in result) {
|
|
1569
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, result.users);
|
|
1570
|
-
}
|
|
1571
|
-
if ("messages" in result) {
|
|
1572
|
-
for (const message of result.messages) {
|
|
1573
|
-
if (message instanceof types.Message || message instanceof types.MessageService) {
|
|
1574
|
-
await this.storage.setMessage(peerToChatId(message.peer_id), message.id, message);
|
|
1575
|
-
}
|
|
1576
|
-
}
|
|
1577
|
-
}
|
|
1578
|
-
}
|
|
1579
|
-
if (result instanceof types.messages.Messages) {
|
|
1580
|
-
for (const message of result.messages) {
|
|
1581
|
-
if (message instanceof types.Message || message instanceof types.MessageService) {
|
|
1582
|
-
await this.storage.setMessage(peerToChatId(message.peer_id), message.id, message);
|
|
1583
|
-
}
|
|
1584
|
-
}
|
|
1585
|
-
}
|
|
1586
|
-
}
|
|
1587
1230
|
/**
|
|
1588
1231
|
* Send a text message.
|
|
1589
1232
|
*
|
|
@@ -1593,50 +1236,30 @@ export class Client extends ClientAbstract {
|
|
|
1593
1236
|
* @returns The sent text message.
|
|
1594
1237
|
*/
|
|
1595
1238
|
async sendMessage(chatId, text, params) {
|
|
1596
|
-
|
|
1597
|
-
const replyMarkup = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params);
|
|
1598
|
-
const peer = await this.getInputPeer(chatId);
|
|
1599
|
-
const randomId = getRandomId();
|
|
1600
|
-
const noWebpage = params?.disableWebPagePreview ? true : undefined;
|
|
1601
|
-
const silent = params?.disableNotification ? true : undefined;
|
|
1602
|
-
const noforwards = params?.protectContent ? true : undefined;
|
|
1603
|
-
const sendAs = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_resolveSendAs).call(this, params);
|
|
1604
|
-
const result = await this.api.messages.sendMessage({
|
|
1605
|
-
peer,
|
|
1606
|
-
random_id: randomId,
|
|
1607
|
-
message,
|
|
1608
|
-
no_webpage: noWebpage,
|
|
1609
|
-
silent,
|
|
1610
|
-
noforwards,
|
|
1611
|
-
reply_to: __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyTo).call(this, params),
|
|
1612
|
-
send_as: sendAs,
|
|
1613
|
-
entities,
|
|
1614
|
-
reply_markup: replyMarkup,
|
|
1615
|
-
});
|
|
1616
|
-
const message_ = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
|
|
1617
|
-
return assertMessageType(message_, "text");
|
|
1239
|
+
return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendMessage(chatId, text, params);
|
|
1618
1240
|
}
|
|
1619
1241
|
/**
|
|
1620
1242
|
* Edit a message's text.
|
|
1621
1243
|
*
|
|
1622
1244
|
* @method
|
|
1623
|
-
* @param chatId The chat
|
|
1624
|
-
* @param messageId The
|
|
1245
|
+
* @param chatId The identifier of the chat that contains the messages.
|
|
1246
|
+
* @param messageId The message's identifier.
|
|
1625
1247
|
* @param text The new text of the message.
|
|
1626
1248
|
* @returns The edited text message.
|
|
1627
1249
|
*/
|
|
1628
1250
|
async editMessageText(chatId, messageId, text, params) {
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1251
|
+
return await __classPrivateFieldGet(this, _Client_messageManager, "f").editMessageText(chatId, messageId, text, params);
|
|
1252
|
+
}
|
|
1253
|
+
/**
|
|
1254
|
+
* Edit a message's reply markup.
|
|
1255
|
+
*
|
|
1256
|
+
* @method
|
|
1257
|
+
* @param chatId The identifier of the chat that contains the messages.
|
|
1258
|
+
* @param messageId The message's identifier.
|
|
1259
|
+
* @returns The edited message.
|
|
1260
|
+
*/
|
|
1261
|
+
async editMessageReplyMarkup(chatId, messageId, params) {
|
|
1262
|
+
return await __classPrivateFieldGet(this, _Client_messageManager, "f").editMessageReplyMarkup(chatId, messageId, params);
|
|
1640
1263
|
}
|
|
1641
1264
|
/**
|
|
1642
1265
|
* Retrieve multiple messages.
|
|
@@ -1650,101 +1273,7 @@ export class Client extends ClientAbstract {
|
|
|
1650
1273
|
* @returns The retrieved messages.
|
|
1651
1274
|
*/
|
|
1652
1275
|
async getMessages(chatId, messageIds) {
|
|
1653
|
-
return await __classPrivateFieldGet(this,
|
|
1654
|
-
}
|
|
1655
|
-
async [(_Client_updatesToMessages = async function _Client_updatesToMessages(chatId, updates) {
|
|
1656
|
-
const messages = new Array();
|
|
1657
|
-
if (updates instanceof types.Updates) {
|
|
1658
|
-
for (const update of updates.updates) {
|
|
1659
|
-
if ("message" in update && update.message instanceof types.MessageEmpty) {
|
|
1660
|
-
continue;
|
|
1661
|
-
}
|
|
1662
|
-
if (update instanceof types.UpdateNewMessage || update instanceof types.UpdateEditMessage) {
|
|
1663
|
-
messages.push(await constructMessage(update.message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this)));
|
|
1664
|
-
}
|
|
1665
|
-
else if (update instanceof types.UpdateNewChannelMessage || update instanceof types.UpdateEditChannelMessage) {
|
|
1666
|
-
messages.push(await constructMessage(update.message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this)));
|
|
1667
|
-
}
|
|
1668
|
-
}
|
|
1669
|
-
}
|
|
1670
|
-
else if (updates instanceof types.UpdateShortSentMessage) {
|
|
1671
|
-
const message = await this.getMessage(chatId, updates.id);
|
|
1672
|
-
if (message != null) {
|
|
1673
|
-
messages.push(message);
|
|
1674
|
-
}
|
|
1675
|
-
}
|
|
1676
|
-
return messages;
|
|
1677
|
-
}, _Client_resolveSendAs = async function _Client_resolveSendAs(params) {
|
|
1678
|
-
const sendAs = params?.sendAs;
|
|
1679
|
-
if (sendAs !== undefined) {
|
|
1680
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertUser).call(this, "sendAs");
|
|
1681
|
-
return sendAs ? await this.getInputPeer(sendAs) : undefined;
|
|
1682
|
-
}
|
|
1683
|
-
}, _Client_constructReplyTo = function _Client_constructReplyTo(params) {
|
|
1684
|
-
const topMsgId = params?.messageThreadId;
|
|
1685
|
-
const replyToMsgId = params?.replyToMessageId;
|
|
1686
|
-
return replyToMsgId !== undefined ? new types.InputReplyToMessage({ reply_to_msg_id: replyToMsgId, top_msg_id: topMsgId, quote_text: params?.replyQuote?.text, quote_entities: params?.replyQuote?.entities.map(messageEntityToTlObject), quote_offset: params?.replyQuote?.offset }) : undefined;
|
|
1687
|
-
}, _Client_parseText = function _Client_parseText(text, params) {
|
|
1688
|
-
const entities_ = params?.entities ?? [];
|
|
1689
|
-
const parseMode = params?.parseMode ?? this.parseMode;
|
|
1690
|
-
switch (parseMode) {
|
|
1691
|
-
case null:
|
|
1692
|
-
break;
|
|
1693
|
-
case "HTML": {
|
|
1694
|
-
const [newText, entitiesToPush] = parseHtml(text);
|
|
1695
|
-
text = newText;
|
|
1696
|
-
for (const entity of entitiesToPush) {
|
|
1697
|
-
entities_.push(entity);
|
|
1698
|
-
}
|
|
1699
|
-
break;
|
|
1700
|
-
}
|
|
1701
|
-
default:
|
|
1702
|
-
UNREACHABLE();
|
|
1703
|
-
}
|
|
1704
|
-
const entities = entities_?.length > 0 ? entities_.map((v) => messageEntityToTlObject(v)) : undefined;
|
|
1705
|
-
return [text, entities];
|
|
1706
|
-
}, _Client_getMessagesInner = async function _Client_getMessagesInner(chatId_, messageIds) {
|
|
1707
|
-
const peer = await this.getInputPeer(chatId_);
|
|
1708
|
-
let messages_ = new Array();
|
|
1709
|
-
const chatId = peerToChatId(peer);
|
|
1710
|
-
let shouldFetch = false;
|
|
1711
|
-
for (const messageId of messageIds) {
|
|
1712
|
-
const message = await this.storage.getMessage(chatId, messageId);
|
|
1713
|
-
if (message == null) {
|
|
1714
|
-
messages_ = [];
|
|
1715
|
-
shouldFetch = true;
|
|
1716
|
-
break;
|
|
1717
|
-
}
|
|
1718
|
-
else {
|
|
1719
|
-
messages_.push(message);
|
|
1720
|
-
}
|
|
1721
|
-
}
|
|
1722
|
-
if (shouldFetch) {
|
|
1723
|
-
if (peer instanceof types.InputPeerChannel) {
|
|
1724
|
-
messages_ = await this.api.channels.getMessages({
|
|
1725
|
-
channel: new types.InputChannel(peer),
|
|
1726
|
-
id: messageIds.map((v) => new types.InputMessageID({ id: v })),
|
|
1727
|
-
}).then((v) => v[as](types.messages.ChannelMessages).messages);
|
|
1728
|
-
}
|
|
1729
|
-
else {
|
|
1730
|
-
messages_ = await this.api.messages.getMessages({
|
|
1731
|
-
id: messageIds.map((v) => new types.InputMessageID({ id: v })),
|
|
1732
|
-
}).then((v) => v[as](types.messages.Messages).messages);
|
|
1733
|
-
}
|
|
1734
|
-
}
|
|
1735
|
-
const messages = new Array();
|
|
1736
|
-
for (const message_ of messages_) {
|
|
1737
|
-
if (message_ instanceof types.MessageEmpty) {
|
|
1738
|
-
continue;
|
|
1739
|
-
}
|
|
1740
|
-
const message = await constructMessage(message_, this[getEntity].bind(this), null, this[getStickerSetName].bind(this));
|
|
1741
|
-
const isReplyToMessage = message_ instanceof types.Message && message_.reply_to instanceof types.MessageReplyHeader;
|
|
1742
|
-
messages.push({ message, isReplyToMessage });
|
|
1743
|
-
}
|
|
1744
|
-
return messages;
|
|
1745
|
-
}, getMessageWithReply)](chatId, messageId) {
|
|
1746
|
-
const messages = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getMessagesInner).call(this, chatId, [messageId]);
|
|
1747
|
-
return messages[0]?.message ?? null;
|
|
1276
|
+
return await __classPrivateFieldGet(this, _Client_messageManager, "f").getMessages(chatId, messageIds);
|
|
1748
1277
|
}
|
|
1749
1278
|
/**
|
|
1750
1279
|
* Retrieve a single message.
|
|
@@ -1758,8 +1287,7 @@ export class Client extends ClientAbstract {
|
|
|
1758
1287
|
* @returns The retrieved message.
|
|
1759
1288
|
*/
|
|
1760
1289
|
async getMessage(chatId, messageId) {
|
|
1761
|
-
|
|
1762
|
-
return messages[0] ?? null;
|
|
1290
|
+
return await __classPrivateFieldGet(this, _Client_messageManager, "f").getMessage(chatId, messageId);
|
|
1763
1291
|
}
|
|
1764
1292
|
/**
|
|
1765
1293
|
* Download a file.
|
|
@@ -1774,139 +1302,8 @@ export class Client extends ClientAbstract {
|
|
|
1774
1302
|
* @returns A generator yielding the contents of the file.
|
|
1775
1303
|
*/
|
|
1776
1304
|
async *download(fileId, params) {
|
|
1777
|
-
const
|
|
1778
|
-
|
|
1779
|
-
case FileType.ChatPhoto: {
|
|
1780
|
-
const big = fileId_.params.thumbnailSource == ThumbnailSource.ChatPhotoBig;
|
|
1781
|
-
const peer = await this.getInputPeer(fileId_.params.chatId);
|
|
1782
|
-
const location = new types.InputPeerPhotoFileLocation({ big: big ? true : undefined, peer, photo_id: fileId_.params.mediaId });
|
|
1783
|
-
for await (const chunk of __classPrivateFieldGet(this, _Client_instances, "m", _Client_downloadInner).call(this, location, fileId_.dcId, params)) {
|
|
1784
|
-
yield chunk;
|
|
1785
|
-
}
|
|
1786
|
-
break;
|
|
1787
|
-
}
|
|
1788
|
-
case FileType.Photo: {
|
|
1789
|
-
if (fileId_.params.mediaId == undefined || fileId_.params.accessHash == undefined || fileId_.params.fileReference == undefined || fileId_.params.thumbnailSize == undefined) {
|
|
1790
|
-
UNREACHABLE();
|
|
1791
|
-
}
|
|
1792
|
-
const location = new types.InputPhotoFileLocation({
|
|
1793
|
-
id: fileId_.params.mediaId,
|
|
1794
|
-
access_hash: fileId_.params.accessHash,
|
|
1795
|
-
file_reference: fileId_.params.fileReference,
|
|
1796
|
-
thumb_size: fileId_.params.thumbnailSize,
|
|
1797
|
-
});
|
|
1798
|
-
for await (const chunk of __classPrivateFieldGet(this, _Client_instances, "m", _Client_downloadInner).call(this, location, fileId_.dcId, params)) {
|
|
1799
|
-
yield chunk;
|
|
1800
|
-
}
|
|
1801
|
-
break;
|
|
1802
|
-
}
|
|
1803
|
-
case FileType.Document:
|
|
1804
|
-
case FileType.Sticker:
|
|
1805
|
-
case FileType.VideoNote:
|
|
1806
|
-
case FileType.Video:
|
|
1807
|
-
case FileType.Audio:
|
|
1808
|
-
case FileType.Voice:
|
|
1809
|
-
case FileType.Animation: {
|
|
1810
|
-
if (fileId_.params.mediaId == undefined || fileId_.params.accessHash == undefined || fileId_.params.fileReference == undefined || fileId_.params.thumbnailSize == undefined) {
|
|
1811
|
-
UNREACHABLE();
|
|
1812
|
-
}
|
|
1813
|
-
const location = new types.InputDocumentFileLocation({
|
|
1814
|
-
id: fileId_.params.mediaId,
|
|
1815
|
-
access_hash: fileId_.params.accessHash,
|
|
1816
|
-
file_reference: fileId_.params.fileReference,
|
|
1817
|
-
thumb_size: fileId_.params.thumbnailSize,
|
|
1818
|
-
});
|
|
1819
|
-
for await (const chunk of __classPrivateFieldGet(this, _Client_instances, "m", _Client_downloadInner).call(this, location, fileId_.dcId, params)) {
|
|
1820
|
-
yield chunk;
|
|
1821
|
-
}
|
|
1822
|
-
break;
|
|
1823
|
-
}
|
|
1824
|
-
default:
|
|
1825
|
-
UNREACHABLE();
|
|
1826
|
-
}
|
|
1827
|
-
}
|
|
1828
|
-
async [(_Client_downloadInner = async function* _Client_downloadInner(location, dcId, params) {
|
|
1829
|
-
const id = "id" in location ? location.id : "photo_id" in location ? location.photo_id : null;
|
|
1830
|
-
if (id != null) {
|
|
1831
|
-
const partCount = await this.storage.getFile(id);
|
|
1832
|
-
if (partCount != null && partCount > 0) {
|
|
1833
|
-
for await (const part of this.storage.iterFileParts(id, partCount)) {
|
|
1834
|
-
yield part;
|
|
1835
|
-
}
|
|
1836
|
-
return;
|
|
1837
|
-
}
|
|
1838
|
-
}
|
|
1839
|
-
const chunkSize = params?.chunkSize ?? 1024 * 1024;
|
|
1840
|
-
if (mod(chunkSize, 1024) != 0) {
|
|
1841
|
-
throw new Error("chunkSize must be divisible by 1024");
|
|
1842
|
-
}
|
|
1843
|
-
const client = new _a(dcId == this.dcId ? this.storage : this.storage.branch(`download_client_${dcId}`), this.apiId, this.apiHash, {
|
|
1844
|
-
transportProvider: this.transportProvider,
|
|
1845
|
-
appVersion: this.appVersion,
|
|
1846
|
-
deviceModel: this.deviceModel,
|
|
1847
|
-
langCode: this.langCode,
|
|
1848
|
-
langPack: this.langPack,
|
|
1849
|
-
systemLangCode: this.systemLangCode,
|
|
1850
|
-
systemVersion: this.systemVersion,
|
|
1851
|
-
cdn: true,
|
|
1852
|
-
});
|
|
1853
|
-
let dc = String(dcId);
|
|
1854
|
-
if (this.dcId < 0) {
|
|
1855
|
-
dc += "-test";
|
|
1856
|
-
}
|
|
1857
|
-
await client.setDc(dc);
|
|
1858
|
-
await client.connect();
|
|
1859
|
-
await __classPrivateFieldGet(client, _Client_instances, "m", _Client_initConnection).call(client);
|
|
1860
|
-
client.invoke.use(async (ctx, next) => {
|
|
1861
|
-
if (ctx.error instanceof AuthKeyUnregistered) {
|
|
1862
|
-
try {
|
|
1863
|
-
const exportedAuth = await this.api.auth.exportAuthorization({ dc_id: dcId });
|
|
1864
|
-
await client.authorize(exportedAuth);
|
|
1865
|
-
return true;
|
|
1866
|
-
}
|
|
1867
|
-
catch (err) {
|
|
1868
|
-
throw err;
|
|
1869
|
-
}
|
|
1870
|
-
}
|
|
1871
|
-
else {
|
|
1872
|
-
return await next();
|
|
1873
|
-
}
|
|
1874
|
-
});
|
|
1875
|
-
const limit = chunkSize;
|
|
1876
|
-
let offset = 0n;
|
|
1877
|
-
let part = 0;
|
|
1878
|
-
while (true) {
|
|
1879
|
-
const file = await (client ?? this).invoke(new functions.upload.getFile({ location, offset, limit }));
|
|
1880
|
-
if (file instanceof types.upload.File) {
|
|
1881
|
-
yield file.bytes;
|
|
1882
|
-
if (id != null) {
|
|
1883
|
-
await this.storage.saveFilePart(id, part, file.bytes);
|
|
1884
|
-
}
|
|
1885
|
-
++part;
|
|
1886
|
-
if (file.bytes.length < limit) {
|
|
1887
|
-
if (id != null) {
|
|
1888
|
-
await this.storage.setFilePartCount(id, part + 1);
|
|
1889
|
-
}
|
|
1890
|
-
break;
|
|
1891
|
-
}
|
|
1892
|
-
else {
|
|
1893
|
-
offset += BigInt(file.bytes.length);
|
|
1894
|
-
}
|
|
1895
|
-
}
|
|
1896
|
-
else {
|
|
1897
|
-
UNREACHABLE();
|
|
1898
|
-
}
|
|
1899
|
-
}
|
|
1900
|
-
}, getStickerSetName)](inputStickerSet, hash = 0) {
|
|
1901
|
-
const maybeStickerSetName = await this.storage.getStickerSetName(inputStickerSet.id, inputStickerSet.access_hash);
|
|
1902
|
-
if (maybeStickerSetName != null && Date.now() - maybeStickerSetName[1].getTime() < STICKER_SET_NAME_TTL) {
|
|
1903
|
-
return maybeStickerSetName[0];
|
|
1904
|
-
}
|
|
1905
|
-
else {
|
|
1906
|
-
const stickerSet = await this.api.messages.getStickerSet({ stickerset: inputStickerSet, hash });
|
|
1907
|
-
const name = stickerSet[as](types.messages.StickerSet).set.short_name;
|
|
1908
|
-
await this.storage.updateStickerSetName(inputStickerSet.id, inputStickerSet.access_hash, name);
|
|
1909
|
-
return name;
|
|
1305
|
+
for await (const chunk of __classPrivateFieldGet(this, _Client_fileManager, "f").download(fileId, params)) {
|
|
1306
|
+
yield chunk;
|
|
1910
1307
|
}
|
|
1911
1308
|
}
|
|
1912
1309
|
/**
|
|
@@ -1919,19 +1316,7 @@ export class Client extends ClientAbstract {
|
|
|
1919
1316
|
* @returns The forwarded messages.
|
|
1920
1317
|
*/
|
|
1921
1318
|
async forwardMessages(from, to, messageIds, params) {
|
|
1922
|
-
|
|
1923
|
-
from_peer: await this.getInputPeer(from),
|
|
1924
|
-
to_peer: await this.getInputPeer(to),
|
|
1925
|
-
id: messageIds,
|
|
1926
|
-
random_id: messageIds.map(() => getRandomId()),
|
|
1927
|
-
silent: params?.disableNotification || undefined,
|
|
1928
|
-
top_msg_id: params?.messageThreadId,
|
|
1929
|
-
noforwards: params?.disableNotification || undefined,
|
|
1930
|
-
send_as: params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined,
|
|
1931
|
-
drop_author: params?.dropSenderName || undefined,
|
|
1932
|
-
drop_media_captions: params?.dropCaption || undefined,
|
|
1933
|
-
});
|
|
1934
|
-
return await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, to, result);
|
|
1319
|
+
return await __classPrivateFieldGet(this, _Client_messageManager, "f").forwardMessages(from, to, messageIds, params);
|
|
1935
1320
|
}
|
|
1936
1321
|
/**
|
|
1937
1322
|
* Forward a single message.
|
|
@@ -1966,7 +1351,7 @@ export class Client extends ClientAbstract {
|
|
|
1966
1351
|
* @param id ID of the callback query to answer.
|
|
1967
1352
|
*/
|
|
1968
1353
|
async answerCallbackQuery(id, params) {
|
|
1969
|
-
await
|
|
1354
|
+
await this.storage.assertBot("answerCallbackQuery");
|
|
1970
1355
|
await this.api.messages.setBotCallbackAnswer({
|
|
1971
1356
|
query_id: BigInt(id),
|
|
1972
1357
|
cache_time: params?.cacheTime ?? 0,
|
|
@@ -1984,47 +1369,7 @@ export class Client extends ClientAbstract {
|
|
|
1984
1369
|
* @returns The sent poll.
|
|
1985
1370
|
*/
|
|
1986
1371
|
async sendPoll(chatId, question, options, params) {
|
|
1987
|
-
|
|
1988
|
-
const randomId = getRandomId();
|
|
1989
|
-
const silent = params?.disableNotification ? true : undefined;
|
|
1990
|
-
const noforwards = params?.protectContent ? true : undefined;
|
|
1991
|
-
const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined; // TODO: check default sendAs
|
|
1992
|
-
const replyMarkup = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params);
|
|
1993
|
-
const explanation = params?.explanation;
|
|
1994
|
-
const parseResult = explanation !== undefined ? __classPrivateFieldGet(this, _Client_instances, "m", _Client_parseText).call(this, explanation, { parseMode: params?.explanationParseMode, entities: params?.explanationEntities }) : undefined;
|
|
1995
|
-
const solution = parseResult === undefined ? undefined : parseResult[0];
|
|
1996
|
-
const solutionEntities = parseResult === undefined ? undefined : parseResult[1];
|
|
1997
|
-
const answers = options.map((v, i) => new types.PollAnswer({ option: new Uint8Array([i]), text: v }));
|
|
1998
|
-
const poll = new types.Poll({
|
|
1999
|
-
id: getRandomId(),
|
|
2000
|
-
answers,
|
|
2001
|
-
question,
|
|
2002
|
-
closed: params?.isClosed ? true : undefined,
|
|
2003
|
-
close_date: params?.closeDate ? Math.floor(params.closeDate.getTime() / 1000) : undefined,
|
|
2004
|
-
close_period: params?.openPeriod ? params.openPeriod : undefined,
|
|
2005
|
-
multiple_choice: params?.allowMultipleAnswers ? true : undefined,
|
|
2006
|
-
public_voters: params?.isAnonymous === false ? true : undefined,
|
|
2007
|
-
quiz: params?.type == "quiz" ? true : undefined,
|
|
2008
|
-
});
|
|
2009
|
-
const media = new types.InputMediaPoll({
|
|
2010
|
-
poll,
|
|
2011
|
-
correct_answers: params?.correctOptionIndex ? [new Uint8Array([params.correctOptionIndex])] : undefined,
|
|
2012
|
-
solution,
|
|
2013
|
-
solution_entities: solutionEntities,
|
|
2014
|
-
});
|
|
2015
|
-
const result = await this.api.messages.sendMedia({
|
|
2016
|
-
peer,
|
|
2017
|
-
random_id: randomId,
|
|
2018
|
-
silent,
|
|
2019
|
-
noforwards,
|
|
2020
|
-
reply_markup: replyMarkup,
|
|
2021
|
-
reply_to: __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyTo).call(this, params),
|
|
2022
|
-
send_as: sendAs,
|
|
2023
|
-
media,
|
|
2024
|
-
message: "",
|
|
2025
|
-
});
|
|
2026
|
-
const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
|
|
2027
|
-
return assertMessageType(message, "poll");
|
|
1372
|
+
return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendPoll(chatId, question, options, params);
|
|
2028
1373
|
}
|
|
2029
1374
|
/**
|
|
2030
1375
|
* Send a chat action.
|
|
@@ -2082,89 +1427,7 @@ export class Client extends ClientAbstract {
|
|
|
2082
1427
|
* @param contents The contents of the file.
|
|
2083
1428
|
*/
|
|
2084
1429
|
async upload(contents, params) {
|
|
2085
|
-
|
|
2086
|
-
const chunkSize = params?.chunkSize ?? 512 * 1024;
|
|
2087
|
-
if (mod(chunkSize, 1024) != 0) {
|
|
2088
|
-
throw new Error("chunkSize must be divisible by 1024");
|
|
2089
|
-
}
|
|
2090
|
-
const signal = params?.signal;
|
|
2091
|
-
dUpload("uploading " + (isBig ? "big " : "") + "file of size " + contents.length + " with chunk size of " + chunkSize);
|
|
2092
|
-
const fileId = getRandomId();
|
|
2093
|
-
const name = params?.fileName ?? fileId.toString();
|
|
2094
|
-
const client = new _a(this.storage, this.apiId, this.apiHash, {
|
|
2095
|
-
transportProvider: this.transportProvider,
|
|
2096
|
-
appVersion: this.appVersion,
|
|
2097
|
-
deviceModel: this.deviceModel,
|
|
2098
|
-
langCode: this.langCode,
|
|
2099
|
-
langPack: this.langPack,
|
|
2100
|
-
systemLangCode: this.systemLangCode,
|
|
2101
|
-
systemVersion: this.systemVersion,
|
|
2102
|
-
cdn: true,
|
|
2103
|
-
initialDc: this.initialDc,
|
|
2104
|
-
autoStart: false,
|
|
2105
|
-
});
|
|
2106
|
-
signal?.addEventListener("abort", () => drop(client.disconnect()));
|
|
2107
|
-
__classPrivateFieldGet(client, _Client_state, "f").salt = __classPrivateFieldGet(this, _Client_state, "f").salt;
|
|
2108
|
-
await client.connect();
|
|
2109
|
-
let part = 0;
|
|
2110
|
-
const partCount = Math.ceil(contents.length / chunkSize);
|
|
2111
|
-
try {
|
|
2112
|
-
main: for (; part < partCount; part++) {
|
|
2113
|
-
chunk: while (true) {
|
|
2114
|
-
try {
|
|
2115
|
-
const start = part * chunkSize;
|
|
2116
|
-
const end = start + chunkSize;
|
|
2117
|
-
const bytes = contents.slice(start, end);
|
|
2118
|
-
if (bytes.length == 0) {
|
|
2119
|
-
continue main;
|
|
2120
|
-
}
|
|
2121
|
-
if (isBig) {
|
|
2122
|
-
await client.invoke(new functions.upload.saveBigFilePart({ file_id: fileId, file_part: part, bytes, file_total_parts: partCount }));
|
|
2123
|
-
}
|
|
2124
|
-
else {
|
|
2125
|
-
await client.invoke(new functions.upload.saveFilePart({ file_id: fileId, bytes, file_part: part }));
|
|
2126
|
-
}
|
|
2127
|
-
dUpload((part + 1) + " out of " + partCount + " chunks have been uploaded so far");
|
|
2128
|
-
break chunk;
|
|
2129
|
-
}
|
|
2130
|
-
catch (err) {
|
|
2131
|
-
if (signal?.aborted) {
|
|
2132
|
-
break main;
|
|
2133
|
-
}
|
|
2134
|
-
if (err instanceof FloodWait) {
|
|
2135
|
-
dUpload("got a flood wait of " + err.seconds + " seconds");
|
|
2136
|
-
await new Promise((r) => setTimeout(r, err.seconds * 1000));
|
|
2137
|
-
}
|
|
2138
|
-
else if (err instanceof ConnectionError) {
|
|
2139
|
-
while (true) {
|
|
2140
|
-
try {
|
|
2141
|
-
await new Promise((r) => setTimeout(r, 3000));
|
|
2142
|
-
await client.connect();
|
|
2143
|
-
}
|
|
2144
|
-
catch {
|
|
2145
|
-
if (signal?.aborted) {
|
|
2146
|
-
break main;
|
|
2147
|
-
}
|
|
2148
|
-
}
|
|
2149
|
-
}
|
|
2150
|
-
}
|
|
2151
|
-
else {
|
|
2152
|
-
throw err;
|
|
2153
|
-
}
|
|
2154
|
-
}
|
|
2155
|
-
}
|
|
2156
|
-
}
|
|
2157
|
-
}
|
|
2158
|
-
finally {
|
|
2159
|
-
drop(client.disconnect());
|
|
2160
|
-
}
|
|
2161
|
-
dUpload("uploaded all " + partCount + " chunk(s)");
|
|
2162
|
-
if (isBig) {
|
|
2163
|
-
return new types.InputFileBig({ id: fileId, parts: contents.length / chunkSize, name });
|
|
2164
|
-
}
|
|
2165
|
-
else {
|
|
2166
|
-
return new types.InputFile({ id: fileId, name, parts: part, md5_checksum: "" });
|
|
2167
|
-
}
|
|
1430
|
+
return await __classPrivateFieldGet(this, _Client_fileManager, "f").upload(contents, params);
|
|
2168
1431
|
}
|
|
2169
1432
|
/**
|
|
2170
1433
|
* Set the bot's commands in the given scope and/or language. Bot-only.
|
|
@@ -2284,7 +1547,7 @@ export class Client extends ClientAbstract {
|
|
|
2284
1547
|
* @method
|
|
2285
1548
|
*/
|
|
2286
1549
|
async setMyDescription(params) {
|
|
2287
|
-
await
|
|
1550
|
+
await this.storage.assertBot("setMyDescription");
|
|
2288
1551
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { description: params?.description, lang_code: params?.languageCode ?? "" });
|
|
2289
1552
|
}
|
|
2290
1553
|
/**
|
|
@@ -2293,7 +1556,7 @@ export class Client extends ClientAbstract {
|
|
|
2293
1556
|
* @method
|
|
2294
1557
|
*/
|
|
2295
1558
|
async setMyName(params) {
|
|
2296
|
-
await
|
|
1559
|
+
await this.storage.assertBot("setMyName");
|
|
2297
1560
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { name: params?.name, lang_code: params?.languageCode ?? "" });
|
|
2298
1561
|
}
|
|
2299
1562
|
/**
|
|
@@ -2302,7 +1565,7 @@ export class Client extends ClientAbstract {
|
|
|
2302
1565
|
* @method
|
|
2303
1566
|
*/
|
|
2304
1567
|
async setMyShortDescription(params) {
|
|
2305
|
-
await
|
|
1568
|
+
await this.storage.assertBot("setMyShortDescription");
|
|
2306
1569
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { about: params?.shortDescription, lang_code: params?.languageCode ?? "" });
|
|
2307
1570
|
}
|
|
2308
1571
|
/**
|
|
@@ -2311,7 +1574,7 @@ export class Client extends ClientAbstract {
|
|
|
2311
1574
|
* @method
|
|
2312
1575
|
*/
|
|
2313
1576
|
async getMyDescription(params) {
|
|
2314
|
-
await
|
|
1577
|
+
await this.storage.assertBot("getMyDescription");
|
|
2315
1578
|
return await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getMyInfo).call(this, params?.languageCode).then((v) => v.description);
|
|
2316
1579
|
}
|
|
2317
1580
|
/**
|
|
@@ -2320,7 +1583,7 @@ export class Client extends ClientAbstract {
|
|
|
2320
1583
|
* @method
|
|
2321
1584
|
*/
|
|
2322
1585
|
async getMyName(params) {
|
|
2323
|
-
await
|
|
1586
|
+
await this.storage.assertBot("getMyName");
|
|
2324
1587
|
return await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getMyInfo).call(this, params?.languageCode).then((v) => v.description);
|
|
2325
1588
|
}
|
|
2326
1589
|
/**
|
|
@@ -2329,34 +1592,28 @@ export class Client extends ClientAbstract {
|
|
|
2329
1592
|
* @method
|
|
2330
1593
|
*/
|
|
2331
1594
|
async getMyShortDescription(params) {
|
|
2332
|
-
await
|
|
1595
|
+
await this.storage.assertBot("getMyShortDescription");
|
|
2333
1596
|
return await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getMyInfo).call(this, params?.languageCode).then((v) => v.about);
|
|
2334
1597
|
}
|
|
2335
1598
|
/**
|
|
2336
1599
|
* Delete multiple messages.
|
|
2337
1600
|
*
|
|
2338
1601
|
* @method
|
|
2339
|
-
* @param chatId The chat that contains the messages.
|
|
1602
|
+
* @param chatId The identifier of the chat that contains the messages.
|
|
2340
1603
|
* @param messageIds The identifier of the messages to delete.
|
|
2341
1604
|
*/
|
|
2342
1605
|
async deleteMessages(chatId, messageIds, params) {
|
|
2343
|
-
|
|
2344
|
-
if (peer instanceof types.InputPeerChannel) {
|
|
2345
|
-
await this.api.channels.deleteMessages({ channel: new types.InputChannel(peer), id: messageIds });
|
|
2346
|
-
}
|
|
2347
|
-
else {
|
|
2348
|
-
await this.api.messages.deleteMessages({ id: messageIds, revoke: params?.onlyForMe ? undefined : true });
|
|
2349
|
-
}
|
|
1606
|
+
return await __classPrivateFieldGet(this, _Client_messageManager, "f").deleteMessages(chatId, messageIds, params);
|
|
2350
1607
|
}
|
|
2351
1608
|
/**
|
|
2352
1609
|
* Delete a single message.
|
|
2353
1610
|
*
|
|
2354
1611
|
* @method
|
|
2355
|
-
* @param chatId The chat that contains the message.
|
|
1612
|
+
* @param chatId The identifier of the chat that contains the message.
|
|
2356
1613
|
* @param messageId The identifier of the message to delete.
|
|
2357
1614
|
*/
|
|
2358
1615
|
async deleteMessage(chatId, messageId, params) {
|
|
2359
|
-
await this.deleteMessages(chatId, [messageId], params);
|
|
1616
|
+
return await __classPrivateFieldGet(this, _Client_messageManager, "f").deleteMessages(chatId, [messageId], params);
|
|
2360
1617
|
}
|
|
2361
1618
|
/**
|
|
2362
1619
|
* Send a photo.
|
|
@@ -2366,29 +1623,7 @@ export class Client extends ClientAbstract {
|
|
|
2366
1623
|
* @param photo The photo to send.
|
|
2367
1624
|
*/
|
|
2368
1625
|
async sendPhoto(chatId, photo, params) {
|
|
2369
|
-
|
|
2370
|
-
const spoiler = params?.hasSpoiler ? true : undefined;
|
|
2371
|
-
if (typeof photo === "string") {
|
|
2372
|
-
const fileId = __classPrivateFieldGet(this, _Client_instances, "m", _Client_resolveFileId).call(this, photo, FileType.Photo);
|
|
2373
|
-
if (fileId != null) {
|
|
2374
|
-
media = new types.InputMediaPhoto({
|
|
2375
|
-
id: new types.InputPhoto(fileId),
|
|
2376
|
-
spoiler,
|
|
2377
|
-
});
|
|
2378
|
-
}
|
|
2379
|
-
}
|
|
2380
|
-
if (media == null) {
|
|
2381
|
-
if (typeof photo === "string" && isHttpUrl(photo)) {
|
|
2382
|
-
media = new types.InputMediaPhotoExternal({ url: photo, spoiler });
|
|
2383
|
-
}
|
|
2384
|
-
else {
|
|
2385
|
-
const [contents, fileName] = await getFileContents(photo);
|
|
2386
|
-
const file = await this.upload(contents, { fileName, chunkSize: params?.chunkSize, signal: params?.signal });
|
|
2387
|
-
media = new types.InputMediaUploadedPhoto({ file, spoiler });
|
|
2388
|
-
}
|
|
2389
|
-
}
|
|
2390
|
-
const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendMedia).call(this, chatId, media, params);
|
|
2391
|
-
return assertMessageType(message, "photo");
|
|
1626
|
+
return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendPhoto(chatId, photo, params);
|
|
2392
1627
|
}
|
|
2393
1628
|
/**
|
|
2394
1629
|
* Send a document.
|
|
@@ -2398,8 +1633,7 @@ export class Client extends ClientAbstract {
|
|
|
2398
1633
|
* @param document The document to send.
|
|
2399
1634
|
*/
|
|
2400
1635
|
async sendDocument(chatId, document, params) {
|
|
2401
|
-
|
|
2402
|
-
return assertMessageType(message, "document");
|
|
1636
|
+
return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendDocument(chatId, document, params);
|
|
2403
1637
|
}
|
|
2404
1638
|
/**
|
|
2405
1639
|
* Send a video.
|
|
@@ -2409,15 +1643,7 @@ export class Client extends ClientAbstract {
|
|
|
2409
1643
|
* @param video The video to send.
|
|
2410
1644
|
*/
|
|
2411
1645
|
async sendVideo(chatId, video, params) {
|
|
2412
|
-
|
|
2413
|
-
new types.DocumentAttributeVideo({
|
|
2414
|
-
supports_streaming: params?.supportsStreaming ? true : undefined,
|
|
2415
|
-
w: params?.width ?? 0,
|
|
2416
|
-
h: params?.height ?? 0,
|
|
2417
|
-
duration: params?.duration ?? 0,
|
|
2418
|
-
}),
|
|
2419
|
-
]);
|
|
2420
|
-
return assertMessageType(message, "video");
|
|
1646
|
+
return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendVideo(chatId, video, params);
|
|
2421
1647
|
}
|
|
2422
1648
|
/**
|
|
2423
1649
|
* Send an animation.
|
|
@@ -2427,16 +1653,7 @@ export class Client extends ClientAbstract {
|
|
|
2427
1653
|
* @param animation The animation to send.
|
|
2428
1654
|
*/
|
|
2429
1655
|
async sendAnimation(chatId, animation, params) {
|
|
2430
|
-
|
|
2431
|
-
new types.DocumentAttributeAnimated(),
|
|
2432
|
-
new types.DocumentAttributeVideo({
|
|
2433
|
-
supports_streaming: true,
|
|
2434
|
-
w: params?.width ?? 0,
|
|
2435
|
-
h: params?.height ?? 0,
|
|
2436
|
-
duration: params?.duration ?? 0,
|
|
2437
|
-
}),
|
|
2438
|
-
]);
|
|
2439
|
-
return assertMessageType(message, "animation");
|
|
1656
|
+
return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendAnimation(chatId, animation, params);
|
|
2440
1657
|
}
|
|
2441
1658
|
/**
|
|
2442
1659
|
* Send a voice message.
|
|
@@ -2446,13 +1663,7 @@ export class Client extends ClientAbstract {
|
|
|
2446
1663
|
* @param voice The voice to send.
|
|
2447
1664
|
*/
|
|
2448
1665
|
async sendVoice(chatId, voice, params) {
|
|
2449
|
-
|
|
2450
|
-
new types.DocumentAttributeAudio({
|
|
2451
|
-
voice: true,
|
|
2452
|
-
duration: params?.duration ?? 0,
|
|
2453
|
-
}),
|
|
2454
|
-
]);
|
|
2455
|
-
return assertMessageType(message, "voice");
|
|
1666
|
+
return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendVoice(chatId, voice, params);
|
|
2456
1667
|
}
|
|
2457
1668
|
/**
|
|
2458
1669
|
* Send an audio file.
|
|
@@ -2462,14 +1673,7 @@ export class Client extends ClientAbstract {
|
|
|
2462
1673
|
* @param audio The audio to send.
|
|
2463
1674
|
*/
|
|
2464
1675
|
async sendAudio(chatId, audio, params) {
|
|
2465
|
-
|
|
2466
|
-
new types.DocumentAttributeAudio({
|
|
2467
|
-
duration: params?.duration ?? 0,
|
|
2468
|
-
performer: params?.performer,
|
|
2469
|
-
title: params?.title,
|
|
2470
|
-
}),
|
|
2471
|
-
]);
|
|
2472
|
-
return assertMessageType(message, "audio");
|
|
1676
|
+
return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendAudio(chatId, audio, params);
|
|
2473
1677
|
}
|
|
2474
1678
|
/**
|
|
2475
1679
|
* Send a video note.
|
|
@@ -2478,16 +1682,8 @@ export class Client extends ClientAbstract {
|
|
|
2478
1682
|
* @param chatId The chat to send the video note to.
|
|
2479
1683
|
* @param videoNote The video note to send.
|
|
2480
1684
|
*/
|
|
2481
|
-
async sendVideoNote(chatId,
|
|
2482
|
-
|
|
2483
|
-
new types.DocumentAttributeVideo({
|
|
2484
|
-
round_message: true,
|
|
2485
|
-
w: params?.length ?? 0,
|
|
2486
|
-
h: params?.length ?? 0,
|
|
2487
|
-
duration: params?.duration ?? 0,
|
|
2488
|
-
}),
|
|
2489
|
-
], false);
|
|
2490
|
-
return assertMessageType(message, "videoNote");
|
|
1685
|
+
async sendVideoNote(chatId, videoNote, params) {
|
|
1686
|
+
return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendVideoNote(chatId, videoNote, params);
|
|
2491
1687
|
}
|
|
2492
1688
|
/**
|
|
2493
1689
|
* Send a location.
|
|
@@ -2498,42 +1694,7 @@ export class Client extends ClientAbstract {
|
|
|
2498
1694
|
* @param longitude The location's longitude.
|
|
2499
1695
|
*/
|
|
2500
1696
|
async sendLocation(chatId, latitude, longitude, params) {
|
|
2501
|
-
|
|
2502
|
-
const randomId = getRandomId();
|
|
2503
|
-
const silent = params?.disableNotification ? true : undefined;
|
|
2504
|
-
const noforwards = params?.protectContent ? true : undefined;
|
|
2505
|
-
const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined; // TODO: check default sendAs
|
|
2506
|
-
const replyMarkup = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params);
|
|
2507
|
-
const result = await this.api.messages.sendMedia({
|
|
2508
|
-
peer,
|
|
2509
|
-
random_id: randomId,
|
|
2510
|
-
silent,
|
|
2511
|
-
noforwards,
|
|
2512
|
-
reply_to: __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyTo).call(this, params),
|
|
2513
|
-
send_as: sendAs,
|
|
2514
|
-
reply_markup: replyMarkup,
|
|
2515
|
-
media: params?.livePeriod !== undefined
|
|
2516
|
-
? new types.InputMediaGeoLive({
|
|
2517
|
-
geo_point: new types.InputGeoPoint({
|
|
2518
|
-
lat: latitude,
|
|
2519
|
-
long: longitude,
|
|
2520
|
-
accuracy_radius: params?.horizontalAccuracy,
|
|
2521
|
-
}),
|
|
2522
|
-
heading: params?.heading,
|
|
2523
|
-
period: params.livePeriod,
|
|
2524
|
-
proximity_notification_radius: params?.proximityAlertRadius,
|
|
2525
|
-
})
|
|
2526
|
-
: new types.InputMediaGeoPoint({
|
|
2527
|
-
geo_point: new types.InputGeoPoint({
|
|
2528
|
-
lat: latitude,
|
|
2529
|
-
long: longitude,
|
|
2530
|
-
accuracy_radius: params?.horizontalAccuracy,
|
|
2531
|
-
}),
|
|
2532
|
-
}),
|
|
2533
|
-
message: "",
|
|
2534
|
-
});
|
|
2535
|
-
const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
|
|
2536
|
-
return assertMessageType(message, "location");
|
|
1697
|
+
return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendLocation(chatId, latitude, longitude, params);
|
|
2537
1698
|
}
|
|
2538
1699
|
/**
|
|
2539
1700
|
* Send a contact.
|
|
@@ -2544,30 +1705,7 @@ export class Client extends ClientAbstract {
|
|
|
2544
1705
|
* @param number The contact's phone number.
|
|
2545
1706
|
*/
|
|
2546
1707
|
async sendContact(chatId, firstName, number, params) {
|
|
2547
|
-
|
|
2548
|
-
const randomId = getRandomId();
|
|
2549
|
-
const silent = params?.disableNotification ? true : undefined;
|
|
2550
|
-
const noforwards = params?.protectContent ? true : undefined;
|
|
2551
|
-
const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined; // TODO: check default sendAs
|
|
2552
|
-
const replyMarkup = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params);
|
|
2553
|
-
const result = await this.api.messages.sendMedia({
|
|
2554
|
-
peer,
|
|
2555
|
-
random_id: randomId,
|
|
2556
|
-
silent,
|
|
2557
|
-
noforwards,
|
|
2558
|
-
reply_to: __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyTo).call(this, params),
|
|
2559
|
-
send_as: sendAs,
|
|
2560
|
-
reply_markup: replyMarkup,
|
|
2561
|
-
media: new types.InputMediaContact({
|
|
2562
|
-
phone_number: number,
|
|
2563
|
-
first_name: firstName,
|
|
2564
|
-
last_name: params?.lastName ?? "",
|
|
2565
|
-
vcard: params?.vcard ?? "",
|
|
2566
|
-
}),
|
|
2567
|
-
message: "",
|
|
2568
|
-
});
|
|
2569
|
-
const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
|
|
2570
|
-
return assertMessageType(message, "contact");
|
|
1708
|
+
return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendContact(chatId, firstName, number, params);
|
|
2571
1709
|
}
|
|
2572
1710
|
/**
|
|
2573
1711
|
* Send a dice.
|
|
@@ -2576,27 +1714,7 @@ export class Client extends ClientAbstract {
|
|
|
2576
1714
|
* @param chatId The chat to send the dice to.
|
|
2577
1715
|
*/
|
|
2578
1716
|
async sendDice(chatId, params) {
|
|
2579
|
-
|
|
2580
|
-
const randomId = getRandomId();
|
|
2581
|
-
const silent = params?.disableNotification ? true : undefined;
|
|
2582
|
-
const noforwards = params?.protectContent ? true : undefined;
|
|
2583
|
-
const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined; // TODO: check default sendAs
|
|
2584
|
-
const replyMarkup = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params);
|
|
2585
|
-
const result = await this.api.messages.sendMedia({
|
|
2586
|
-
peer,
|
|
2587
|
-
random_id: randomId,
|
|
2588
|
-
silent,
|
|
2589
|
-
noforwards,
|
|
2590
|
-
reply_to: __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyTo).call(this, params),
|
|
2591
|
-
send_as: sendAs,
|
|
2592
|
-
reply_markup: replyMarkup,
|
|
2593
|
-
media: new types.InputMediaDice({
|
|
2594
|
-
emoticon: params?.emoji ?? "🎲",
|
|
2595
|
-
}),
|
|
2596
|
-
message: "",
|
|
2597
|
-
});
|
|
2598
|
-
const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
|
|
2599
|
-
return assertMessageType(message, "dice");
|
|
1717
|
+
return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendDice(chatId, params);
|
|
2600
1718
|
}
|
|
2601
1719
|
/**
|
|
2602
1720
|
* Send a venue.
|
|
@@ -2609,35 +1727,7 @@ export class Client extends ClientAbstract {
|
|
|
2609
1727
|
* @param address The written address of the venue.
|
|
2610
1728
|
*/
|
|
2611
1729
|
async sendVenue(chatId, latitude, longitude, title, address, params) {
|
|
2612
|
-
|
|
2613
|
-
const randomId = getRandomId();
|
|
2614
|
-
const silent = params?.disableNotification ? true : undefined;
|
|
2615
|
-
const noforwards = params?.protectContent ? true : undefined;
|
|
2616
|
-
const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined; // TODO: check default sendAs
|
|
2617
|
-
const replyMarkup = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params);
|
|
2618
|
-
const result = await this.api.messages.sendMedia({
|
|
2619
|
-
peer,
|
|
2620
|
-
random_id: randomId,
|
|
2621
|
-
silent,
|
|
2622
|
-
noforwards,
|
|
2623
|
-
reply_to: __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyTo).call(this, params),
|
|
2624
|
-
send_as: sendAs,
|
|
2625
|
-
reply_markup: replyMarkup,
|
|
2626
|
-
media: new types.InputMediaVenue({
|
|
2627
|
-
geo_point: new types.InputGeoPoint({
|
|
2628
|
-
lat: latitude,
|
|
2629
|
-
long: longitude,
|
|
2630
|
-
}),
|
|
2631
|
-
title,
|
|
2632
|
-
address,
|
|
2633
|
-
venue_id: params?.foursquareId ?? "",
|
|
2634
|
-
venue_type: params?.foursquareType ?? "",
|
|
2635
|
-
provider: "foursquare",
|
|
2636
|
-
}),
|
|
2637
|
-
message: "",
|
|
2638
|
-
});
|
|
2639
|
-
const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
|
|
2640
|
-
return assertMessageType(message, "venue");
|
|
1730
|
+
return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendVenue(chatId, latitude, longitude, title, address, params);
|
|
2641
1731
|
}
|
|
2642
1732
|
/**
|
|
2643
1733
|
* Get network statistics. This might not always be available.
|
|
@@ -2667,32 +1757,7 @@ export class Client extends ClientAbstract {
|
|
|
2667
1757
|
* @method
|
|
2668
1758
|
*/
|
|
2669
1759
|
async getChats(params) {
|
|
2670
|
-
await __classPrivateFieldGet(this,
|
|
2671
|
-
if (!__classPrivateFieldGet(this, _Client_chatsLoadedFromStorage, "f")) {
|
|
2672
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_loadChatsFromStorage).call(this);
|
|
2673
|
-
}
|
|
2674
|
-
if (params?.after?.id && !__classPrivateFieldGet(this, _Client_chats, "f").has(params.after.id)) {
|
|
2675
|
-
throw new Error("Invalid after");
|
|
2676
|
-
}
|
|
2677
|
-
let limit = params?.limit ?? 100;
|
|
2678
|
-
if (limit <= 0 || limit > 100) {
|
|
2679
|
-
limit = 100;
|
|
2680
|
-
}
|
|
2681
|
-
const listId = getChatListId(params?.from ?? "main");
|
|
2682
|
-
let chats = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLoadedChats).call(this, listId);
|
|
2683
|
-
if (params?.after) {
|
|
2684
|
-
chats = chats
|
|
2685
|
-
.filter((v) => v.order < params.after.order);
|
|
2686
|
-
}
|
|
2687
|
-
if (chats.length < limit) {
|
|
2688
|
-
d("have only %d chats but %d more is needed", chats.length, limit - chats.length);
|
|
2689
|
-
if (!await this.storage.hasAllChats(listId)) {
|
|
2690
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchChats).call(this, listId, limit, params?.after);
|
|
2691
|
-
return await this.getChats(params);
|
|
2692
|
-
}
|
|
2693
|
-
}
|
|
2694
|
-
chats = chats.slice(0, limit);
|
|
2695
|
-
return chats;
|
|
1760
|
+
return await __classPrivateFieldGet(this, _Client_chatListManager, "f").getChats(params?.from, params?.after, params?.limit);
|
|
2696
1761
|
}
|
|
2697
1762
|
/**
|
|
2698
1763
|
* Get a chat.
|
|
@@ -2706,13 +1771,13 @@ export class Client extends ClientAbstract {
|
|
|
2706
1771
|
maybeChatId = chatId;
|
|
2707
1772
|
}
|
|
2708
1773
|
else if (typeof chatId === "string") {
|
|
2709
|
-
maybeChatId = __classPrivateFieldGet(this,
|
|
1774
|
+
maybeChatId = __classPrivateFieldGet(this, _Client_chatListManager, "f").tryGetChatId(getUsername(chatId));
|
|
2710
1775
|
}
|
|
2711
1776
|
else {
|
|
2712
1777
|
UNREACHABLE();
|
|
2713
1778
|
}
|
|
2714
1779
|
if (maybeChatId != null) {
|
|
2715
|
-
const [chat] = __classPrivateFieldGet(this,
|
|
1780
|
+
const [chat] = __classPrivateFieldGet(this, _Client_chatListManager, "f").getChatAnywhere(maybeChatId);
|
|
2716
1781
|
if (chat !== undefined) {
|
|
2717
1782
|
return chat;
|
|
2718
1783
|
}
|
|
@@ -2767,159 +1832,281 @@ export class Client extends ClientAbstract {
|
|
|
2767
1832
|
/**
|
|
2768
1833
|
* Get chat history. User-only.
|
|
2769
1834
|
*
|
|
2770
|
-
* @param chatId The identifier of the chat to get its history.
|
|
2771
1835
|
* @method
|
|
1836
|
+
* @param chatId The identifier of the chat to get its history.
|
|
2772
1837
|
*/
|
|
2773
1838
|
async getHistory(chatId, params) {
|
|
2774
|
-
|
|
2775
|
-
if (limit <= 0) {
|
|
2776
|
-
limit = 1;
|
|
2777
|
-
}
|
|
2778
|
-
else if (limit > 100) {
|
|
2779
|
-
limit = 100;
|
|
2780
|
-
}
|
|
2781
|
-
let offsetId = params?.after?.id ?? 0;
|
|
2782
|
-
if (offsetId < 0) {
|
|
2783
|
-
offsetId = 0;
|
|
2784
|
-
}
|
|
2785
|
-
const peer = await this.getInputPeer(chatId);
|
|
2786
|
-
const messages = new Array();
|
|
2787
|
-
for (const message_ of await this.storage.getHistory(peerToChatId(peer), offsetId, limit)) {
|
|
2788
|
-
const message = await constructMessage(message_, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this), false);
|
|
2789
|
-
messages.push(message);
|
|
2790
|
-
}
|
|
2791
|
-
if (messages.length < limit) {
|
|
2792
|
-
d("have only %d messages but need %d more", messages.length, limit - messages.length);
|
|
2793
|
-
if (messages.length > 0) {
|
|
2794
|
-
offsetId = messages[messages.length - 1].id; // TODO: track id of oldest message and don't send requests for it
|
|
2795
|
-
}
|
|
2796
|
-
const result = await this.api.messages.getHistory({
|
|
2797
|
-
peer: peer,
|
|
2798
|
-
offset_id: offsetId,
|
|
2799
|
-
offset_date: 0,
|
|
2800
|
-
add_offset: 0,
|
|
2801
|
-
limit,
|
|
2802
|
-
max_id: 0,
|
|
2803
|
-
min_id: 0,
|
|
2804
|
-
hash: 0n,
|
|
2805
|
-
});
|
|
2806
|
-
if (!("messages" in result)) {
|
|
2807
|
-
UNREACHABLE();
|
|
2808
|
-
}
|
|
2809
|
-
for (const message_ of result.messages) {
|
|
2810
|
-
const message = await constructMessage(message_, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this), false);
|
|
2811
|
-
messages.push(message);
|
|
2812
|
-
}
|
|
2813
|
-
}
|
|
2814
|
-
return messages;
|
|
1839
|
+
return await __classPrivateFieldGet(this, _Client_messageManager, "f").getHistory(chatId, params);
|
|
2815
1840
|
}
|
|
2816
1841
|
/**
|
|
2817
1842
|
* Get custom emoji documents for download.
|
|
2818
1843
|
*
|
|
2819
|
-
* @param id Identifier of one or more of custom emojis.
|
|
2820
1844
|
* @method
|
|
1845
|
+
* @param id Identifier of one or more of custom emojis.
|
|
2821
1846
|
*/
|
|
2822
1847
|
async getCustomEmojiDocuments(id) {
|
|
2823
|
-
|
|
2824
|
-
if (!id.length) {
|
|
2825
|
-
throw new Error("No custom emoji ID provided");
|
|
2826
|
-
}
|
|
2827
|
-
const documents = new Array();
|
|
2828
|
-
let shouldFetch = false;
|
|
2829
|
-
for (const [i, id_] of id.entries()) {
|
|
2830
|
-
const maybeDocument = await this.storage.getCustomEmojiDocument(BigInt(id_));
|
|
2831
|
-
if (maybeDocument != null && Date.now() - maybeDocument[1].getTime() <= 30 * 60 * 1000) {
|
|
2832
|
-
const document_ = maybeDocument[0];
|
|
2833
|
-
const fileUniqueId = new FileUniqueID(FileUniqueType.Document, { mediaId: document_.id }).encode();
|
|
2834
|
-
const fileId = new FileID(null, null, FileType.Document, document_.dc_id, {
|
|
2835
|
-
mediaId: document_.id,
|
|
2836
|
-
accessHash: document_.access_hash,
|
|
2837
|
-
fileReference: document_.file_reference,
|
|
2838
|
-
}).encode();
|
|
2839
|
-
const document = constructDocument(document_, new types.DocumentAttributeFilename({ file_name: `${id[i] ?? "customEmoji"}.${extension(document_.mime_type)}` }), fileId, fileUniqueId);
|
|
2840
|
-
documents.push(document);
|
|
2841
|
-
}
|
|
2842
|
-
else {
|
|
2843
|
-
shouldFetch = true;
|
|
2844
|
-
break;
|
|
2845
|
-
}
|
|
2846
|
-
}
|
|
2847
|
-
if (!shouldFetch) {
|
|
2848
|
-
return documents;
|
|
2849
|
-
}
|
|
2850
|
-
const documents_ = await this.api.messages.getCustomEmojiDocuments({ document_id: id.map(BigInt) }).then((v) => v.map((v) => v[as](types.Document)));
|
|
2851
|
-
for (const [i, document_] of documents_.entries()) {
|
|
2852
|
-
const fileUniqueId = new FileUniqueID(FileUniqueType.Document, { mediaId: document_.id }).encode();
|
|
2853
|
-
const fileId = new FileID(null, null, FileType.Document, document_.dc_id, {
|
|
2854
|
-
mediaId: document_.id,
|
|
2855
|
-
accessHash: document_.access_hash,
|
|
2856
|
-
fileReference: document_.file_reference,
|
|
2857
|
-
}).encode();
|
|
2858
|
-
const document = constructDocument(document_, new types.DocumentAttributeFilename({ file_name: `${id[i] ?? "customEmoji"}.${extension(document_.mime_type)}` }), fileId, fileUniqueId);
|
|
2859
|
-
documents.push(document);
|
|
2860
|
-
}
|
|
2861
|
-
return documents;
|
|
1848
|
+
return await __classPrivateFieldGet(this, _Client_fileManager, "f").getCustomEmojiDocuments(id);
|
|
2862
1849
|
}
|
|
2863
1850
|
/**
|
|
2864
1851
|
* Set a chat's available reactions.
|
|
2865
1852
|
*
|
|
1853
|
+
* @method
|
|
2866
1854
|
* @param chatId The identifier of the chat.
|
|
2867
1855
|
* @param availableReactions The new available reactions.
|
|
2868
|
-
* @method
|
|
2869
1856
|
*/
|
|
2870
1857
|
async setAvailableReactions(chatId, availableReactions) {
|
|
2871
|
-
|
|
2872
|
-
await this.api.messages.setChatAvailableReactions({
|
|
2873
|
-
peer: await this.getInputPeer(chatId),
|
|
2874
|
-
available_reactions: availableReactions == "none" ? new types.ChatReactionsNone() : availableReactions == "all" ? new types.ChatReactionsAll() : Array.isArray(availableReactions) ? new types.ChatReactionsSome({ reactions: availableReactions.map((v) => v.type == "emoji" ? new types.ReactionEmoji({ emoticon: v.emoji }) : new types.ReactionCustomEmoji({ document_id: BigInt(v.id) })) }) : UNREACHABLE(),
|
|
2875
|
-
});
|
|
1858
|
+
await __classPrivateFieldGet(this, _Client_reactionManager, "f").setAvailableReactions(chatId, availableReactions);
|
|
2876
1859
|
}
|
|
2877
1860
|
/**
|
|
2878
1861
|
* Change reactions made to a message.
|
|
2879
1862
|
*
|
|
1863
|
+
* @method
|
|
2880
1864
|
* @param chatId The identifier of the chat which the message belongs to.
|
|
2881
1865
|
* @param messageId The identifier of the message to add the reaction to.
|
|
2882
1866
|
* @param reactions The new reactions.
|
|
2883
1867
|
*/
|
|
2884
1868
|
async setReactions(chatId, messageId, reactions, params) {
|
|
2885
|
-
await __classPrivateFieldGet(this,
|
|
1869
|
+
await __classPrivateFieldGet(this, _Client_reactionManager, "f").setReactions(chatId, messageId, reactions, params);
|
|
2886
1870
|
}
|
|
2887
1871
|
/**
|
|
2888
1872
|
* Make a reaction to a message.
|
|
2889
1873
|
*
|
|
1874
|
+
* @method
|
|
2890
1875
|
* @param chatId The identifier of the chat which the message belongs to.
|
|
2891
1876
|
* @param messageId The identifier of the message to add the reaction to.
|
|
2892
1877
|
* @param reaction The reaction to add.
|
|
2893
1878
|
*/
|
|
2894
1879
|
async addReaction(chatId, messageId, reaction, params) {
|
|
2895
|
-
|
|
2896
|
-
for (const r of chosenReactions) {
|
|
2897
|
-
if (reactionEqual(r.reaction, reaction)) {
|
|
2898
|
-
return;
|
|
2899
|
-
}
|
|
2900
|
-
}
|
|
2901
|
-
const reactions = [reaction, ...chosenReactions.map((v) => v.reaction)];
|
|
2902
|
-
await this.setReactions(chatId, messageId, reactions, params);
|
|
1880
|
+
await __classPrivateFieldGet(this, _Client_reactionManager, "f").addReaction(chatId, messageId, reaction, params);
|
|
2903
1881
|
}
|
|
2904
1882
|
/**
|
|
2905
1883
|
* Undo a reaction made to a message.
|
|
2906
1884
|
*
|
|
1885
|
+
* @method
|
|
2907
1886
|
* @param chatId The identifier of the chat which the message belongs to.
|
|
2908
1887
|
* @param messageId The identifier of the message which the reaction was made to.
|
|
2909
1888
|
* @param reaction The reaction to remove.
|
|
2910
1889
|
*/
|
|
2911
1890
|
async removeReaction(chatId, messageId, reaction) {
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
1891
|
+
await __classPrivateFieldGet(this, _Client_reactionManager, "f").removeReaction(chatId, messageId, reaction);
|
|
1892
|
+
}
|
|
1893
|
+
/**
|
|
1894
|
+
* Set a chat's photo.
|
|
1895
|
+
*
|
|
1896
|
+
* @method
|
|
1897
|
+
* @param chatId The identifier of the chat.
|
|
1898
|
+
* @param photo A photo to set as the chat's photo.
|
|
1899
|
+
*/
|
|
1900
|
+
async setChatPhoto(chatId, photo, params) {
|
|
1901
|
+
const peer = await this.getInputPeer(chatId);
|
|
1902
|
+
if (!(peer instanceof types.InputPeerChannel) && !(peer instanceof types.InputPeerChat)) {
|
|
1903
|
+
UNREACHABLE();
|
|
1904
|
+
}
|
|
1905
|
+
const [contents, fileName] = await getFileContents(photo);
|
|
1906
|
+
const file = await this.upload(contents, { fileName: params?.fileName ?? fileName, chunkSize: params?.chunkSize, signal: params?.signal });
|
|
1907
|
+
const photo_ = new types.InputChatUploadedPhoto({ file });
|
|
1908
|
+
if (peer instanceof types.InputPeerChannel) {
|
|
1909
|
+
await this.api.channels.editPhoto({ channel: new types.InputChannel(peer), photo: photo_ });
|
|
1910
|
+
}
|
|
1911
|
+
else if (peer instanceof types.InputPeerChat) {
|
|
1912
|
+
await this.api.messages.editChatPhoto({ chat_id: peer.chat_id, photo: photo_ });
|
|
1913
|
+
}
|
|
1914
|
+
}
|
|
1915
|
+
/**
|
|
1916
|
+
* Delete a chat's photo.
|
|
1917
|
+
*
|
|
1918
|
+
* @method
|
|
1919
|
+
* @param chatId The identifier of the chat.
|
|
1920
|
+
*/
|
|
1921
|
+
async deleteChatPhoto(chatId) {
|
|
1922
|
+
const peer = await this.getInputPeer(chatId);
|
|
1923
|
+
if (!(peer instanceof types.InputPeerChannel) && !(peer instanceof types.InputPeerChat)) {
|
|
1924
|
+
UNREACHABLE();
|
|
1925
|
+
}
|
|
1926
|
+
if (peer instanceof types.InputPeerChannel) {
|
|
1927
|
+
await this.api.channels.editPhoto({ channel: new types.InputChannel(peer), photo: new types.InputChatPhotoEmpty() });
|
|
1928
|
+
}
|
|
1929
|
+
else if (peer instanceof types.InputPeerChat) {
|
|
1930
|
+
await this.api.messages.editChatPhoto({ chat_id: peer.chat_id, photo: new types.InputChatPhotoEmpty() });
|
|
1931
|
+
}
|
|
1932
|
+
}
|
|
1933
|
+
/**
|
|
1934
|
+
* Delete all messages sent by a specific member of a chat.
|
|
1935
|
+
*
|
|
1936
|
+
* @method
|
|
1937
|
+
* @param chatId The identifier of the chat. Must be a supergroup.
|
|
1938
|
+
* @param memberId The identifier of the member.
|
|
1939
|
+
*/
|
|
1940
|
+
async deleteChatMemberMessages(chatId, memberId) {
|
|
1941
|
+
return await __classPrivateFieldGet(this, _Client_messageManager, "f").deleteChatMemberMessages(chatId, memberId);
|
|
1942
|
+
}
|
|
1943
|
+
/**
|
|
1944
|
+
* Pin a message in a chat.
|
|
1945
|
+
*
|
|
1946
|
+
* @method
|
|
1947
|
+
* @param chatId The identifier of the chat that contains the message.
|
|
1948
|
+
* @param messageId The message's identifier.
|
|
1949
|
+
*/
|
|
1950
|
+
async pinMessage(chatId, messageId, params) {
|
|
1951
|
+
return await __classPrivateFieldGet(this, _Client_messageManager, "f").pinMessage(chatId, messageId, params);
|
|
1952
|
+
}
|
|
1953
|
+
/**
|
|
1954
|
+
* Unpin a pinned message.
|
|
1955
|
+
*
|
|
1956
|
+
* @method
|
|
1957
|
+
* @param chatId The identifier of the chat that contains the message.
|
|
1958
|
+
* @param messageId The message's identifier.
|
|
1959
|
+
*/
|
|
1960
|
+
async unpinMessage(chatId, messageId) {
|
|
1961
|
+
return await __classPrivateFieldGet(this, _Client_messageManager, "f").unpinMessage(chatId, messageId);
|
|
1962
|
+
}
|
|
1963
|
+
/**
|
|
1964
|
+
* Unpin all pinned messages.
|
|
1965
|
+
*
|
|
1966
|
+
* @method
|
|
1967
|
+
* @param chatId The identifier of the chat.
|
|
1968
|
+
*/
|
|
1969
|
+
async unpinMessages(chatId) {
|
|
1970
|
+
return await __classPrivateFieldGet(this, _Client_messageManager, "f").unpinMessages(chatId);
|
|
1971
|
+
}
|
|
1972
|
+
/**
|
|
1973
|
+
* Ban a member from a chat.
|
|
1974
|
+
*
|
|
1975
|
+
* @method
|
|
1976
|
+
* @param chatId The identifier of the chat.
|
|
1977
|
+
* @param memberId The identifier of the member.
|
|
1978
|
+
*/
|
|
1979
|
+
async banChatMember(chatId, memberId, params) {
|
|
1980
|
+
const chat = await this.getInputPeer(chatId);
|
|
1981
|
+
if (!(chat instanceof types.InputPeerChannel) && !(chat instanceof types.InputPeerChat)) {
|
|
1982
|
+
throw new Error("Invalid chat ID");
|
|
1983
|
+
}
|
|
1984
|
+
const member = await this.getInputPeer(memberId);
|
|
1985
|
+
if (chat instanceof types.InputPeerChannel) {
|
|
1986
|
+
if (params?.deleteMessages) {
|
|
1987
|
+
try {
|
|
1988
|
+
await this.deleteChatMemberMessages(chatId, memberId);
|
|
1989
|
+
}
|
|
1990
|
+
catch {
|
|
1991
|
+
//
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
await this.api.channels.editBanned({
|
|
1995
|
+
channel: new types.InputChannel(chat),
|
|
1996
|
+
participant: member,
|
|
1997
|
+
banned_rights: new types.ChatBannedRights({
|
|
1998
|
+
until_date: params?.untilDate ? toUnixTimestamp(params.untilDate) : 0,
|
|
1999
|
+
view_messages: true,
|
|
2000
|
+
send_messages: true,
|
|
2001
|
+
send_media: true,
|
|
2002
|
+
send_stickers: true,
|
|
2003
|
+
send_gifs: true,
|
|
2004
|
+
send_games: true,
|
|
2005
|
+
send_inline: true,
|
|
2006
|
+
embed_links: true,
|
|
2007
|
+
}),
|
|
2008
|
+
});
|
|
2009
|
+
}
|
|
2010
|
+
else if (chat instanceof types.InputPeerChat) {
|
|
2011
|
+
if (!(member instanceof types.InputPeerUser)) {
|
|
2012
|
+
throw new Error("Invalid user ID");
|
|
2918
2013
|
}
|
|
2014
|
+
await this.api.messages.deleteChatUser({
|
|
2015
|
+
chat_id: chat.chat_id,
|
|
2016
|
+
user_id: new types.InputUser(member),
|
|
2017
|
+
revoke_history: params?.deleteMessages ? true : undefined,
|
|
2018
|
+
});
|
|
2919
2019
|
}
|
|
2920
2020
|
}
|
|
2021
|
+
/**
|
|
2022
|
+
* Unban a member from a chat.
|
|
2023
|
+
*
|
|
2024
|
+
* @method
|
|
2025
|
+
* @param chatId The identifier of the chat. Must be a supergroup.
|
|
2026
|
+
* @param memberId The identifier of the member.
|
|
2027
|
+
*/
|
|
2028
|
+
async unbanChatMember(chatId, memberId) {
|
|
2029
|
+
const chat = await this.getInputPeer(chatId);
|
|
2030
|
+
if (!(chat instanceof types.InputPeerChannel)) {
|
|
2031
|
+
throw new Error("Invalid chat ID");
|
|
2032
|
+
}
|
|
2033
|
+
const member = await this.getInputPeer(memberId);
|
|
2034
|
+
await this.api.channels.editBanned({
|
|
2035
|
+
channel: new types.InputChannel(chat),
|
|
2036
|
+
participant: member,
|
|
2037
|
+
banned_rights: new types.ChatBannedRights({ until_date: 0 }),
|
|
2038
|
+
});
|
|
2039
|
+
}
|
|
2040
|
+
/**
|
|
2041
|
+
* Kick a member from a chat. Same as a banChatMember call followed by unbanChatMember.
|
|
2042
|
+
*
|
|
2043
|
+
* @method
|
|
2044
|
+
* @param chatId The identifier of the chat. Must be a supergroup.
|
|
2045
|
+
* @param memberId The identifier of the member.
|
|
2046
|
+
*/
|
|
2047
|
+
async kickChatMember(chatId, memberId) {
|
|
2048
|
+
await this.banChatMember(chatId, memberId);
|
|
2049
|
+
await this.unbanChatMember(chatId, memberId);
|
|
2050
|
+
}
|
|
2051
|
+
/**
|
|
2052
|
+
* Set the rights of a chat member.
|
|
2053
|
+
*
|
|
2054
|
+
* @method
|
|
2055
|
+
* @param chatId The identifier of the chat. Must be a supergroup.
|
|
2056
|
+
* @param memberId The identifier of a member.
|
|
2057
|
+
*/
|
|
2058
|
+
async setChatMemberRights(chatId, memberId, params) {
|
|
2059
|
+
const chat = await this.getInputPeer(chatId);
|
|
2060
|
+
if (!(chat instanceof types.InputPeerChannel)) {
|
|
2061
|
+
throw new Error("Invalid chat ID");
|
|
2062
|
+
}
|
|
2063
|
+
const member = await this.getInputPeer(memberId);
|
|
2064
|
+
await this.api.channels.editBanned({
|
|
2065
|
+
channel: new types.InputChannel(chat),
|
|
2066
|
+
participant: member,
|
|
2067
|
+
banned_rights: new types.ChatBannedRights({
|
|
2068
|
+
until_date: params?.untilDate ? toUnixTimestamp(params.untilDate) : 0,
|
|
2069
|
+
send_messages: params?.rights?.canSendMessages ? true : undefined,
|
|
2070
|
+
send_audios: params?.rights?.canSendAudio ? true : undefined,
|
|
2071
|
+
send_docs: params?.rights?.canSendDocuments ? true : undefined,
|
|
2072
|
+
send_photos: params?.rights?.canSendPhotos ? true : undefined,
|
|
2073
|
+
send_videos: params?.rights?.canSendVideos ? true : undefined,
|
|
2074
|
+
send_roundvideos: params?.rights?.canSendVideoNotes ? true : undefined,
|
|
2075
|
+
send_voices: params?.rights?.canSendVoice ? true : undefined,
|
|
2076
|
+
send_polls: params?.rights?.canSendPolls ? true : undefined,
|
|
2077
|
+
send_stickers: params?.rights?.canSendStickers ? true : undefined,
|
|
2078
|
+
send_gifs: params?.rights?.canSendAnimations ? true : undefined,
|
|
2079
|
+
send_games: params?.rights?.canSendGames ? true : undefined,
|
|
2080
|
+
send_inline: params?.rights?.canSendInlineBotResults ? true : undefined,
|
|
2081
|
+
embed_links: params?.rights?.canAddWebPagePreviews ? true : undefined,
|
|
2082
|
+
change_info: params?.rights?.canChangeInfo ? true : undefined,
|
|
2083
|
+
invite_users: params?.rights?.canInviteUsers ? true : undefined,
|
|
2084
|
+
pin_messages: params?.rights?.canPinMessages ? true : undefined,
|
|
2085
|
+
manage_topics: params?.rights?.canManageTopics ? true : undefined,
|
|
2086
|
+
}),
|
|
2087
|
+
});
|
|
2088
|
+
}
|
|
2921
2089
|
}
|
|
2922
|
-
|
|
2090
|
+
_Client_parseText = function _Client_parseText(text, params) {
|
|
2091
|
+
const entities_ = params?.entities ?? [];
|
|
2092
|
+
const parseMode = params?.parseMode ?? __classPrivateFieldGet(this, _Client_parseMode, "f");
|
|
2093
|
+
switch (parseMode) {
|
|
2094
|
+
case null:
|
|
2095
|
+
break;
|
|
2096
|
+
case "HTML": {
|
|
2097
|
+
const [newText, entitiesToPush] = parseHtml(text);
|
|
2098
|
+
text = newText;
|
|
2099
|
+
for (const entity of entitiesToPush) {
|
|
2100
|
+
entities_.push(entity);
|
|
2101
|
+
}
|
|
2102
|
+
break;
|
|
2103
|
+
}
|
|
2104
|
+
default:
|
|
2105
|
+
UNREACHABLE();
|
|
2106
|
+
}
|
|
2107
|
+
const entities = entities_?.length > 0 ? entities_.map((v) => messageEntityToTlObject(v)) : undefined;
|
|
2108
|
+
return [text, entities];
|
|
2109
|
+
}, _Client_getMe = async function _Client_getMe() {
|
|
2923
2110
|
if (__classPrivateFieldGet(this, _Client_lastGetMe, "f") != null) {
|
|
2924
2111
|
return __classPrivateFieldGet(this, _Client_lastGetMe, "f");
|
|
2925
2112
|
}
|
|
@@ -2928,38 +2115,12 @@ _a = Client, _Client_getMe = async function _Client_getMe() {
|
|
|
2928
2115
|
__classPrivateFieldSet(this, _Client_lastGetMe, user, "f");
|
|
2929
2116
|
return user;
|
|
2930
2117
|
}
|
|
2931
|
-
},
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
const maybeUpdate = await this.storage.getFirstUpdate(boxId);
|
|
2938
|
-
if (maybeUpdate == null) {
|
|
2939
|
-
break;
|
|
2940
|
-
}
|
|
2941
|
-
const [key, update] = maybeUpdate;
|
|
2942
|
-
for (let i = 0; i < 100; ++i) {
|
|
2943
|
-
try {
|
|
2944
|
-
const handle = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleUpdate).call(this, update);
|
|
2945
|
-
handle: for (let i = 0; i < 2; ++i) {
|
|
2946
|
-
try {
|
|
2947
|
-
await handle();
|
|
2948
|
-
break handle;
|
|
2949
|
-
}
|
|
2950
|
-
catch {
|
|
2951
|
-
continue handle;
|
|
2952
|
-
}
|
|
2953
|
-
}
|
|
2954
|
-
break;
|
|
2955
|
-
}
|
|
2956
|
-
catch (err) {
|
|
2957
|
-
d("#handleUpdate error: %o", err);
|
|
2958
|
-
}
|
|
2959
|
-
}
|
|
2960
|
-
await this.storage.set(key, null);
|
|
2961
|
-
} while (true);
|
|
2962
|
-
__classPrivateFieldGet(this, _Client_handleUpdatesSet, "f").delete(boxId);
|
|
2118
|
+
}, _Client_handleCtxUpdate = async function _Client_handleCtxUpdate(update) {
|
|
2119
|
+
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, update), resolve);
|
|
2120
|
+
}, _Client_queueHandleCtxUpdate = function _Client_queueHandleCtxUpdate(update) {
|
|
2121
|
+
__classPrivateFieldGet(this, _Client_updateManager, "f").getHandleUpdateQueue(UpdateManager.MAIN_BOX_ID).add(async () => {
|
|
2122
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, update);
|
|
2123
|
+
});
|
|
2963
2124
|
}, _Client_handleUpdate = async function _Client_handleUpdate(update) {
|
|
2964
2125
|
const promises = new Array();
|
|
2965
2126
|
if (update instanceof types.UpdateUserName) {
|
|
@@ -2977,7 +2138,7 @@ _a = Client, _Client_getMe = async function _Client_getMe() {
|
|
|
2977
2138
|
if (update.message instanceof types.Message || update.message instanceof types.MessageService) {
|
|
2978
2139
|
const chatId = peerToChatId(update.message.peer_id);
|
|
2979
2140
|
await this.storage.setMessage(chatId, update.message.id, update.message);
|
|
2980
|
-
promises.push(
|
|
2141
|
+
promises.push(__classPrivateFieldGet(this, _Client_chatListManager, "f").reassignChatLastMessage(chatId));
|
|
2981
2142
|
}
|
|
2982
2143
|
}
|
|
2983
2144
|
if (update instanceof types.UpdateMessageReactions) {
|
|
@@ -2990,7 +2151,7 @@ _a = Client, _Client_getMe = async function _Client_getMe() {
|
|
|
2990
2151
|
const forwards = message.forwards ?? 0;
|
|
2991
2152
|
const recentReactions = update.reactions.recent_reactions ?? [];
|
|
2992
2153
|
const reactions = update.reactions.results.map((v) => constructMessageReaction(v, recentReactions));
|
|
2993
|
-
promises.push(
|
|
2154
|
+
promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { messageInteractions: { chatId, messageId: update.msg_id, reactions, views, forwards } }));
|
|
2994
2155
|
}
|
|
2995
2156
|
}
|
|
2996
2157
|
else if (update instanceof types.UpdateChannelMessageViews || update instanceof types.UpdateChannelMessageForwards) {
|
|
@@ -3007,7 +2168,7 @@ _a = Client, _Client_getMe = async function _Client_getMe() {
|
|
|
3007
2168
|
const forwards = message.forwards ?? 0;
|
|
3008
2169
|
const recentReactions = message.reactions?.recent_reactions ?? [];
|
|
3009
2170
|
const reactions = message.reactions?.results.map((v) => constructMessageReaction(v, recentReactions)) ?? [];
|
|
3010
|
-
promises.push(
|
|
2171
|
+
promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { messageInteractions: { chatId, messageId: update.id, reactions, views, forwards } }));
|
|
3011
2172
|
}
|
|
3012
2173
|
}
|
|
3013
2174
|
if (update instanceof types.UpdateNewMessage ||
|
|
@@ -3021,16 +2182,14 @@ _a = Client, _Client_getMe = async function _Client_getMe() {
|
|
|
3021
2182
|
shouldIgnore = __classPrivateFieldGet(this, _Client_ignoreOutgoing, "f");
|
|
3022
2183
|
}
|
|
3023
2184
|
if (!shouldIgnore) {
|
|
3024
|
-
const message = await
|
|
2185
|
+
const message = await __classPrivateFieldGet(this, _Client_messageManager, "f").constructMessage(update.message);
|
|
3025
2186
|
promises.push((async () => {
|
|
3026
|
-
let context;
|
|
3027
2187
|
if (update instanceof types.UpdateNewMessage || update instanceof types.UpdateNewChannelMessage) {
|
|
3028
|
-
|
|
2188
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { message });
|
|
3029
2189
|
}
|
|
3030
2190
|
else {
|
|
3031
|
-
|
|
2191
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { editedMessage: message });
|
|
3032
2192
|
}
|
|
3033
|
-
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, context, resolve);
|
|
3034
2193
|
})());
|
|
3035
2194
|
}
|
|
3036
2195
|
}
|
|
@@ -3046,12 +2205,12 @@ _a = Client, _Client_getMe = async function _Client_getMe() {
|
|
|
3046
2205
|
if (deletedMessages.length > 0) {
|
|
3047
2206
|
promises.push((async () => {
|
|
3048
2207
|
try {
|
|
3049
|
-
await __classPrivateFieldGet(this,
|
|
2208
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { deletedMessages });
|
|
3050
2209
|
}
|
|
3051
2210
|
finally {
|
|
3052
2211
|
for (const { chatId, messageId } of deletedMessages) {
|
|
3053
2212
|
await this.storage.setMessage(chatId, messageId, null);
|
|
3054
|
-
await __classPrivateFieldGet(this,
|
|
2213
|
+
await __classPrivateFieldGet(this, _Client_chatListManager, "f").reassignChatLastMessage(chatId);
|
|
3055
2214
|
}
|
|
3056
2215
|
}
|
|
3057
2216
|
})());
|
|
@@ -3069,424 +2228,58 @@ _a = Client, _Client_getMe = async function _Client_getMe() {
|
|
|
3069
2228
|
if (deletedMessages.length > 0) {
|
|
3070
2229
|
promises.push((async () => {
|
|
3071
2230
|
try {
|
|
3072
|
-
await __classPrivateFieldGet(this,
|
|
2231
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { deletedMessages });
|
|
3073
2232
|
}
|
|
3074
2233
|
finally {
|
|
3075
2234
|
for (const { chatId, messageId } of deletedMessages) {
|
|
3076
2235
|
await this.storage.setMessage(chatId, messageId, null);
|
|
3077
|
-
await __classPrivateFieldGet(this,
|
|
2236
|
+
await __classPrivateFieldGet(this, _Client_chatListManager, "f").reassignChatLastMessage(chatId);
|
|
3078
2237
|
}
|
|
3079
2238
|
}
|
|
3080
2239
|
})());
|
|
3081
2240
|
}
|
|
3082
2241
|
}
|
|
3083
2242
|
if (update instanceof types.UpdateBotCallbackQuery || update instanceof types.UpdateInlineBotCallbackQuery) {
|
|
3084
|
-
promises.push(
|
|
2243
|
+
promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { callbackQuery: await constructCallbackQuery(update, this[getEntity].bind(this), __classPrivateFieldGet(this, _Client_messageManager, "f").getMessageWithReply.bind(this)) }));
|
|
3085
2244
|
}
|
|
3086
2245
|
else if (update instanceof types.UpdateBotInlineQuery) {
|
|
3087
|
-
promises.push(
|
|
2246
|
+
promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { inlineQuery: await constructInlineQuery(update, this[getEntity].bind(this)) }));
|
|
3088
2247
|
}
|
|
3089
2248
|
else if (update instanceof types.UpdateBotInlineSend) {
|
|
3090
|
-
promises.push(
|
|
2249
|
+
promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { chosenInlineResult: await constructChosenInlineResult(update, this[getEntity].bind(this)) }));
|
|
3091
2250
|
}
|
|
3092
2251
|
else if (update instanceof types.UpdateBotMessageReactions) {
|
|
3093
|
-
const
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
2252
|
+
const messageReactionCount = await constructMessageReactionCount(update, this[getEntity].bind(this));
|
|
2253
|
+
if (messageReactionCount) {
|
|
2254
|
+
promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { messageReactionCount }));
|
|
2255
|
+
}
|
|
2256
|
+
}
|
|
2257
|
+
else if (update instanceof types.UpdateBotMessageReaction) {
|
|
2258
|
+
const messageReactions = await constructMessageReactions(update, this[getEntity].bind(this));
|
|
2259
|
+
if (messageReactions) {
|
|
2260
|
+
promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { messageReactions }));
|
|
3101
2261
|
}
|
|
3102
2262
|
}
|
|
3103
2263
|
if (update instanceof types.UpdatePinnedDialogs) {
|
|
3104
|
-
await __classPrivateFieldGet(this,
|
|
2264
|
+
await __classPrivateFieldGet(this, _Client_chatListManager, "f").handleUpdatePinnedDialogs(update);
|
|
2265
|
+
}
|
|
2266
|
+
else if (update instanceof types.UpdateFolderPeers) {
|
|
2267
|
+
await __classPrivateFieldGet(this, _Client_chatListManager, "f").handelUpdateFolderPeers(update);
|
|
3105
2268
|
}
|
|
3106
2269
|
if (update instanceof types.UpdateChannel) {
|
|
3107
|
-
|
|
3108
|
-
const channel = await this[getEntity](peer);
|
|
3109
|
-
if (channel != null && "left" in channel && channel.left) {
|
|
3110
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_removeChat).call(this, peerToChatId(peer));
|
|
3111
|
-
}
|
|
3112
|
-
else if (channel instanceof types.ChannelForbidden) {
|
|
3113
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_removeChat).call(this, peerToChatId(peer));
|
|
3114
|
-
}
|
|
3115
|
-
else if (channel instanceof types.Channel) {
|
|
3116
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updateOrAddChat).call(this, peerToChatId(peer));
|
|
3117
|
-
}
|
|
2270
|
+
await __classPrivateFieldGet(this, _Client_chatListManager, "f").handleUpdateChannel(update);
|
|
3118
2271
|
}
|
|
3119
|
-
else if (update instanceof types.UpdateChat) {
|
|
3120
|
-
|
|
3121
|
-
const chat = await this[getEntity](peer);
|
|
3122
|
-
if (chat != null && "left" in chat && chat.left) {
|
|
3123
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_removeChat).call(this, peerToChatId(peer));
|
|
3124
|
-
}
|
|
3125
|
-
else if (chat instanceof types.ChatForbidden) {
|
|
3126
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_removeChat).call(this, peerToChatId(peer));
|
|
3127
|
-
}
|
|
3128
|
-
else if (chat instanceof types.Chat) {
|
|
3129
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updateOrAddChat).call(this, peerToChatId(peer));
|
|
3130
|
-
}
|
|
2272
|
+
else if (update instanceof types.UpdateChat) {
|
|
2273
|
+
await __classPrivateFieldGet(this, _Client_chatListManager, "f").handleUpdateChat(update);
|
|
3131
2274
|
}
|
|
3132
2275
|
else if (update instanceof types.UpdateUser || update instanceof types.UpdateUserName) {
|
|
3133
|
-
|
|
3134
|
-
const chat = await this[getEntity](peer);
|
|
3135
|
-
if (chat != null) {
|
|
3136
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updateOrAddChat).call(this, peerToChatId(peer));
|
|
3137
|
-
}
|
|
2276
|
+
await __classPrivateFieldGet(this, _Client_chatListManager, "f").handleUpdateUser(update);
|
|
3138
2277
|
}
|
|
3139
2278
|
return () => Promise.all(promises);
|
|
3140
|
-
}, _Client_constructReplyMarkup = async function _Client_constructReplyMarkup(params) {
|
|
3141
|
-
if (params?.replyMarkup) {
|
|
3142
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "replyMarkup");
|
|
3143
|
-
return replyMarkupToTlObject(params.replyMarkup, __classPrivateFieldGet(this, _Client_usernameResolver, "f").bind(this));
|
|
3144
|
-
}
|
|
3145
2279
|
}, _Client_setMyInfo =
|
|
3146
2280
|
//#endregion
|
|
3147
2281
|
async function _Client_setMyInfo(info) {
|
|
3148
2282
|
await this.api.bots.setBotInfo({ bot: new types.InputUserSelf(), ...info });
|
|
3149
2283
|
}, _Client_getMyInfo = function _Client_getMyInfo(languageCode) {
|
|
3150
2284
|
return this.api.bots.getBotInfo({ bot: new types.InputUserSelf(), lang_code: languageCode ?? "" });
|
|
3151
|
-
}, _Client_resolveFileId = function _Client_resolveFileId(maybeFileId, expectedFileType) {
|
|
3152
|
-
let fileId = null;
|
|
3153
|
-
try {
|
|
3154
|
-
fileId = FileID.decode(maybeFileId);
|
|
3155
|
-
}
|
|
3156
|
-
catch (err) {
|
|
3157
|
-
d("fileId: %o", err);
|
|
3158
|
-
}
|
|
3159
|
-
if (fileId != null) {
|
|
3160
|
-
if (fileId.fileType != expectedFileType) {
|
|
3161
|
-
UNREACHABLE();
|
|
3162
|
-
}
|
|
3163
|
-
if (fileId.params.mediaId == undefined || fileId.params.accessHash == undefined || fileId.params.fileReference == undefined) {
|
|
3164
|
-
UNREACHABLE();
|
|
3165
|
-
}
|
|
3166
|
-
return {
|
|
3167
|
-
id: fileId.params.mediaId,
|
|
3168
|
-
access_hash: fileId.params.accessHash,
|
|
3169
|
-
file_reference: fileId.params.fileReference,
|
|
3170
|
-
};
|
|
3171
|
-
}
|
|
3172
|
-
return null;
|
|
3173
|
-
}, _Client_sendMedia = async function _Client_sendMedia(chatId, media, params) {
|
|
3174
|
-
const peer = await this.getInputPeer(chatId);
|
|
3175
|
-
const randomId = getRandomId();
|
|
3176
|
-
const silent = params?.disableNotification ? true : undefined;
|
|
3177
|
-
const noforwards = params?.protectContent ? true : undefined;
|
|
3178
|
-
const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined; // TODO: check default sendAs
|
|
3179
|
-
const replyMarkup = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params);
|
|
3180
|
-
const caption_ = params?.caption;
|
|
3181
|
-
const parseResult = caption_ !== undefined ? __classPrivateFieldGet(this, _Client_instances, "m", _Client_parseText).call(this, caption_, { parseMode: params?.parseMode, entities: params?.captionEntities }) : undefined;
|
|
3182
|
-
const caption = parseResult === undefined ? undefined : parseResult[0];
|
|
3183
|
-
const captionEntities = parseResult === undefined ? undefined : parseResult[1];
|
|
3184
|
-
const result = await this.api.messages.sendMedia({
|
|
3185
|
-
peer,
|
|
3186
|
-
random_id: randomId,
|
|
3187
|
-
silent,
|
|
3188
|
-
noforwards,
|
|
3189
|
-
reply_markup: replyMarkup,
|
|
3190
|
-
reply_to: __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyTo).call(this, params),
|
|
3191
|
-
send_as: sendAs,
|
|
3192
|
-
media,
|
|
3193
|
-
message: caption ?? "",
|
|
3194
|
-
entities: captionEntities,
|
|
3195
|
-
});
|
|
3196
|
-
return await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
|
|
3197
|
-
}, _Client_sendDocumentInner = async function _Client_sendDocumentInner(chatId, document, params, fileType, otherAttribs, urlSupported = false) {
|
|
3198
|
-
let media = null;
|
|
3199
|
-
const spoiler = params?.hasSpoiler ? true : undefined;
|
|
3200
|
-
if (typeof document === "string") {
|
|
3201
|
-
const fileId = __classPrivateFieldGet(this, _Client_instances, "m", _Client_resolveFileId).call(this, document, fileType);
|
|
3202
|
-
if (fileId != null) {
|
|
3203
|
-
media = new types.InputMediaDocument({
|
|
3204
|
-
id: new types.InputDocument(fileId),
|
|
3205
|
-
spoiler,
|
|
3206
|
-
});
|
|
3207
|
-
}
|
|
3208
|
-
}
|
|
3209
|
-
if (media == null) {
|
|
3210
|
-
if (typeof document === "string" && isHttpUrl(document)) {
|
|
3211
|
-
if (!urlSupported) {
|
|
3212
|
-
throw new Error("URL not supported");
|
|
3213
|
-
}
|
|
3214
|
-
media = new types.InputMediaDocumentExternal({ url: document, spoiler });
|
|
3215
|
-
}
|
|
3216
|
-
else {
|
|
3217
|
-
const [contents, fileName_] = await getFileContents(document);
|
|
3218
|
-
const fileName = params?.fileName ?? fileName_;
|
|
3219
|
-
const mimeType = params?.mimeType ?? contentType(fileName.split(".").slice(-1)[0]) ?? "application/octet-stream";
|
|
3220
|
-
const file = await this.upload(contents, { fileName, chunkSize: params?.chunkSize, signal: params?.signal });
|
|
3221
|
-
let thumb = undefined;
|
|
3222
|
-
if (params?.thumbnail) {
|
|
3223
|
-
const [thumbContents, fileName__] = await getFileContents(params.thumbnail);
|
|
3224
|
-
thumb = await this.upload(thumbContents, { fileName: fileName__, chunkSize: params?.chunkSize, signal: params?.signal });
|
|
3225
|
-
}
|
|
3226
|
-
media = new types.InputMediaUploadedDocument({
|
|
3227
|
-
file,
|
|
3228
|
-
thumb,
|
|
3229
|
-
spoiler,
|
|
3230
|
-
attributes: [new types.DocumentAttributeFilename({ file_name: fileName }), ...otherAttribs],
|
|
3231
|
-
mime_type: mimeType,
|
|
3232
|
-
});
|
|
3233
|
-
}
|
|
3234
|
-
}
|
|
3235
|
-
const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendMedia).call(this, chatId, media, params);
|
|
3236
|
-
return message;
|
|
3237
|
-
}, _Client_sendChatUpdate = async function _Client_sendChatUpdate(chatId, added) {
|
|
3238
|
-
try {
|
|
3239
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertUser).call(this, "");
|
|
3240
|
-
}
|
|
3241
|
-
catch {
|
|
3242
|
-
return;
|
|
3243
|
-
}
|
|
3244
|
-
const [chat] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
|
|
3245
|
-
const update = chat === undefined ? { deletedChat: { chatId } } : added ? { newChat: chat } : { editedChat: chat };
|
|
3246
|
-
__classPrivateFieldGet(this, _Client_instances, "m", _Client_getHandleUpdateQueue).call(this, __classPrivateFieldGet(this, _Client_mainBoxId, "f")).add(async () => {
|
|
3247
|
-
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, update), resolve);
|
|
3248
|
-
});
|
|
3249
|
-
}, _Client_reassignChatLastMessage = async function _Client_reassignChatLastMessage(chatId, add = false, sendUpdate = true) {
|
|
3250
|
-
try {
|
|
3251
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertUser).call(this, "");
|
|
3252
|
-
}
|
|
3253
|
-
catch {
|
|
3254
|
-
return () => Promise.resolve();
|
|
3255
|
-
}
|
|
3256
|
-
const [chat, listId] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
|
|
3257
|
-
if (!chat && !add) {
|
|
3258
|
-
return () => Promise.resolve();
|
|
3259
|
-
}
|
|
3260
|
-
const message_ = await this.storage.getLastMessage(chatId);
|
|
3261
|
-
if (message_ != null) {
|
|
3262
|
-
const message = await constructMessage(message_, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this));
|
|
3263
|
-
if (chat) {
|
|
3264
|
-
chat.order = getChatOrder(message, chat.pinned);
|
|
3265
|
-
chat.lastMessage = message;
|
|
3266
|
-
await this.storage.setChat(listId, chatId, chat.pinned, message.id, message.date);
|
|
3267
|
-
}
|
|
3268
|
-
else {
|
|
3269
|
-
const pinnedChats = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getPinnedChats).call(this, listId);
|
|
3270
|
-
const chat = await constructChat3(chatId, pinnedChats.indexOf(chatId), message, this[getEntity].bind(this));
|
|
3271
|
-
if (chat == null) {
|
|
3272
|
-
UNREACHABLE();
|
|
3273
|
-
}
|
|
3274
|
-
__classPrivateFieldGet(this, _Client_chats, "f").set(chatId, chat);
|
|
3275
|
-
await this.storage.setChat(listId, chatId, chat.pinned, chat.lastMessage?.id ?? 0, chat.lastMessage?.date ?? new Date(0));
|
|
3276
|
-
}
|
|
3277
|
-
if (sendUpdate) {
|
|
3278
|
-
return () => __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
|
|
3279
|
-
}
|
|
3280
|
-
return () => Promise.resolve();
|
|
3281
|
-
}
|
|
3282
|
-
const message = await this.getHistory(chatId, { limit: 1 }).then((v) => v[0]);
|
|
3283
|
-
if (message !== undefined) {
|
|
3284
|
-
if (chat) {
|
|
3285
|
-
chat.order = getChatOrder(message, chat.pinned);
|
|
3286
|
-
chat.lastMessage = message;
|
|
3287
|
-
await this.storage.setChat(listId, chatId, chat.pinned, message.id, message.date);
|
|
3288
|
-
}
|
|
3289
|
-
else {
|
|
3290
|
-
const pinnedChats = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getPinnedChats).call(this, listId);
|
|
3291
|
-
const chat = await constructChat3(chatId, pinnedChats.indexOf(chatId), message, this[getEntity].bind(this));
|
|
3292
|
-
if (chat == null) {
|
|
3293
|
-
UNREACHABLE();
|
|
3294
|
-
}
|
|
3295
|
-
__classPrivateFieldGet(this, _Client_chats, "f").set(chatId, chat);
|
|
3296
|
-
}
|
|
3297
|
-
if (sendUpdate) {
|
|
3298
|
-
return () => __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
|
|
3299
|
-
}
|
|
3300
|
-
return () => Promise.resolve();
|
|
3301
|
-
}
|
|
3302
|
-
if (chat) {
|
|
3303
|
-
chat.order = getChatOrder(undefined, chat.pinned);
|
|
3304
|
-
chat.lastMessage = undefined;
|
|
3305
|
-
if (sendUpdate) {
|
|
3306
|
-
return () => __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
|
|
3307
|
-
}
|
|
3308
|
-
}
|
|
3309
|
-
return () => Promise.resolve();
|
|
3310
|
-
}, _Client_tryGetChatId = function _Client_tryGetChatId(username) {
|
|
3311
|
-
username = username.toLowerCase();
|
|
3312
|
-
for (const chat of __classPrivateFieldGet(this, _Client_chats, "f").values()) {
|
|
3313
|
-
if ("username" in chat) {
|
|
3314
|
-
if (chat.username === username || chat.also?.some((v) => v.toLowerCase() === username)) {
|
|
3315
|
-
return chat.id;
|
|
3316
|
-
}
|
|
3317
|
-
}
|
|
3318
|
-
}
|
|
3319
|
-
for (const chat of __classPrivateFieldGet(this, _Client_archivedChats, "f").values()) {
|
|
3320
|
-
if ("username" in chat) {
|
|
3321
|
-
if (chat.username === username || chat.also?.some((v) => v.toLowerCase() === username)) {
|
|
3322
|
-
return chat.id;
|
|
3323
|
-
}
|
|
3324
|
-
}
|
|
3325
|
-
}
|
|
3326
|
-
return null;
|
|
3327
|
-
}, _Client_getChatAnywhere = function _Client_getChatAnywhere(chatId) {
|
|
3328
|
-
let chat = __classPrivateFieldGet(this, _Client_chats, "f").get(chatId);
|
|
3329
|
-
if (chat) {
|
|
3330
|
-
return [chat, 0];
|
|
3331
|
-
}
|
|
3332
|
-
chat = __classPrivateFieldGet(this, _Client_archivedChats, "f").get(chatId);
|
|
3333
|
-
if (chat) {
|
|
3334
|
-
return [chat, 1];
|
|
3335
|
-
}
|
|
3336
|
-
return [undefined, -1];
|
|
3337
|
-
}, _Client_getChatList = function _Client_getChatList(listId) {
|
|
3338
|
-
switch (listId) {
|
|
3339
|
-
case 0:
|
|
3340
|
-
return __classPrivateFieldGet(this, _Client_chats, "f");
|
|
3341
|
-
case 1:
|
|
3342
|
-
return __classPrivateFieldGet(this, _Client_archivedChats, "f");
|
|
3343
|
-
default:
|
|
3344
|
-
throw new Error("Invalid chat list: " + listId);
|
|
3345
|
-
}
|
|
3346
|
-
}, _Client_loadChatsFromStorage = async function _Client_loadChatsFromStorage() {
|
|
3347
|
-
const chats = await this.storage.getChats(0);
|
|
3348
|
-
const archivedChats = await this.storage.getChats(1);
|
|
3349
|
-
for (const { chatId, pinned, topMessageId } of chats) {
|
|
3350
|
-
const chat = await constructChat4(chatId, pinned, topMessageId, this[getEntity].bind(this), this.getMessage.bind(this));
|
|
3351
|
-
if (chat == null) {
|
|
3352
|
-
continue;
|
|
3353
|
-
}
|
|
3354
|
-
__classPrivateFieldGet(this, _Client_chats, "f").set(chat.id, chat);
|
|
3355
|
-
}
|
|
3356
|
-
for (const { chatId, pinned, topMessageId } of archivedChats) {
|
|
3357
|
-
const chat = await constructChat4(chatId, pinned, topMessageId, this[getEntity].bind(this), this.getMessage.bind(this));
|
|
3358
|
-
if (chat == null) {
|
|
3359
|
-
continue;
|
|
3360
|
-
}
|
|
3361
|
-
__classPrivateFieldGet(this, _Client_archivedChats, "f").set(chat.id, chat);
|
|
3362
|
-
}
|
|
3363
|
-
__classPrivateFieldSet(this, _Client_chatsLoadedFromStorage, true, "f");
|
|
3364
|
-
}, _Client_getLoadedChats = function _Client_getLoadedChats(listId) {
|
|
3365
|
-
const chats_ = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, listId);
|
|
3366
|
-
const chats = new Array();
|
|
3367
|
-
for (const chat of chats_.values()) {
|
|
3368
|
-
chats.push(chat);
|
|
3369
|
-
}
|
|
3370
|
-
return chats
|
|
3371
|
-
.sort((a, b) => b.id - a.id)
|
|
3372
|
-
.sort((a, b) => b.order.localeCompare(a.order));
|
|
3373
|
-
}, _Client_loadPinnedChats = async function _Client_loadPinnedChats() {
|
|
3374
|
-
const [pinnedChats, pinnedArchiveChats] = await Promise.all([this.storage.getPinnedChats(0), this.storage.getPinnedChats(1)]);
|
|
3375
|
-
if (pinnedChats != null && pinnedArchiveChats != null) {
|
|
3376
|
-
__classPrivateFieldSet(this, _Client_pinnedChats, pinnedChats, "f");
|
|
3377
|
-
__classPrivateFieldSet(this, _Client_pinnedArchiveChats, pinnedArchiveChats, "f");
|
|
3378
|
-
__classPrivateFieldSet(this, _Client_storageHadPinnedChats, true, "f");
|
|
3379
|
-
}
|
|
3380
|
-
__classPrivateFieldSet(this, _Client_pinnedChatsLoaded, true, "f");
|
|
3381
|
-
}, _Client_fetchPinnedChats = async function _Client_fetchPinnedChats(listId = null) {
|
|
3382
|
-
if (listId == null || listId == 0) {
|
|
3383
|
-
const dialogs = await this.api.messages.getPinnedDialogs({ folder_id: 0 });
|
|
3384
|
-
const pinnedChats = new Array();
|
|
3385
|
-
for (const dialog of dialogs.dialogs) {
|
|
3386
|
-
pinnedChats.push(peerToChatId(dialog.peer));
|
|
3387
|
-
}
|
|
3388
|
-
__classPrivateFieldSet(this, _Client_pinnedChats, pinnedChats, "f");
|
|
3389
|
-
await this.storage.setPinnedChats(0, __classPrivateFieldGet(this, _Client_pinnedChats, "f"));
|
|
3390
|
-
}
|
|
3391
|
-
if (listId == null || listId == 1) {
|
|
3392
|
-
const dialogs = await this.api.messages.getPinnedDialogs({ folder_id: 1 });
|
|
3393
|
-
const pinnedArchiveChats = new Array();
|
|
3394
|
-
for (const dialog of dialogs.dialogs) {
|
|
3395
|
-
pinnedArchiveChats.push(peerToChatId(dialog.peer));
|
|
3396
|
-
}
|
|
3397
|
-
__classPrivateFieldSet(this, _Client_pinnedArchiveChats, pinnedArchiveChats, "f");
|
|
3398
|
-
await this.storage.setPinnedChats(1, __classPrivateFieldGet(this, _Client_pinnedArchiveChats, "f"));
|
|
3399
|
-
}
|
|
3400
|
-
if (listId != null && listId != 0 && listId != 1) {
|
|
3401
|
-
UNREACHABLE();
|
|
3402
|
-
}
|
|
3403
|
-
}, _Client_getPinnedChats = async function _Client_getPinnedChats(listId) {
|
|
3404
|
-
if (!__classPrivateFieldGet(this, _Client_pinnedChatsLoaded, "f")) {
|
|
3405
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_loadPinnedChats).call(this);
|
|
3406
|
-
}
|
|
3407
|
-
if (!__classPrivateFieldGet(this, _Client_storageHadPinnedChats, "f")) {
|
|
3408
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchPinnedChats).call(this);
|
|
3409
|
-
}
|
|
3410
|
-
switch (listId) {
|
|
3411
|
-
case 0:
|
|
3412
|
-
return __classPrivateFieldGet(this, _Client_pinnedChats, "f");
|
|
3413
|
-
case 1:
|
|
3414
|
-
return __classPrivateFieldGet(this, _Client_pinnedArchiveChats, "f");
|
|
3415
|
-
default:
|
|
3416
|
-
UNREACHABLE();
|
|
3417
|
-
}
|
|
3418
|
-
}, _Client_updateOrAddChat = async function _Client_updateOrAddChat(chatId) {
|
|
3419
|
-
const [chat, listId] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
|
|
3420
|
-
if (chat !== undefined) {
|
|
3421
|
-
const newChat = await constructChat3(chatId, chat.pinned, chat.lastMessage, this[getEntity].bind(this));
|
|
3422
|
-
if (newChat != null) {
|
|
3423
|
-
__classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, listId).set(chatId, newChat);
|
|
3424
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
|
|
3425
|
-
}
|
|
3426
|
-
}
|
|
3427
|
-
else {
|
|
3428
|
-
const chat = await constructChat4(chatId, -1, -1, this[getEntity].bind(this), this.getMessage.bind(this));
|
|
3429
|
-
if (chat != null) {
|
|
3430
|
-
__classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, 0).set(chatId, chat);
|
|
3431
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId, false, false);
|
|
3432
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, true);
|
|
3433
|
-
}
|
|
3434
|
-
}
|
|
3435
|
-
}, _Client_removeChat = async function _Client_removeChat(chatId) {
|
|
3436
|
-
const [chat, listId] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
|
|
3437
|
-
if (chat !== undefined) {
|
|
3438
|
-
__classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, listId).delete(chatId);
|
|
3439
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
|
|
3440
|
-
}
|
|
3441
|
-
}, _Client_updatePinnedChats = async function _Client_updatePinnedChats(update) {
|
|
3442
|
-
const listId = update.folder_id ?? 0;
|
|
3443
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchPinnedChats).call(this, update.folder_id);
|
|
3444
|
-
const chats = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, listId);
|
|
3445
|
-
const pinnedChats = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getPinnedChats).call(this, listId);
|
|
3446
|
-
for (const [i, chatId] of pinnedChats.entries()) {
|
|
3447
|
-
const chat = chats.get(chatId);
|
|
3448
|
-
if (chat !== undefined) {
|
|
3449
|
-
chat.order = getChatOrder(chat.lastMessage, i);
|
|
3450
|
-
chat.pinned = i;
|
|
3451
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
|
|
3452
|
-
}
|
|
3453
|
-
}
|
|
3454
|
-
for (const chat of chats.values()) {
|
|
3455
|
-
if (chat.pinned != -1 && pinnedChats.indexOf(chat.id) == -1) {
|
|
3456
|
-
chat.order = getChatOrder(chat.lastMessage, -1);
|
|
3457
|
-
chat.pinned = -1;
|
|
3458
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chat.id, false);
|
|
3459
|
-
}
|
|
3460
|
-
}
|
|
3461
|
-
await this.storage.setPinnedChats(listId, await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getPinnedChats).call(this, listId));
|
|
3462
|
-
}, _Client_fetchChats = async function _Client_fetchChats(listId, limit, after) {
|
|
3463
|
-
const dialogs = await this.api.messages.getDialogs({
|
|
3464
|
-
limit,
|
|
3465
|
-
offset_id: after?.lastMessage?.id ?? 0,
|
|
3466
|
-
offset_date: after?.lastMessage?.date ? Math.ceil(after.lastMessage.date.getTime() / 1000) : 0,
|
|
3467
|
-
offset_peer: after ? await this.getInputPeer(after.id) : new types.InputPeerEmpty(),
|
|
3468
|
-
hash: 0n,
|
|
3469
|
-
folder_id: listId,
|
|
3470
|
-
});
|
|
3471
|
-
const pinnedChats = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getPinnedChats).call(this, listId);
|
|
3472
|
-
if (!(dialogs instanceof types.messages.Dialogs) && !(dialogs instanceof types.messages.DialogsSlice)) {
|
|
3473
|
-
UNREACHABLE();
|
|
3474
|
-
}
|
|
3475
|
-
if (dialogs.dialogs.length < limit) {
|
|
3476
|
-
await this.storage.setHasAllChats(listId, true);
|
|
3477
|
-
}
|
|
3478
|
-
const chats = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, listId);
|
|
3479
|
-
for (const dialog of dialogs.dialogs) {
|
|
3480
|
-
const chat = await constructChat(dialog, dialogs, pinnedChats, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this));
|
|
3481
|
-
chats.set(chat.id, chat);
|
|
3482
|
-
await this.storage.setChat(listId, chat.id, chat.pinned, chat.lastMessage?.id ?? 0, chat.lastMessage?.date ?? new Date(0));
|
|
3483
|
-
}
|
|
3484
|
-
}, _Client_sendReaction = async function _Client_sendReaction(chatId, messageId, reactions, params) {
|
|
3485
|
-
await this.api.messages.sendReaction({
|
|
3486
|
-
peer: await this.getInputPeer(chatId),
|
|
3487
|
-
msg_id: messageId,
|
|
3488
|
-
reaction: reactions.map((v) => reactionToTlObject(v)),
|
|
3489
|
-
big: params?.big ? true : undefined,
|
|
3490
|
-
add_to_recent: params?.addToRecents ? true : undefined,
|
|
3491
|
-
});
|
|
3492
2285
|
};
|