@mtkruto/node 0.1.132 → 0.1.134

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.
Files changed (194) hide show
  1. package/esm/3_errors.d.ts +519 -510
  2. package/esm/3_errors.js +521 -509
  3. package/esm/3_types.d.ts +19 -7
  4. package/esm/3_types.js +19 -7
  5. package/esm/4_constants.d.ts +2 -2
  6. package/esm/4_constants.js +2 -2
  7. package/esm/4_errors.d.ts +7 -12
  8. package/esm/4_errors.js +6 -7
  9. package/esm/5_client.d.ts +3 -3
  10. package/esm/5_client.js +3 -3
  11. package/esm/client/0_utilities.d.ts +30 -2
  12. package/esm/client/0_utilities.js +13 -5
  13. package/esm/client/1_composer.d.ts +30 -0
  14. package/esm/client/{4_composer.js → 1_composer.js} +15 -2
  15. package/esm/client/2_client_plain.d.ts +1 -1
  16. package/esm/client/2_client_plain.js +1 -1
  17. package/esm/client/{3_types.d.ts → 3_params.d.ts} +68 -172
  18. package/esm/client/3_params.js +1 -0
  19. package/esm/client/{5_client.d.ts → 4_client.d.ts} +89 -57
  20. package/esm/client/{5_client.js → 4_client.js} +499 -308
  21. package/esm/client/5_composer.d.ts +4 -0
  22. package/esm/client/5_composer.js +3 -0
  23. package/esm/storage/0_storage.d.ts +4 -1
  24. package/esm/storage/0_storage.js +36 -7
  25. package/esm/storage/1_storage_indexed_db.d.ts +6 -2
  26. package/esm/storage/1_storage_indexed_db.js +7 -5
  27. package/esm/storage/1_storage_local_storage.d.ts +1 -1
  28. package/esm/storage/1_storage_local_storage.js +1 -1
  29. package/esm/storage/1_storage_memory.d.ts +1 -1
  30. package/esm/storage/1_storage_memory.js +1 -1
  31. package/esm/storage/1_storage_session_storage.d.ts +1 -1
  32. package/esm/storage/1_storage_session_storage.js +1 -1
  33. package/esm/tl/2_types.d.ts +313 -24
  34. package/esm/tl/2_types.js +982 -46
  35. package/esm/tl/3_functions.d.ts +95 -32
  36. package/esm/tl/3_functions.js +227 -66
  37. package/esm/tl/3_utilities.d.ts +1 -0
  38. package/esm/tl/3_utilities.js +14 -0
  39. package/esm/tl/6_message.js +1 -1
  40. package/esm/types/0_authorization_state.d.ts +5 -0
  41. package/esm/types/0_authorization_state.js +1 -0
  42. package/esm/types/0_chat_photo.d.ts +22 -21
  43. package/esm/types/0_connection_state.d.ts +17 -0
  44. package/esm/types/0_connection_state.js +1 -0
  45. package/esm/types/0_giveaway_parameters.d.ts +9 -0
  46. package/esm/types/0_giveaway_parameters.js +9 -0
  47. package/esm/types/0_login_url.d.ts +0 -4
  48. package/esm/types/0_mask_position.d.ts +0 -4
  49. package/esm/types/0_message_entity.d.ts +91 -74
  50. package/esm/types/0_message_identifier.d.ts +4 -0
  51. package/esm/types/0_message_identifier.js +1 -0
  52. package/esm/types/0_network_statistics_entry.d.ts +4 -0
  53. package/esm/types/0_network_statistics_entry.js +1 -0
  54. package/esm/types/0_reaction.d.ts +14 -10
  55. package/esm/types/0_reaction.js +29 -1
  56. package/esm/types/1__getters.d.ts +3 -0
  57. package/esm/types/1_bot_command_scope.d.ts +32 -27
  58. package/esm/types/1_chat_p.d.ts +77 -68
  59. package/esm/types/1_giveaway.d.ts +8 -0
  60. package/esm/types/1_giveaway.js +7 -0
  61. package/esm/types/1_keyboard_button.d.ts +41 -57
  62. package/esm/types/1_keyboard_button.js +3 -0
  63. package/esm/types/1_message_reaction.d.ts +14 -0
  64. package/esm/types/1_message_reaction.js +22 -0
  65. package/esm/types/1_network_statistics.d.ts +5 -0
  66. package/esm/types/1_network_statistics.js +1 -0
  67. package/esm/types/1_poll.d.ts +0 -13
  68. package/esm/types/1_reaction_count.d.ts +7 -0
  69. package/esm/types/1_reaction_count.js +6 -0
  70. package/esm/types/1_user.d.ts +2 -2
  71. package/esm/types/2_game.d.ts +0 -7
  72. package/esm/types/2_inline_keyboard_button.d.ts +36 -37
  73. package/esm/types/2_inline_query.d.ts +0 -6
  74. package/esm/types/2_message_interactions.d.ts +8 -0
  75. package/esm/types/2_message_interactions.js +1 -0
  76. package/esm/types/2_message_reaction_count.d.ts +8 -0
  77. package/esm/types/2_message_reaction_count.js +1 -0
  78. package/esm/types/2_reply_keyboard_markup.d.ts +0 -7
  79. package/esm/types/3_inline_keyboard_markup.d.ts +0 -2
  80. package/esm/types/4_message.d.ts +457 -0
  81. package/esm/types/{3_message.js → 4_message.js} +216 -129
  82. package/{script/types/4_callback_query.d.ts → esm/types/5_callback_query.d.ts} +1 -1
  83. package/esm/types/5_chat.d.ts +37 -0
  84. package/esm/types/{4_chat.js → 5_chat.js} +2 -2
  85. package/esm/types/6_update.d.ts +134 -0
  86. package/esm/types/6_update.js +1 -0
  87. package/package.json +1 -1
  88. package/script/3_errors.d.ts +519 -510
  89. package/script/3_errors.js +533 -520
  90. package/script/3_types.d.ts +19 -7
  91. package/script/3_types.js +19 -7
  92. package/script/4_constants.d.ts +2 -2
  93. package/script/4_constants.js +2 -2
  94. package/script/4_errors.d.ts +7 -12
  95. package/script/4_errors.js +5 -6
  96. package/script/5_client.d.ts +3 -3
  97. package/script/5_client.js +3 -3
  98. package/script/client/0_utilities.d.ts +30 -2
  99. package/script/client/0_utilities.js +15 -6
  100. package/script/client/1_composer.d.ts +30 -0
  101. package/script/client/{4_composer.js → 1_composer.js} +17 -4
  102. package/script/client/2_client_plain.d.ts +1 -1
  103. package/script/client/2_client_plain.js +2 -2
  104. package/script/client/{3_types.d.ts → 3_params.d.ts} +68 -172
  105. package/script/client/3_params.js +2 -0
  106. package/script/client/{5_client.d.ts → 4_client.d.ts} +89 -57
  107. package/script/client/{5_client.js → 4_client.js} +505 -314
  108. package/script/client/5_composer.d.ts +4 -0
  109. package/script/client/{6_composer.js → 5_composer.js} +2 -2
  110. package/script/storage/0_storage.d.ts +4 -1
  111. package/script/storage/0_storage.js +36 -7
  112. package/script/storage/1_storage_indexed_db.d.ts +6 -2
  113. package/script/storage/1_storage_indexed_db.js +7 -5
  114. package/script/storage/1_storage_local_storage.d.ts +1 -1
  115. package/script/storage/1_storage_local_storage.js +1 -1
  116. package/script/storage/1_storage_memory.d.ts +1 -1
  117. package/script/storage/1_storage_memory.js +1 -1
  118. package/script/storage/1_storage_session_storage.d.ts +1 -1
  119. package/script/storage/1_storage_session_storage.js +1 -1
  120. package/script/tl/2_types.d.ts +313 -24
  121. package/script/tl/2_types.js +1169 -217
  122. package/script/tl/3_functions.d.ts +95 -32
  123. package/script/tl/3_functions.js +241 -77
  124. package/script/tl/3_utilities.d.ts +1 -0
  125. package/script/tl/3_utilities.js +16 -1
  126. package/script/tl/6_message.js +1 -1
  127. package/script/types/0_authorization_state.d.ts +5 -0
  128. package/script/types/0_authorization_state.js +2 -0
  129. package/script/types/0_chat_photo.d.ts +22 -21
  130. package/script/types/0_connection_state.d.ts +17 -0
  131. package/script/types/0_connection_state.js +2 -0
  132. package/script/types/0_giveaway_parameters.d.ts +9 -0
  133. package/script/types/0_giveaway_parameters.js +13 -0
  134. package/script/types/0_login_url.d.ts +0 -4
  135. package/script/types/0_mask_position.d.ts +0 -4
  136. package/script/types/0_message_entity.d.ts +91 -74
  137. package/script/types/0_message_identifier.d.ts +4 -0
  138. package/script/types/0_message_identifier.js +2 -0
  139. package/script/types/0_network_statistics_entry.d.ts +4 -0
  140. package/script/types/0_network_statistics_entry.js +2 -0
  141. package/script/types/0_reaction.d.ts +14 -10
  142. package/script/types/0_reaction.js +33 -0
  143. package/script/types/1__getters.d.ts +3 -0
  144. package/script/types/1_bot_command_scope.d.ts +32 -27
  145. package/script/types/1_chat_p.d.ts +77 -68
  146. package/script/types/1_giveaway.d.ts +8 -0
  147. package/script/types/1_giveaway.js +11 -0
  148. package/script/types/1_keyboard_button.d.ts +41 -57
  149. package/script/types/1_keyboard_button.js +3 -0
  150. package/script/types/1_message_reaction.d.ts +14 -0
  151. package/script/types/1_message_reaction.js +26 -0
  152. package/script/types/1_network_statistics.d.ts +5 -0
  153. package/script/types/1_network_statistics.js +2 -0
  154. package/script/types/1_poll.d.ts +0 -13
  155. package/script/types/1_reaction_count.d.ts +7 -0
  156. package/script/types/1_reaction_count.js +10 -0
  157. package/script/types/1_user.d.ts +2 -2
  158. package/script/types/2_game.d.ts +0 -7
  159. package/script/types/2_inline_keyboard_button.d.ts +36 -37
  160. package/script/types/2_inline_query.d.ts +0 -6
  161. package/script/types/2_message_interactions.d.ts +8 -0
  162. package/script/types/2_message_interactions.js +2 -0
  163. package/script/types/2_message_reaction_count.d.ts +8 -0
  164. package/script/types/2_message_reaction_count.js +2 -0
  165. package/script/types/2_reply_keyboard_markup.d.ts +0 -7
  166. package/script/types/3_inline_keyboard_markup.d.ts +0 -2
  167. package/script/types/4_message.d.ts +457 -0
  168. package/script/types/{3_message.js → 4_message.js} +218 -130
  169. package/{esm/types/4_callback_query.d.ts → script/types/5_callback_query.d.ts} +1 -1
  170. package/script/types/5_chat.d.ts +37 -0
  171. package/script/types/{4_chat.js → 5_chat.js} +3 -3
  172. package/script/types/6_update.d.ts +134 -0
  173. package/script/types/6_update.js +2 -0
  174. package/esm/client/3_types.js +0 -11
  175. package/esm/client/4_composer.d.ts +0 -31
  176. package/esm/client/6_composer.d.ts +0 -4
  177. package/esm/client/6_composer.js +0 -3
  178. package/esm/types/3_message.d.ts +0 -182
  179. package/esm/types/4_chat.d.ts +0 -34
  180. package/script/client/3_types.js +0 -15
  181. package/script/client/4_composer.d.ts +0 -31
  182. package/script/client/6_composer.d.ts +0 -4
  183. package/script/types/3_message.d.ts +0 -182
  184. package/script/types/4_chat.d.ts +0 -34
  185. /package/esm/client/{1_client_abstract.d.ts → 0_client_abstract.d.ts} +0 -0
  186. /package/esm/client/{1_client_abstract.js → 0_client_abstract.js} +0 -0
  187. /package/esm/types/{0_audio.d.ts → 1_audio.d.ts} +0 -0
  188. /package/esm/types/{0_audio.js → 1_audio.js} +0 -0
  189. /package/esm/types/{4_callback_query.js → 5_callback_query.js} +0 -0
  190. /package/script/client/{1_client_abstract.d.ts → 0_client_abstract.d.ts} +0 -0
  191. /package/script/client/{1_client_abstract.js → 0_client_abstract.js} +0 -0
  192. /package/script/types/{0_audio.d.ts → 1_audio.d.ts} +0 -0
  193. /package/script/types/{0_audio.js → 1_audio.js} +0 -0
  194. /package/script/types/{4_callback_query.js → 5_callback_query.js} +0 -0
@@ -9,22 +9,21 @@ 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, _a, _Client_auth, _Client_sessionId, _Client_state, _Client_promises, _Client_toAcknowledge, _Client_updateState, _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_assertUser, _Client_assertBot, _Client_fetchState, _Client_connectionInited, _Client_initConnection, _Client_lastPropagatedAuthorizationState, _Client_propagateAuthorizationState, _Client_selfId, _Client_getSelfId, _Client_receiveLoop, _Client_pingLoopAbortSignal, _Client_pingInterval, _Client_pingLoop, _Client_pingLoopStarted, _Client_autoStarted, _Client_lastMsgId, _Client_invoke, _Client_handleInvokeError, _Client_processChats, _Client_processUsers, _Client_handleUpdateQueue, _Client_processUpdatesQueue, _Client_checkGap, _Client_checkChannelGap, _Client_lastUpdates, _Client_processUpdates, _Client_setUpdateStateDate, _Client_setUpdatePts, _Client_getLocalState, _Client_recoverUpdateGap, _Client_recoverChannelUpdateGap, _Client_getChannelAccessHash, _Client_getInputPeerInner, _Client_updatesToMessages, _Client_resolveSendAs, _Client_constructReplyTo, _Client_parseText, _Client_getMessagesInner, _Client_downloadInner, _Client_lastGetMe, _Client_getMe, _Client_handleUpdate, _Client_usernameResolver, _Client_constructReplyMarkup, _Client_assertMsgHas, _Client_handle, _Client_setMyInfo, _Client_getMyInfo, _Client_resolveFileId, _Client_sendMedia, _Client_sendDocumentInner, _Client_sendChatUpdate, _Client_reassignChatLastMessage, _Client_chats, _Client_archivedChats, _Client_chatsLoadedFromStorage, _Client_tryGetChatId, _Client_getChatAnywhere, _Client_getChatList, _Client_loadChatsFromStorage, _Client_getLoadedChats, _Client_pinnedChats, _Client_pinnedArchiveChats, _Client_storageHadPinnedChats, _Client_pinnedChatsLoaded, _Client_loadPinnedChats, _Client_fetchPinnedChats, _Client_getPinnedChats, _Client_updateOrAddChat, _Client_removeChat, _Client_updatePinnedChats, _Client_fetchChats;
12
+ var _Client_instances, _a, _Client_auth, _Client_sessionId, _Client_state, _Client_promises, _Client_toAcknowledge, _Client_updateState, _Client_guaranteeUpdateDelivery, _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_assertUser, _Client_assertBot, _Client_fetchState, _Client_connectionInited, _Client_initConnection, _Client_lastPropagatedAuthorizationState, _Client_propagateAuthorizationState, _Client_selfId, _Client_getSelfId, _Client_receiveLoop, _Client_pingLoopAbortSignal, _Client_pingInterval, _Client_pingLoop, _Client_pingLoopStarted, _Client_autoStarted, _Client_lastMsgId, _Client_invoke, _Client_handleInvokeError, _Client_processChats, _Client_processUsers, _Client_handleUpdateQueues, _Client_getHandleUpdateQueue, _Client_processUpdatesQueue, _Client_checkGap, _Client_checkChannelGap, _Client_channelUpdateQueues, _Client_processChannelPtsUpdateInner, _Client_queueUpdate, _Client_processChannelPtsUpdate, _Client_mainBoxId, _Client_processPtsUpdateInner, _Client_ptsUpdateQueue, _Client_processPtsUpdate, _Client_lastUpdates, _Client_processUpdates, _Client_setUpdateStateDate, _Client_setUpdatePts, _Client_getLocalState, _Client_recoverUpdateGap, _Client_recoverChannelUpdateGap, _Client_getChannelAccessHash, _Client_getInputPeerInner, _Client_updatesToMessages, _Client_resolveSendAs, _Client_constructReplyTo, _Client_parseText, _Client_getMessagesInner, _Client_downloadInner, _Client_lastGetMe, _Client_getMe, _Client_handleUpdatesSet, _Client_handleStoredUpdates, _Client_handleUpdate, _Client_usernameResolver, _Client_constructReplyMarkup, _Client_handle, _Client_setMyInfo, _Client_getMyInfo, _Client_resolveFileId, _Client_sendMedia, _Client_sendDocumentInner, _Client_sendChatUpdate, _Client_reassignChatLastMessage, _Client_chats, _Client_archivedChats, _Client_chatsLoadedFromStorage, _Client_tryGetChatId, _Client_getChatAnywhere, _Client_getChatList, _Client_loadChatsFromStorage, _Client_getLoadedChats, _Client_pinnedChats, _Client_pinnedArchiveChats, _Client_storageHadPinnedChats, _Client_pinnedChatsLoaded, _Client_loadPinnedChats, _Client_fetchPinnedChats, _Client_getPinnedChats, _Client_updateOrAddChat, _Client_removeChat, _Client_updatePinnedChats, _Client_fetchChats, _Client_sendReaction;
13
13
  import { contentType, debug, extension, gunzip, Mutex } from "../0_deps.js";
14
14
  import { bigIntFromBuffer, cleanObject, drop, getRandomBigInt, getRandomId, mod, mustPrompt, mustPromptOneOf, Queue, sha1, 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";
15
+ import { as, functions, getChannelChatId, inputPeerToPeer, Message_, MessageContainer, name, peerToChatId, RPCResult, TLError, TLReader, types } from "../2_tl.js";
16
16
  import { StorageMemory } from "../3_storage.js";
17
- import { botCommandScopeToTlObject, constructCallbackQuery, constructChat, constructChat2, constructChat3, constructChat4, constructChosenInlineResult, constructDocument, constructInlineQuery, constructMessage, constructUser, FileID, FileType, FileUniqueID, FileUniqueType, getChatOrder, inlineQueryResultToTlObject, messageEntityToTlObject, replyMarkupToTlObject, ThumbnailSource } from "../3_types.js";
17
+ import { assertMessageType, botCommandScopeToTlObject, constructCallbackQuery, constructChat, constructChat2, constructChat3, constructChat4, constructChatP, constructChosenInlineResult, constructDocument, constructInlineQuery, constructMessage, constructMessageReaction, constructReactionCount, constructUser, FileID, FileType, FileUniqueID, FileUniqueType, getChatOrder, inlineQueryResultToTlObject, messageEntityToTlObject, reactionEqual, reactionToTlObject, replyMarkupToTlObject, ThumbnailSource } from "../3_types.js";
18
18
  import { ACK_THRESHOLD, APP_VERSION, CHANNEL_DIFFERENCE_LIMIT_BOT, CHANNEL_DIFFERENCE_LIMIT_USER, DEVICE_MODEL, LANG_CODE, LANG_PACK, LAYER, MAX_CHANNEL_ID, MAX_CHAT_ID, STICKER_SET_NAME_TTL, 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
+ import { ClientAbstract } from "./0_client_abstract.js";
20
21
  import { parseHtml } from "./0_html.js";
21
22
  import { decryptMessage, encryptMessage, getMessageId } from "./0_message.js";
22
23
  import { checkPassword } from "./0_password.js";
23
- import { getFileContents, getUsername, isChannelPtsUpdate, isHttpUrl, isPtsUpdate, resolve } from "./0_utilities.js";
24
- import { ClientAbstract } from "./1_client_abstract.js";
24
+ import { getChatListId, getFileContents, getUsername, isChannelPtsUpdate, isHttpUrl, isPtsUpdate, resolve } from "./0_utilities.js";
25
+ import { Composer, concat, flatten, skip } from "./1_composer.js";
25
26
  import { ClientPlain } from "./2_client_plain.js";
26
- import { getChatListId } from "./3_types.js";
27
- import { Composer, concat, flatten, skip } from "./4_composer.js";
28
27
  const d = debug("Client");
29
28
  const dGap = debug("Client/recoverUpdateGap");
30
29
  const dGapC = debug("Client/recoverChannelUpdateGap");
@@ -71,6 +70,7 @@ export class Client extends ClientAbstract {
71
70
  _Client_promises.set(this, new Map());
72
71
  _Client_toAcknowledge.set(this, new Set());
73
72
  _Client_updateState.set(this, void 0);
73
+ _Client_guaranteeUpdateDelivery.set(this, void 0);
74
74
  Object.defineProperty(this, "storage", {
75
75
  enumerable: true,
76
76
  configurable: true,
@@ -180,163 +180,179 @@ export class Client extends ClientAbstract {
180
180
  })
181
181
  });
182
182
  _Client_constructContext.set(this, async (update) => {
183
- const msg = update.message ?? update.editedMessage ?? update.callbackQuery?.message;
183
+ const msg = "message" in update ? update.message : "editedMessage" in update ? update.editedMessage : "callbackQuery" in update ? update.callbackQuery.message : undefined;
184
+ const reactions = "messageInteractions" in update ? update.messageInteractions : undefined;
184
185
  const mustGetMsg = () => {
185
186
  if (msg !== undefined) {
186
- return msg;
187
+ return { chatId: msg.chat.id, messageId: msg.id };
188
+ }
189
+ else if (reactions !== undefined) {
190
+ return { chatId: reactions.chatId, messageId: reactions.messageId };
187
191
  }
188
192
  else {
189
193
  UNREACHABLE();
190
194
  }
191
195
  };
192
196
  const chat = msg?.chat;
193
- const from = update.callbackQuery?.from ?? update.inlineQuery?.from ?? update.message?.from ?? update.editedMessage?.from;
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;
194
198
  const senderChat = msg?.senderChat;
195
- const getReplyToMessageId = (quote, effectiveMessage) => {
196
- const shouldQuote = quote === undefined ? effectiveMessage.chat.type != "private" : quote;
197
- const replyToMessageId = shouldQuote ? effectiveMessage.id : undefined;
199
+ const getReplyToMessageId = (quote, chatId, messageId) => {
200
+ const isPrivate = chatId > 0;
201
+ const shouldQuote = quote === undefined ? !isPrivate : quote;
202
+ const replyToMessageId = shouldQuote ? messageId : undefined;
198
203
  return replyToMessageId;
199
204
  };
200
- const me = update.connectionState !== undefined ? __classPrivateFieldGet(this, _Client_lastGetMe, "f") : (update.authorizationState !== undefined && !update.authorizationState.authorized) ? __classPrivateFieldGet(this, _Client_lastGetMe, "f") : await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getMe).call(this);
201
- return cleanObject({
205
+ const me = "connectionState" in update ? __classPrivateFieldGet(this, _Client_lastGetMe, "f") : ("authorizationState" in update && !update.authorizationState.authorized) ? __classPrivateFieldGet(this, _Client_lastGetMe, "f") : await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getMe).call(this);
206
+ const context = {
202
207
  ...update,
203
208
  client: this,
204
- me: me == null ? undefined : me,
205
- msg,
206
- chat,
207
- from,
208
- senderChat,
209
+ me: (me == null ? undefined : me),
210
+ msg: msg,
211
+ chat: chat,
212
+ from: from,
213
+ senderChat: senderChat,
214
+ get toJSON() {
215
+ return () => update;
216
+ },
209
217
  reply: (text, params) => {
210
- const effectiveMessage = mustGetMsg();
211
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
212
- return this.sendMessage(effectiveMessage.chat.id, text, { ...params, replyToMessageId });
218
+ const { chatId, messageId } = mustGetMsg();
219
+ const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
220
+ return this.sendMessage(chatId, text, { ...params, replyToMessageId });
213
221
  },
214
222
  replyPoll: (question, options, params) => {
215
- const effectiveMessage = mustGetMsg();
216
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
217
- return this.sendPoll(effectiveMessage.chat.id, question, options, { ...params, replyToMessageId });
223
+ const { chatId, messageId } = mustGetMsg();
224
+ const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
225
+ return this.sendPoll(chatId, question, options, { ...params, replyToMessageId });
218
226
  },
219
227
  replyPhoto: (photo, params) => {
220
- const effectiveMessage = mustGetMsg();
221
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
222
- return this.sendPhoto(effectiveMessage.chat.id, photo, { ...params, replyToMessageId });
228
+ const { chatId, messageId } = mustGetMsg();
229
+ const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
230
+ return this.sendPhoto(chatId, photo, { ...params, replyToMessageId });
223
231
  },
224
232
  replyDocument: (document, params) => {
225
- const effectiveMessage = mustGetMsg();
226
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
227
- return this.sendDocument(effectiveMessage.chat.id, document, { ...params, replyToMessageId });
233
+ const { chatId, messageId } = mustGetMsg();
234
+ const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
235
+ return this.sendDocument(chatId, document, { ...params, replyToMessageId });
228
236
  },
229
237
  replyContact: (firstName, number, params) => {
230
- const effectiveMessage = mustGetMsg();
231
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
232
- return this.sendContact(effectiveMessage.chat.id, firstName, number, { ...params, replyToMessageId });
238
+ const { chatId, messageId } = mustGetMsg();
239
+ const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
240
+ return this.sendContact(chatId, firstName, number, { ...params, replyToMessageId });
233
241
  },
234
242
  replyLocation: (latitude, longitude, params) => {
235
- const effectiveMessage = mustGetMsg();
236
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
237
- return this.sendLocation(effectiveMessage.chat.id, latitude, longitude, { ...params, replyToMessageId });
243
+ const { chatId, messageId } = mustGetMsg();
244
+ const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
245
+ return this.sendLocation(chatId, latitude, longitude, { ...params, replyToMessageId });
238
246
  },
239
247
  replyDice: (params) => {
240
- const effectiveMessage = mustGetMsg();
241
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
242
- return this.sendDice(effectiveMessage.chat.id, { ...params, replyToMessageId });
248
+ const { chatId, messageId } = mustGetMsg();
249
+ const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
250
+ return this.sendDice(chatId, { ...params, replyToMessageId });
243
251
  },
244
252
  replyVenue: (latitude, longitude, title, address, params) => {
245
- const effectiveMessage = mustGetMsg();
246
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
247
- return this.sendVenue(effectiveMessage.chat.id, latitude, longitude, title, address, { ...params, replyToMessageId });
253
+ const { chatId, messageId } = mustGetMsg();
254
+ const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
255
+ return this.sendVenue(chatId, latitude, longitude, title, address, { ...params, replyToMessageId });
248
256
  },
249
- replyVideo: (document, params) => {
250
- const effectiveMessage = mustGetMsg();
251
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
252
- return this.sendDocument(effectiveMessage.chat.id, document, { ...params, replyToMessageId });
257
+ replyVideo: (video, params) => {
258
+ const { chatId, messageId } = mustGetMsg();
259
+ const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
260
+ return this.sendVideo(chatId, video, { ...params, replyToMessageId });
253
261
  },
254
262
  replyAnimation: (document, params) => {
255
- const effectiveMessage = mustGetMsg();
256
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
257
- return this.sendAnimation(effectiveMessage.chat.id, document, { ...params, replyToMessageId });
263
+ const { chatId, messageId } = mustGetMsg();
264
+ const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
265
+ return this.sendAnimation(chatId, document, { ...params, replyToMessageId });
258
266
  },
259
267
  replyVoice: (document, params) => {
260
- const effectiveMessage = mustGetMsg();
261
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
262
- return this.sendVoice(effectiveMessage.chat.id, document, { ...params, replyToMessageId });
268
+ const { chatId, messageId } = mustGetMsg();
269
+ const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
270
+ return this.sendVoice(chatId, document, { ...params, replyToMessageId });
263
271
  },
264
272
  replyAudio: (document, params) => {
265
- const effectiveMessage = mustGetMsg();
266
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
267
- return this.sendAudio(effectiveMessage.chat.id, document, { ...params, replyToMessageId });
273
+ const { chatId, messageId } = mustGetMsg();
274
+ const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
275
+ return this.sendAudio(chatId, document, { ...params, replyToMessageId });
268
276
  },
269
277
  replyVideoNote: (videoNote, params) => {
270
- const effectiveMessage = mustGetMsg();
271
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
272
- return this.sendVideoNote(effectiveMessage.chat.id, videoNote, { ...params, replyToMessageId });
278
+ const { chatId, messageId } = mustGetMsg();
279
+ const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
280
+ return this.sendVideoNote(chatId, videoNote, { ...params, replyToMessageId });
273
281
  },
274
282
  delete: () => {
275
- const effectiveMessage = mustGetMsg();
276
- return this.deleteMessage(effectiveMessage.chat.id, effectiveMessage.id);
283
+ const { chatId, messageId } = mustGetMsg();
284
+ return this.deleteMessage(chatId, messageId);
277
285
  },
278
286
  forward: (to, params) => {
279
- const effectiveMessage = mustGetMsg();
280
- return this.forwardMessage(effectiveMessage.chat.id, to, effectiveMessage.id, params);
287
+ const { chatId, messageId } = mustGetMsg();
288
+ return this.forwardMessage(chatId, to, messageId, params);
289
+ },
290
+ react: (reactions, params) => {
291
+ const { chatId, messageId } = mustGetMsg();
292
+ return this.setReactions(chatId, messageId, reactions, params);
281
293
  },
282
294
  answerCallbackQuery: (params) => {
283
- const { callbackQuery } = update;
284
- if (callbackQuery === undefined) {
295
+ if (!("callbackQuery" in update)) {
285
296
  UNREACHABLE();
286
297
  }
287
- return this.answerCallbackQuery(callbackQuery.id, params);
298
+ return this.answerCallbackQuery(update.callbackQuery.id, params);
288
299
  },
289
300
  answerInlineQuery: (results, params) => {
290
- const { inlineQuery } = update;
291
- if (inlineQuery == undefined) {
301
+ if (!("inlineQuery" in update)) {
292
302
  UNREACHABLE();
293
303
  }
294
- return this.answerInlineQuery(inlineQuery.id, results, params);
304
+ return this.answerInlineQuery(update.inlineQuery.id, results, params);
295
305
  },
296
306
  sendChatAction: (chatAction, params) => {
297
- const effectiveMessage = mustGetMsg();
298
- return this.sendChatAction(effectiveMessage.chat.id, chatAction, params);
307
+ const { chatId } = mustGetMsg();
308
+ return this.sendChatAction(chatId, chatAction, params);
299
309
  },
300
310
  editMessageText: (messageId, text, params) => {
301
- const effectiveMessage = mustGetMsg();
302
- return this.editMessageText(effectiveMessage.chat.id, messageId, text, params);
311
+ const { chatId } = mustGetMsg();
312
+ return this.editMessageText(chatId, messageId, text, params);
303
313
  },
304
314
  getMessage: (messageId) => {
305
- const effectiveMessage = mustGetMsg();
306
- return this.getMessage(effectiveMessage.chat.id, messageId);
315
+ const { chatId } = mustGetMsg();
316
+ return this.getMessage(chatId, messageId);
307
317
  },
308
318
  getMessages: (messageIds) => {
309
- const effectiveMessage = mustGetMsg();
310
- return this.getMessages(effectiveMessage.chat.id, messageIds);
319
+ const { chatId } = mustGetMsg();
320
+ return this.getMessages(chatId, messageIds);
311
321
  },
312
322
  forwardMessage: (to, messageId, params) => {
313
- const effectiveMessage = mustGetMsg();
314
- return this.forwardMessage(effectiveMessage.chat.id, to, messageId, params);
323
+ const { chatId } = mustGetMsg();
324
+ return this.forwardMessage(chatId, to, messageId, params);
315
325
  },
316
326
  forwardMessages: (to, messageIds, params) => {
317
- const effectiveMessage = mustGetMsg();
318
- return this.forwardMessages(effectiveMessage.chat.id, to, messageIds, params);
327
+ const { chatId } = mustGetMsg();
328
+ return this.forwardMessages(chatId, to, messageIds, params);
319
329
  },
320
330
  deleteMessage: (messageId, params) => {
321
- const effectiveMessage = mustGetMsg();
322
- return this.deleteMessage(effectiveMessage.chat.id, messageId, params);
331
+ const { chatId } = mustGetMsg();
332
+ return this.deleteMessage(chatId, messageId, params);
323
333
  },
324
334
  deleteMessages: (messageIds, params) => {
325
- const effectiveMessage = mustGetMsg();
326
- return this.deleteMessages(effectiveMessage.chat.id, messageIds, params);
335
+ const { chatId } = mustGetMsg();
336
+ return this.deleteMessages(chatId, messageIds, params);
327
337
  },
328
338
  setAvailableReactions: (availableReactions) => {
329
- const effectiveMessage = mustGetMsg();
330
- return this.setAvailableReactions(effectiveMessage.chat.id, availableReactions);
339
+ const { chatId } = mustGetMsg();
340
+ return this.setAvailableReactions(chatId, availableReactions);
331
341
  },
332
342
  addReaction: (messageId, reaction, params) => {
333
- const effectiveMessage = mustGetMsg();
334
- return this.addReaction(effectiveMessage.chat.id, messageId, reaction, params);
343
+ const { chatId } = mustGetMsg();
344
+ return this.addReaction(chatId, messageId, reaction, params);
335
345
  },
336
- get toJSON() {
337
- return () => update;
346
+ removeReaction: (messageId, reaction) => {
347
+ const { chatId } = mustGetMsg();
348
+ return this.removeReaction(chatId, messageId, reaction);
349
+ },
350
+ setReactions: (messageId, reactions, params) => {
351
+ const { chatId } = mustGetMsg();
352
+ return this.setReactions(chatId, messageId, reactions, params);
338
353
  },
339
- }, false);
354
+ };
355
+ return cleanObject(context, false);
340
356
  });
341
357
  _Client_lastPropagatedConnectionState.set(this, null);
342
358
  Object.defineProperty(this, "stateChangeHandler", {
@@ -394,10 +410,14 @@ export class Client extends ClientAbstract {
394
410
  },
395
411
  })
396
412
  });
397
- _Client_handleUpdateQueue.set(this, new Queue("handleUpdate"));
413
+ _Client_handleUpdateQueues.set(this, new Map());
398
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"));
399
418
  _Client_lastUpdates.set(this, new Date());
400
419
  _Client_lastGetMe.set(this, null);
420
+ _Client_handleUpdatesSet.set(this, new Set());
401
421
  _Client_usernameResolver.set(this, async (v) => {
402
422
  const inputPeer = await this.getInputPeer(v).then((v) => v[as](types.InputPeerUser));
403
423
  return new types.InputUser(inputPeer);
@@ -423,6 +443,7 @@ export class Client extends ClientAbstract {
423
443
  __classPrivateFieldSet(this, _Client_autoStart, params?.autoStart ?? true, "f");
424
444
  __classPrivateFieldSet(this, _Client_ignoreOutgoing, params?.ignoreOutgoing ?? null, "f");
425
445
  __classPrivateFieldSet(this, _Client_prefixes, params?.prefixes, "f");
446
+ __classPrivateFieldSet(this, _Client_guaranteeUpdateDelivery, params?.guaranteeUpdateDelivery ?? false, "f");
426
447
  const transportProvider = this.transportProvider;
427
448
  this.transportProvider = (params) => {
428
449
  const transport = transportProvider(params);
@@ -487,7 +508,7 @@ export class Client extends ClientAbstract {
487
508
  */
488
509
  async setDc(dc) {
489
510
  if (!__classPrivateFieldGet(this, _Client_storageInited, "f")) {
490
- await this.storage.init();
511
+ await this.storage.initialize();
491
512
  __classPrivateFieldSet(this, _Client_storageInited, true, "f");
492
513
  }
493
514
  if (await this.storage.getDc() != dc) {
@@ -509,7 +530,10 @@ export class Client extends ClientAbstract {
509
530
  const release = await __classPrivateFieldGet(this, _Client_connectMutex, "f").acquire();
510
531
  try {
511
532
  if (!__classPrivateFieldGet(this, _Client_storageInited, "f")) {
512
- await this.storage.init();
533
+ await this.storage.initialize();
534
+ if (!__classPrivateFieldGet(this, _Client_guaranteeUpdateDelivery, "f")) {
535
+ await this.storage.deleteUpdates();
536
+ }
513
537
  __classPrivateFieldSet(this, _Client_storageInited, true, "f");
514
538
  }
515
539
  const authKey = await this.storage.getAuthKey();
@@ -552,8 +576,8 @@ export class Client extends ClientAbstract {
552
576
  release();
553
577
  }
554
578
  }
555
- async [(_Client_auth = new WeakMap(), _Client_sessionId = new WeakMap(), _Client_state = new WeakMap(), _Client_promises = new WeakMap(), _Client_toAcknowledge = new WeakMap(), _Client_updateState = new WeakMap(), _Client_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_pingLoopStarted = new WeakMap(), _Client_autoStarted = new WeakMap(), _Client_lastMsgId = new WeakMap(), _Client_handleInvokeError = new WeakMap(), _Client_handleUpdateQueue = new WeakMap(), _Client_processUpdatesQueue = new WeakMap(), _Client_lastUpdates = new WeakMap(), _Client_lastGetMe = new WeakMap(), _Client_usernameResolver = new WeakMap(), _Client_handle = new WeakMap(), _Client_chats = new WeakMap(), _Client_archivedChats = new WeakMap(), _Client_chatsLoadedFromStorage = new WeakMap(), _Client_pinnedChats = new WeakMap(), _Client_pinnedArchiveChats = new WeakMap(), _Client_storageHadPinnedChats = new WeakMap(), _Client_pinnedChatsLoaded = new WeakMap(), _Client_instances = new WeakSet(), _Client_propagateConnectionState = function _Client_propagateConnectionState(connectionState) {
556
- __classPrivateFieldGet(this, _Client_handleUpdateQueue, "f").add(async () => {
579
+ async [(_Client_auth = new WeakMap(), _Client_sessionId = new WeakMap(), _Client_state = new WeakMap(), _Client_promises = new WeakMap(), _Client_toAcknowledge = new WeakMap(), _Client_updateState = new WeakMap(), _Client_guaranteeUpdateDelivery = 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_pingLoopStarted = new WeakMap(), _Client_autoStarted = new WeakMap(), _Client_lastMsgId = new WeakMap(), _Client_handleInvokeError = new WeakMap(), _Client_handleUpdateQueues = new WeakMap(), _Client_processUpdatesQueue = new WeakMap(), _Client_channelUpdateQueues = new WeakMap(), _Client_mainBoxId = new WeakMap(), _Client_ptsUpdateQueue = new WeakMap(), _Client_lastUpdates = new WeakMap(), _Client_lastGetMe = new WeakMap(), _Client_handleUpdatesSet = new WeakMap(), _Client_usernameResolver = new WeakMap(), _Client_handle = new WeakMap(), _Client_chats = new WeakMap(), _Client_archivedChats = new WeakMap(), _Client_chatsLoadedFromStorage = new WeakMap(), _Client_pinnedChats = new WeakMap(), _Client_pinnedArchiveChats = new WeakMap(), _Client_storageHadPinnedChats = new WeakMap(), _Client_pinnedChatsLoaded = new WeakMap(), _Client_instances = new WeakSet(), _Client_propagateConnectionState = function _Client_propagateConnectionState(connectionState) {
580
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_getHandleUpdateQueue).call(this, __classPrivateFieldGet(this, _Client_mainBoxId, "f")).add(async () => {
557
581
  await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { connectionState }), resolve);
558
582
  });
559
583
  __classPrivateFieldSet(this, _Client_lastPropagatedConnectionState, connectionState, "f");
@@ -884,11 +908,11 @@ export class Client extends ClientAbstract {
884
908
  dRecv("RPCResult: %s", (typeof result === "object" && name in result) ? result[name] : result.constructor.name);
885
909
  }
886
910
  const messageId = message.body.messageId;
911
+ const promise = __classPrivateFieldGet(this, _Client_promises, "f").get(messageId);
887
912
  const resolvePromise = () => {
888
- const promise = __classPrivateFieldGet(this, _Client_promises, "f").get(messageId);
889
913
  if (promise) {
890
914
  if (result instanceof types.Rpc_error) {
891
- promise.reject(upgradeInstance(result));
915
+ promise.reject(upgradeInstance(result, promise.call));
892
916
  }
893
917
  else {
894
918
  promise.resolve(result);
@@ -898,7 +922,7 @@ export class Client extends ClientAbstract {
898
922
  };
899
923
  if (result instanceof types._Updates || result instanceof types._Update) {
900
924
  __classPrivateFieldGet(this, _Client_processUpdatesQueue, "f").add(async () => {
901
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, result, true);
925
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, result, true, promise?.call);
902
926
  resolvePromise();
903
927
  });
904
928
  }
@@ -999,13 +1023,14 @@ export class Client extends ClientAbstract {
999
1023
  }
1000
1024
  },
1001
1025
  reject: () => { },
1026
+ call: function_,
1002
1027
  });
1003
1028
  return;
1004
1029
  }
1005
1030
  let result;
1006
1031
  try {
1007
1032
  result = await new Promise((resolve, reject) => {
1008
- __classPrivateFieldGet(this, _Client_promises, "f").set(message.id, { resolve, reject });
1033
+ __classPrivateFieldGet(this, _Client_promises, "f").set(message.id, { resolve, reject, call: function_ });
1009
1034
  });
1010
1035
  }
1011
1036
  catch (err) {
@@ -1066,6 +1091,15 @@ export class Client extends ClientAbstract {
1066
1091
  }
1067
1092
  }
1068
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
+ }
1069
1103
  }, _Client_checkGap = async function _Client_checkGap(pts, ptsCount) {
1070
1104
  const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
1071
1105
  if (localState.pts + ptsCount < pts) {
@@ -1079,9 +1113,77 @@ export class Client extends ClientAbstract {
1079
1113
  if (localPts + ptsCount < pts) {
1080
1114
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverChannelUpdateGap).call(this, channelId, "processUpdates");
1081
1115
  }
1082
- }, _Client_processUpdates = async function _Client_processUpdates(updates_, checkGap) {
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) {
1083
1185
  __classPrivateFieldSet(this, _Client_lastUpdates, new Date(), "f");
1084
- /// First, individual updates (Update[1]) and updateShort* are extracted from Updates.[2]
1186
+ /// First, individual updates (Update[1]) are extracted from Updates.[2]
1085
1187
  ///
1086
1188
  /// If an updatesTooLong[3] was received, an update gap recovery is initiated and no further action will be taken.
1087
1189
  ///
@@ -1102,14 +1204,14 @@ export class Client extends ClientAbstract {
1102
1204
  const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
1103
1205
  const localSeq = localState.seq;
1104
1206
  if (localSeq + 1 == seqStart) {
1105
- // The updates can be applied.
1207
+ // The update sequence can be applied.
1106
1208
  localState.seq = seq;
1107
1209
  localState.date = updates_.date;
1108
1210
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdateStateDate).call(this, updates_.date);
1109
1211
  await this.storage.setState(localState);
1110
1212
  }
1111
1213
  else if (localSeq + 1 > seqStart) {
1112
- // The updates were already applied, and must be ignored.
1214
+ // The update sequence was already applied, and must be ignored.
1113
1215
  d("localSeq + 1 > seqStart");
1114
1216
  return;
1115
1217
  }
@@ -1123,10 +1225,77 @@ export class Client extends ClientAbstract {
1123
1225
  else if (updates_ instanceof types.UpdateShort) {
1124
1226
  updates = [updates_.update];
1125
1227
  }
1126
- else if (updates_ instanceof types.UpdateShortMessage ||
1127
- updates_ instanceof types.UpdateShortChatMessage ||
1128
- updates_ instanceof types.UpdateShortSentMessage) {
1129
- updates = [updates_];
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
+ ];
1130
1299
  }
1131
1300
  else if (updates_ instanceof types.UpdatesTooLong) {
1132
1301
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverUpdateGap).call(this, "updatesTooLong");
@@ -1138,86 +1307,20 @@ export class Client extends ClientAbstract {
1138
1307
  else {
1139
1308
  UNREACHABLE();
1140
1309
  }
1141
- /// Then, we go through each Update and updateShort*, and see if they are order-sensitive.
1142
- /// If they were, we check the local state to see if it is OK to process them right away.
1143
- ///
1144
- /// If we there was a gap, a recovery process will be initiated and the processing will be postponed.
1145
- let localState = null;
1146
- let originalPts = null;
1147
- const channelPtsMap = new Map();
1148
- for (const update of updates) {
1149
- if (isPtsUpdate(update)) {
1150
- if (update.pts == 0) {
1151
- continue;
1152
- }
1153
- if (checkGap) {
1154
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_checkGap).call(this, update.pts, update.pts_count);
1155
- }
1156
- localState ??= await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
1157
- originalPts ??= localState.pts;
1158
- if (localState.pts + update.pts_count > update.pts) {
1159
- updates = updates.filter((v) => v != update);
1160
- }
1161
- else {
1162
- localState.pts = update.pts;
1163
- }
1164
- }
1165
- else if (isChannelPtsUpdate(update)) {
1166
- if (update.pts == 0) {
1167
- continue;
1168
- }
1169
- const ptsCount = update.pts_count;
1170
- const channelId = update instanceof types.UpdateNewChannelMessage || update instanceof types.UpdateEditChannelMessage ? update.message.peer_id[as](types.PeerChannel).channel_id : update.channel_id;
1171
- if (checkGap) {
1172
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_checkChannelGap).call(this, channelId, update.pts, ptsCount);
1173
- }
1174
- let currentPts = channelPtsMap.get(channelId);
1175
- if (currentPts === undefined) {
1176
- currentPts = await this.storage.getChannelPts(channelId);
1177
- }
1178
- currentPts ??= update.pts - ptsCount;
1179
- if (currentPts + ptsCount > update.pts) {
1180
- updates = updates.filter((v) => v != update);
1181
- }
1182
- else {
1183
- channelPtsMap.set(channelId, update.pts);
1184
- }
1185
- }
1186
- }
1187
1310
  /// We process the updates when we are sure there is no gap.
1188
1311
  if (updates_ instanceof types.Updates || updates_ instanceof types.UpdatesCombined) {
1189
1312
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, updates_.chats);
1190
1313
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, updates_.users);
1191
1314
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdateStateDate).call(this, updates_.date);
1192
1315
  }
1193
- else if (updates_ instanceof types.UpdateShort) {
1316
+ else if (updates_ instanceof types.UpdateShort ||
1317
+ updates_ instanceof types.UpdateShortMessage ||
1318
+ updates_ instanceof types.UpdateShortChatMessage ||
1319
+ updates_ instanceof types.UpdateShortSentMessage) {
1194
1320
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdateStateDate).call(this, updates_.date);
1195
1321
  }
1196
- const updatesToHandle = new Array();
1197
1322
  for (const update of updates) {
1198
- if (update instanceof types.UpdateShortMessage ||
1199
- update instanceof types.UpdateShortChatMessage ||
1200
- update instanceof types.UpdateShortSentMessage) {
1201
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdateStateDate).call(this, update.date);
1202
- }
1203
- else if (update instanceof types.UpdateChannelTooLong) {
1204
- if (update.pts != undefined) {
1205
- await this.storage.setChannelPts(update.channel_id, update.pts);
1206
- }
1207
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverChannelUpdateGap).call(this, update.channel_id, "updateChannelTooLong");
1208
- }
1209
- else if (update instanceof types.UpdateUserName) {
1210
- await this.storage.updateUsernames("user", update.user_id, update.usernames.map((v) => v.username));
1211
- const peer = new types.PeerUser(update);
1212
- const entity = await this[getEntity](peer);
1213
- if (entity != null) {
1214
- entity.usernames = update.usernames;
1215
- entity.first_name = update.first_name;
1216
- entity.last_name = update.last_name;
1217
- await this.storage.setEntity(entity);
1218
- }
1219
- }
1220
- else if (update instanceof types.UpdatePtsChanged) {
1323
+ if (update instanceof types.UpdatePtsChanged) {
1221
1324
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchState).call(this, "updatePtsChanged");
1222
1325
  if (__classPrivateFieldGet(this, _Client_updateState, "f")) {
1223
1326
  await this.storage.setState(__classPrivateFieldGet(this, _Client_updateState, "f"));
@@ -1226,31 +1329,16 @@ export class Client extends ClientAbstract {
1226
1329
  UNREACHABLE();
1227
1330
  }
1228
1331
  }
1229
- if (isPtsUpdate(update)) {
1230
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdatePts).call(this, update.pts);
1332
+ else if (isPtsUpdate(update)) {
1333
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_processPtsUpdate).call(this, update, checkGap);
1231
1334
  }
1232
1335
  else if (isChannelPtsUpdate(update)) {
1233
- let channelId = null;
1234
- if ("channel_id" in update) {
1235
- channelId = update.channel_id;
1236
- }
1237
- else if ("peer_id" in update.message && update.message.peer_id !== undefined && "channel_id" in update.message.peer_id) {
1238
- channelId = update.message.peer_id.channel_id;
1239
- }
1240
- if (channelId != null) {
1241
- await this.storage.setChannelPts(channelId, update.pts);
1242
- }
1336
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChannelPtsUpdate).call(this, update, checkGap);
1243
1337
  }
1244
- /// If there were any Update, they will be passed to the update handling queue.
1245
- if (update instanceof types._Update || update instanceof types.UpdateShortMessage || update instanceof types.UpdateShortChatMessage || update instanceof types.UpdateShortSentMessage) {
1246
- updatesToHandle.push(update);
1338
+ else {
1339
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_queueUpdate).call(this, update, 0n, false);
1247
1340
  }
1248
1341
  }
1249
- __classPrivateFieldGet(this, _Client_handleUpdateQueue, "f").add(async () => {
1250
- for (const update of updatesToHandle) {
1251
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleUpdate).call(this, update);
1252
- }
1253
- });
1254
1342
  }, _Client_setUpdateStateDate = async function _Client_setUpdateStateDate(date) {
1255
1343
  const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
1256
1344
  localState.date = date;
@@ -1526,7 +1614,7 @@ export class Client extends ClientAbstract {
1526
1614
  reply_markup: replyMarkup,
1527
1615
  });
1528
1616
  const message_ = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
1529
- return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message_, "text");
1617
+ return assertMessageType(message_, "text");
1530
1618
  }
1531
1619
  /**
1532
1620
  * Edit a message's text.
@@ -1548,7 +1636,7 @@ export class Client extends ClientAbstract {
1548
1636
  reply_markup: await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params),
1549
1637
  });
1550
1638
  const message_ = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
1551
- return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message_, "text");
1639
+ return assertMessageType(message_, "text");
1552
1640
  }
1553
1641
  /**
1554
1642
  * Retrieve multiple messages.
@@ -1579,7 +1667,7 @@ export class Client extends ClientAbstract {
1579
1667
  }
1580
1668
  }
1581
1669
  }
1582
- else if (updates instanceof types.UpdateShortSentMessage || updates instanceof types.UpdateShortSentMessage) {
1670
+ else if (updates instanceof types.UpdateShortSentMessage) {
1583
1671
  const message = await this.getMessage(chatId, updates.id);
1584
1672
  if (message != null) {
1585
1673
  messages.push(message);
@@ -1936,7 +2024,7 @@ export class Client extends ClientAbstract {
1936
2024
  message: "",
1937
2025
  });
1938
2026
  const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
1939
- return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message, "poll");
2027
+ return assertMessageType(message, "poll");
1940
2028
  }
1941
2029
  /**
1942
2030
  * Send a chat action.
@@ -2144,9 +2232,19 @@ export class Client extends ClientAbstract {
2144
2232
  }
2145
2233
  on(filter, ...middleawre) {
2146
2234
  const type = typeof filter === "string" ? filter : filter[0];
2147
- const keys = Array.isArray(filter) ? filter.slice(1) : [];
2235
+ let keys = Array.isArray(filter) ? filter.slice(1) : [];
2236
+ let messageType = null;
2237
+ if (type == "message") {
2238
+ messageType = keys[0];
2239
+ keys = keys.slice(1);
2240
+ }
2148
2241
  return this.filter((ctx) => {
2149
2242
  if (type in ctx) {
2243
+ if (messageType != null) {
2244
+ // deno-lint-ignore ban-ts-comment
2245
+ // @ts-ignore
2246
+ assertMessageType(ctx[type], messageType);
2247
+ }
2150
2248
  if (keys.length > 0) {
2151
2249
  for (const key of keys) {
2152
2250
  // deno-lint-ignore ban-ts-comment
@@ -2211,27 +2309,27 @@ export class Client extends ClientAbstract {
2211
2309
  *
2212
2310
  * @method
2213
2311
  */
2214
- async setMyDescription({ description, languageCode }) {
2312
+ async setMyDescription(params) {
2215
2313
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "setMyDescription");
2216
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { description, lang_code: languageCode ?? "" });
2314
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { description: params?.description, lang_code: params?.languageCode ?? "" });
2217
2315
  }
2218
2316
  /**
2219
2317
  * Set the bot's name in the given language. Bot-only.
2220
2318
  *
2221
2319
  * @method
2222
2320
  */
2223
- async setMyName({ name, languageCode }) {
2321
+ async setMyName(params) {
2224
2322
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "setMyName");
2225
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { name, lang_code: languageCode ?? "" });
2323
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { name: params?.name, lang_code: params?.languageCode ?? "" });
2226
2324
  }
2227
2325
  /**
2228
2326
  * Set the bot's short description in the given language. Bot-only.
2229
2327
  *
2230
2328
  * @method
2231
2329
  */
2232
- async setMyShortDescription({ shortDescription: about, languageCode }) {
2330
+ async setMyShortDescription(params) {
2233
2331
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "setMyShortDescription");
2234
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { about, lang_code: languageCode ?? "" });
2332
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { about: params?.shortDescription, lang_code: params?.languageCode ?? "" });
2235
2333
  }
2236
2334
  /**
2237
2335
  * Get the bot's description in the given language. Bot-only.
@@ -2316,7 +2414,7 @@ export class Client extends ClientAbstract {
2316
2414
  }
2317
2415
  }
2318
2416
  const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendMedia).call(this, chatId, media, params);
2319
- return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message, "photo");
2417
+ return assertMessageType(message, "photo");
2320
2418
  }
2321
2419
  /**
2322
2420
  * Send a document.
@@ -2327,7 +2425,7 @@ export class Client extends ClientAbstract {
2327
2425
  */
2328
2426
  async sendDocument(chatId, document, params) {
2329
2427
  const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendDocumentInner).call(this, chatId, document, params, FileType.Document, []);
2330
- return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message, "document");
2428
+ return assertMessageType(message, "document");
2331
2429
  }
2332
2430
  /**
2333
2431
  * Send a video.
@@ -2345,7 +2443,7 @@ export class Client extends ClientAbstract {
2345
2443
  duration: params?.duration ?? 0,
2346
2444
  }),
2347
2445
  ]);
2348
- return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message, "video");
2446
+ return assertMessageType(message, "video");
2349
2447
  }
2350
2448
  /**
2351
2449
  * Send an animation.
@@ -2364,7 +2462,7 @@ export class Client extends ClientAbstract {
2364
2462
  duration: params?.duration ?? 0,
2365
2463
  }),
2366
2464
  ]);
2367
- return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message, "animation");
2465
+ return assertMessageType(message, "animation");
2368
2466
  }
2369
2467
  /**
2370
2468
  * Send a voice message.
@@ -2380,7 +2478,7 @@ export class Client extends ClientAbstract {
2380
2478
  duration: params?.duration ?? 0,
2381
2479
  }),
2382
2480
  ]);
2383
- return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message, "voice");
2481
+ return assertMessageType(message, "voice");
2384
2482
  }
2385
2483
  /**
2386
2484
  * Send an audio file.
@@ -2397,7 +2495,7 @@ export class Client extends ClientAbstract {
2397
2495
  title: params?.title,
2398
2496
  }),
2399
2497
  ]);
2400
- return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message, "audio");
2498
+ return assertMessageType(message, "audio");
2401
2499
  }
2402
2500
  /**
2403
2501
  * Send a video note.
@@ -2415,7 +2513,7 @@ export class Client extends ClientAbstract {
2415
2513
  duration: params?.duration ?? 0,
2416
2514
  }),
2417
2515
  ], false);
2418
- return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message, "videoNote");
2516
+ return assertMessageType(message, "videoNote");
2419
2517
  }
2420
2518
  /**
2421
2519
  * Send a location.
@@ -2461,7 +2559,7 @@ export class Client extends ClientAbstract {
2461
2559
  message: "",
2462
2560
  });
2463
2561
  const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
2464
- return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message, "location");
2562
+ return assertMessageType(message, "location");
2465
2563
  }
2466
2564
  /**
2467
2565
  * Send a contact.
@@ -2495,7 +2593,7 @@ export class Client extends ClientAbstract {
2495
2593
  message: "",
2496
2594
  });
2497
2595
  const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
2498
- return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message, "contact");
2596
+ return assertMessageType(message, "contact");
2499
2597
  }
2500
2598
  /**
2501
2599
  * Send a dice.
@@ -2524,7 +2622,7 @@ export class Client extends ClientAbstract {
2524
2622
  message: "",
2525
2623
  });
2526
2624
  const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
2527
- return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message, "dice");
2625
+ return assertMessageType(message, "dice");
2528
2626
  }
2529
2627
  /**
2530
2628
  * Send a venue.
@@ -2565,7 +2663,7 @@ export class Client extends ClientAbstract {
2565
2663
  message: "",
2566
2664
  });
2567
2665
  const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
2568
- return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message, "dice");
2666
+ return assertMessageType(message, "venue");
2569
2667
  }
2570
2668
  /**
2571
2669
  * Get network statistics. This might not always be available.
@@ -2803,21 +2901,48 @@ export class Client extends ClientAbstract {
2803
2901
  });
2804
2902
  }
2805
2903
  /**
2806
- * Add a reaction to a message.
2904
+ * Change reactions made to a message.
2905
+ *
2906
+ * @param chatId The identifier of the chat which the message belongs to.
2907
+ * @param messageId The identifier of the message to add the reaction to.
2908
+ * @param reactions The new reactions.
2909
+ */
2910
+ async setReactions(chatId, messageId, reactions, params) {
2911
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendReaction).call(this, chatId, messageId, reactions, params);
2912
+ }
2913
+ /**
2914
+ * Make a reaction to a message.
2807
2915
  *
2808
2916
  * @param chatId The identifier of the chat which the message belongs to.
2809
2917
  * @param messageId The identifier of the message to add the reaction to.
2810
2918
  * @param reaction The reaction to add.
2811
2919
  */
2812
2920
  async addReaction(chatId, messageId, reaction, params) {
2813
- // TODO: check storage and skip if already there
2814
- await this.api.messages.sendReaction({
2815
- peer: await this.getInputPeer(chatId),
2816
- msg_id: messageId,
2817
- reaction: [reaction.type == "emoji" ? new types.ReactionEmoji({ emoticon: reaction.emoji }) : new types.ReactionCustomEmoji({ document_id: BigInt(reaction.id) })],
2818
- big: params?.big ? true : undefined,
2819
- add_to_recent: params?.addToRecents ? true : undefined,
2820
- });
2921
+ const chosenReactions = await this.getMessage(chatId, messageId).then((v) => v?.reactions ?? []).then((v) => v.filter((v) => v.chosen));
2922
+ for (const r of chosenReactions) {
2923
+ if (reactionEqual(r.reaction, reaction)) {
2924
+ return;
2925
+ }
2926
+ }
2927
+ const reactions = [reaction, ...chosenReactions.map((v) => v.reaction)];
2928
+ await this.setReactions(chatId, messageId, reactions, params);
2929
+ }
2930
+ /**
2931
+ * Undo a reaction made to a message.
2932
+ *
2933
+ * @param chatId The identifier of the chat which the message belongs to.
2934
+ * @param messageId The identifier of the message which the reaction was made to.
2935
+ * @param reaction The reaction to remove.
2936
+ */
2937
+ async removeReaction(chatId, messageId, reaction) {
2938
+ const chosenReactions = await this.getMessage(chatId, messageId).then((v) => v?.reactions ?? []).then((v) => v.filter((v) => v.chosen));
2939
+ for (const r of chosenReactions) {
2940
+ if (reactionEqual(r.reaction, reaction)) {
2941
+ const reactions = chosenReactions.filter((v) => v != r).map((v) => v.reaction);
2942
+ await this.setReactions(chatId, messageId, reactions);
2943
+ break;
2944
+ }
2945
+ }
2821
2946
  }
2822
2947
  }
2823
2948
  _a = Client, _Client_getMe = async function _Client_getMe() {
@@ -2829,65 +2954,92 @@ _a = Client, _Client_getMe = async function _Client_getMe() {
2829
2954
  __classPrivateFieldSet(this, _Client_lastGetMe, user, "f");
2830
2955
  return user;
2831
2956
  }
2832
- }, _Client_handleUpdate =
2833
- // TODO: log errors
2834
- async function _Client_handleUpdate(update) {
2835
- if (update instanceof types.UpdateShortMessage) {
2836
- update = new types.UpdateNewMessage({
2837
- message: new types.Message({
2838
- out: update.out,
2839
- mentioned: update.mentioned,
2840
- media_unread: update.media_unread,
2841
- silent: update.silent,
2842
- id: update.id,
2843
- from_id: update.out ? new types.PeerUser({ user_id: await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getSelfId).call(this).then(BigInt) }) : new types.PeerUser({ user_id: update.user_id }),
2844
- peer_id: new types.PeerUser({ user_id: update.user_id }),
2845
- message: update.message,
2846
- date: update.date,
2847
- fwd_from: update.fwd_from,
2848
- via_bot_id: update.via_bot_id,
2849
- reply_to: update.reply_to,
2850
- entities: update.entities,
2851
- ttl_period: update.ttl_period,
2852
- }),
2853
- pts: update.pts,
2854
- pts_count: update.pts_count,
2855
- });
2957
+ }, _Client_handleStoredUpdates = async function _Client_handleStoredUpdates(boxId) {
2958
+ if (__classPrivateFieldGet(this, _Client_handleUpdatesSet, "f").has(boxId)) {
2959
+ return;
2856
2960
  }
2857
- else if (update instanceof types.UpdateShortChatMessage) {
2858
- update = new types.UpdateNewMessage({
2859
- message: new types.Message({
2860
- out: update.out,
2861
- mentioned: update.mentioned,
2862
- media_unread: update.media_unread,
2863
- silent: update.silent,
2864
- id: update.id,
2865
- from_id: new types.PeerUser({ user_id: update.from_id }),
2866
- peer_id: new types.PeerChat({ chat_id: update.chat_id }),
2867
- fwd_from: update.fwd_from,
2868
- via_bot_id: update.via_bot_id,
2869
- reply_to: update.reply_to,
2870
- date: update.date,
2871
- message: update.message,
2872
- entities: update.entities,
2873
- ttl_period: update.ttl_period,
2874
- }),
2875
- pts: update.pts,
2876
- pts_count: update.pts_count,
2877
- });
2961
+ __classPrivateFieldGet(this, _Client_handleUpdatesSet, "f").add(boxId);
2962
+ do {
2963
+ const maybeUpdate = await this.storage.getFirstUpdate(boxId);
2964
+ if (maybeUpdate == null) {
2965
+ break;
2966
+ }
2967
+ const [key, update] = maybeUpdate;
2968
+ for (let i = 0; i < 100; ++i) {
2969
+ try {
2970
+ const handle = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleUpdate).call(this, update);
2971
+ handle: for (let i = 0; i < 2; ++i) {
2972
+ try {
2973
+ await handle();
2974
+ break handle;
2975
+ }
2976
+ catch {
2977
+ continue handle;
2978
+ }
2979
+ }
2980
+ break;
2981
+ }
2982
+ catch (err) {
2983
+ d("#handleUpdate error: %o", err);
2984
+ }
2985
+ }
2986
+ await this.storage.set(key, null);
2987
+ } while (true);
2988
+ __classPrivateFieldGet(this, _Client_handleUpdatesSet, "f").delete(boxId);
2989
+ }, _Client_handleUpdate = async function _Client_handleUpdate(update) {
2990
+ const promises = new Array();
2991
+ if (update instanceof types.UpdateUserName) {
2992
+ await this.storage.updateUsernames("user", update.user_id, update.usernames.map((v) => v.username));
2993
+ const peer = new types.PeerUser(update);
2994
+ const entity = await this[getEntity](peer);
2995
+ if (entity != null) {
2996
+ entity.usernames = update.usernames;
2997
+ entity.first_name = update.first_name;
2998
+ entity.last_name = update.last_name;
2999
+ await this.storage.setEntity(entity);
3000
+ }
2878
3001
  }
2879
3002
  if (update instanceof types.UpdateNewMessage || update instanceof types.UpdateNewChannelMessage || update instanceof types.UpdateEditMessage || update instanceof types.UpdateEditChannelMessage) {
2880
3003
  if (update.message instanceof types.Message || update.message instanceof types.MessageService) {
2881
3004
  const chatId = peerToChatId(update.message.peer_id);
2882
3005
  await this.storage.setMessage(chatId, update.message.id, update.message);
2883
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId);
3006
+ promises.push((await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId))());
3007
+ }
3008
+ }
3009
+ if (update instanceof types.UpdateMessageReactions) {
3010
+ const chatId = peerToChatId(update.peer);
3011
+ const message = await this.storage.getMessage(chatId, update.msg_id);
3012
+ if (message instanceof types.Message) {
3013
+ message.reactions = update.reactions;
3014
+ await this.storage.setMessage(chatId, update.msg_id, message);
3015
+ const views = message.views ?? 0;
3016
+ const forwards = message.forwards ?? 0;
3017
+ const recentReactions = update.reactions.recent_reactions ?? [];
3018
+ const reactions = update.reactions.results.map((v) => constructMessageReaction(v, recentReactions));
3019
+ promises.push((async () => __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { messageInteractions: { chatId, messageId: update.msg_id, reactions, views, forwards } }), resolve))());
3020
+ }
3021
+ }
3022
+ else if (update instanceof types.UpdateChannelMessageViews || update instanceof types.UpdateChannelMessageForwards) {
3023
+ const chatId = peerToChatId(new types.PeerChannel(update));
3024
+ const message = await this.storage.getMessage(chatId, update.id);
3025
+ if (message instanceof types.Message) {
3026
+ if ("views" in update) {
3027
+ message.views = update.views;
3028
+ }
3029
+ if ("forwards" in update) {
3030
+ message.forwards = update.forwards;
3031
+ }
3032
+ const views = message.views ?? 0;
3033
+ const forwards = message.forwards ?? 0;
3034
+ const recentReactions = message.reactions?.recent_reactions ?? [];
3035
+ const reactions = message.reactions?.results.map((v) => constructMessageReaction(v, recentReactions)) ?? [];
3036
+ promises.push((async () => __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { messageInteractions: { chatId, messageId: update.id, reactions, views, forwards } }), resolve))());
2884
3037
  }
2885
3038
  }
2886
3039
  if (update instanceof types.UpdateNewMessage ||
2887
3040
  update instanceof types.UpdateNewChannelMessage ||
2888
3041
  update instanceof types.UpdateEditMessage ||
2889
3042
  update instanceof types.UpdateEditChannelMessage) {
2890
- const key = update instanceof types.UpdateNewMessage || update instanceof types.UpdateNewChannelMessage ? "message" : "editedMessage";
2891
3043
  if (!(update.message instanceof types.MessageEmpty)) {
2892
3044
  const isOutgoing = update.message.out;
2893
3045
  let shouldIgnore = isOutgoing ? (await this.storage.getAccountType()) == "user" ? false : true : false;
@@ -2896,7 +3048,16 @@ async function _Client_handleUpdate(update) {
2896
3048
  }
2897
3049
  if (!shouldIgnore) {
2898
3050
  const message = await constructMessage(update.message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this));
2899
- await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { [key]: message }), resolve);
3051
+ promises.push((async () => {
3052
+ let context;
3053
+ if (update instanceof types.UpdateNewMessage || update instanceof types.UpdateNewChannelMessage) {
3054
+ context = await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { message });
3055
+ }
3056
+ else {
3057
+ context = await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { editedMessage: message });
3058
+ }
3059
+ await __classPrivateFieldGet(this, _Client_handle, "f").call(this, context, resolve);
3060
+ })());
2900
3061
  }
2901
3062
  }
2902
3063
  }
@@ -2905,16 +3066,21 @@ async function _Client_handleUpdate(update) {
2905
3066
  for (const messageId of update.messages) {
2906
3067
  const chatId = await this.storage.getMessageChat(messageId);
2907
3068
  if (chatId) {
2908
- const message = await this.storage.getMessage(chatId, messageId);
2909
- if (message != null && !(message instanceof types.MessageEmpty)) {
2910
- deletedMessages.push(await constructMessage(message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this)));
2911
- }
2912
- await this.storage.setMessage(chatId, messageId, null);
2913
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId);
3069
+ deletedMessages.push({ chatId, messageId });
2914
3070
  }
2915
3071
  }
2916
3072
  if (deletedMessages.length > 0) {
2917
- await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { deletedMessages: deletedMessages }), resolve);
3073
+ promises.push((async () => {
3074
+ try {
3075
+ await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { deletedMessages }), resolve);
3076
+ }
3077
+ finally {
3078
+ for (const { chatId, messageId } of deletedMessages) {
3079
+ await this.storage.setMessage(chatId, messageId, null);
3080
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId);
3081
+ }
3082
+ }
3083
+ })());
2918
3084
  }
2919
3085
  }
2920
3086
  else if (update instanceof types.UpdateDeleteChannelMessages) {
@@ -2922,24 +3088,43 @@ async function _Client_handleUpdate(update) {
2922
3088
  const deletedMessages = new Array();
2923
3089
  for (const messageId of update.messages) {
2924
3090
  const message = await this.storage.getMessage(chatId, messageId);
2925
- if (message != null && !(message instanceof types.MessageEmpty)) {
2926
- deletedMessages.push(await constructMessage(message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this)));
3091
+ if (message != null) {
3092
+ deletedMessages.push({ chatId, messageId });
2927
3093
  }
2928
- await this.storage.setMessage(chatId, messageId, null);
2929
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId);
2930
3094
  }
2931
3095
  if (deletedMessages.length > 0) {
2932
- await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { deletedMessages: deletedMessages }), resolve);
3096
+ promises.push((async () => {
3097
+ try {
3098
+ await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { deletedMessages }), resolve);
3099
+ }
3100
+ finally {
3101
+ for (const { chatId, messageId } of deletedMessages) {
3102
+ await this.storage.setMessage(chatId, messageId, null);
3103
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId);
3104
+ }
3105
+ }
3106
+ })());
2933
3107
  }
2934
3108
  }
2935
3109
  if (update instanceof types.UpdateBotCallbackQuery || update instanceof types.UpdateInlineBotCallbackQuery) {
2936
- await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { callbackQuery: await constructCallbackQuery(update, this[getEntity].bind(this), this[getMessageWithReply].bind(this)) }), resolve);
3110
+ promises.push((async () => __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { callbackQuery: await constructCallbackQuery(update, this[getEntity].bind(this), this[getMessageWithReply].bind(this)) }), resolve))());
2937
3111
  }
2938
3112
  else if (update instanceof types.UpdateBotInlineQuery) {
2939
- await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { inlineQuery: await constructInlineQuery(update, this[getEntity].bind(this)) }), resolve);
3113
+ promises.push((async () => __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { inlineQuery: await constructInlineQuery(update, this[getEntity].bind(this)) }), resolve))());
2940
3114
  }
2941
3115
  else if (update instanceof types.UpdateBotInlineSend) {
2942
- await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { chosenInlineResult: await constructChosenInlineResult(update, this[getEntity].bind(this)) }), resolve);
3116
+ promises.push((async () => __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { chosenInlineResult: await constructChosenInlineResult(update, this[getEntity].bind(this)) }), resolve))());
3117
+ }
3118
+ else if (update instanceof types.UpdateBotMessageReactions) {
3119
+ const date = new Date(update.date * 1000);
3120
+ const reactions = update.reactions.map((v) => constructReactionCount(v));
3121
+ const entity = await this[getEntity](update.peer);
3122
+ if (entity) {
3123
+ const chat = constructChatP(entity);
3124
+ const messageId = update.msg_id;
3125
+ const messageReactionCount = { chat, messageId, date, reactions };
3126
+ promises.push((async () => __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { messageReactionCount }), resolve))());
3127
+ }
2943
3128
  }
2944
3129
  if (update instanceof types.UpdatePinnedDialogs) {
2945
3130
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatePinnedChats).call(this, update);
@@ -2977,16 +3162,12 @@ async function _Client_handleUpdate(update) {
2977
3162
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updateOrAddChat).call(this, peerToChatId(peer));
2978
3163
  }
2979
3164
  }
3165
+ return () => Promise.all(promises);
2980
3166
  }, _Client_constructReplyMarkup = async function _Client_constructReplyMarkup(params) {
2981
3167
  if (params?.replyMarkup) {
2982
3168
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "replyMarkup");
2983
3169
  return replyMarkupToTlObject(params.replyMarkup, __classPrivateFieldGet(this, _Client_usernameResolver, "f").bind(this));
2984
3170
  }
2985
- }, _Client_assertMsgHas = function _Client_assertMsgHas(message, key) {
2986
- if (!(key in message) || message[key] === undefined) {
2987
- UNREACHABLE();
2988
- }
2989
- return message;
2990
3171
  }, _Client_setMyInfo =
2991
3172
  //#endregion
2992
3173
  async function _Client_setMyInfo(info) {
@@ -3088,7 +3269,7 @@ async function _Client_setMyInfo(info) {
3088
3269
  }
3089
3270
  const [chat] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
3090
3271
  const update = chat === undefined ? { deletedChat: { chatId } } : added ? { newChat: chat } : { editedChat: chat };
3091
- __classPrivateFieldGet(this, _Client_handleUpdateQueue, "f").add(async () => {
3272
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_getHandleUpdateQueue).call(this, __classPrivateFieldGet(this, _Client_mainBoxId, "f")).add(async () => {
3092
3273
  await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, update), resolve);
3093
3274
  });
3094
3275
  }, _Client_reassignChatLastMessage = async function _Client_reassignChatLastMessage(chatId, add = false, sendUpdate = true) {
@@ -3096,11 +3277,11 @@ async function _Client_setMyInfo(info) {
3096
3277
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertUser).call(this, "");
3097
3278
  }
3098
3279
  catch {
3099
- return;
3280
+ return () => Promise.resolve();
3100
3281
  }
3101
3282
  const [chat, listId] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
3102
3283
  if (!chat && !add) {
3103
- return;
3284
+ return () => Promise.resolve();
3104
3285
  }
3105
3286
  const message_ = await this.storage.getLastMessage(chatId);
3106
3287
  if (message_ != null) {
@@ -3120,9 +3301,9 @@ async function _Client_setMyInfo(info) {
3120
3301
  await this.storage.setChat(listId, chatId, chat.pinned, chat.lastMessage?.id ?? 0, chat.lastMessage?.date ?? new Date(0));
3121
3302
  }
3122
3303
  if (sendUpdate) {
3123
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
3304
+ return () => __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
3124
3305
  }
3125
- return;
3306
+ return () => Promise.resolve();
3126
3307
  }
3127
3308
  const message = await this.getHistory(chatId, { limit: 1 }).then((v) => v[0]);
3128
3309
  if (message !== undefined) {
@@ -3140,17 +3321,18 @@ async function _Client_setMyInfo(info) {
3140
3321
  __classPrivateFieldGet(this, _Client_chats, "f").set(chatId, chat);
3141
3322
  }
3142
3323
  if (sendUpdate) {
3143
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
3324
+ return () => __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
3144
3325
  }
3145
- return;
3326
+ return () => Promise.resolve();
3146
3327
  }
3147
3328
  if (chat) {
3148
3329
  chat.order = getChatOrder(undefined, chat.pinned);
3149
3330
  chat.lastMessage = undefined;
3150
3331
  if (sendUpdate) {
3151
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
3332
+ return () => __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
3152
3333
  }
3153
3334
  }
3335
+ return () => Promise.resolve();
3154
3336
  }, _Client_tryGetChatId = function _Client_tryGetChatId(username) {
3155
3337
  username = username.toLowerCase();
3156
3338
  for (const chat of __classPrivateFieldGet(this, _Client_chats, "f").values()) {
@@ -3302,6 +3484,7 @@ async function _Client_setMyInfo(info) {
3302
3484
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chat.id, false);
3303
3485
  }
3304
3486
  }
3487
+ await this.storage.setPinnedChats(listId, await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getPinnedChats).call(this, listId));
3305
3488
  }, _Client_fetchChats = async function _Client_fetchChats(listId, limit, after) {
3306
3489
  const dialogs = await this.api.messages.getDialogs({
3307
3490
  limit,
@@ -3324,4 +3507,12 @@ async function _Client_setMyInfo(info) {
3324
3507
  chats.set(chat.id, chat);
3325
3508
  await this.storage.setChat(listId, chat.id, chat.pinned, chat.lastMessage?.id ?? 0, chat.lastMessage?.date ?? new Date(0));
3326
3509
  }
3510
+ }, _Client_sendReaction = async function _Client_sendReaction(chatId, messageId, reactions, params) {
3511
+ await this.api.messages.sendReaction({
3512
+ peer: await this.getInputPeer(chatId),
3513
+ msg_id: messageId,
3514
+ reaction: reactions.map((v) => reactionToTlObject(v)),
3515
+ big: params?.big ? true : undefined,
3516
+ add_to_recent: params?.addToRecents ? true : undefined,
3517
+ });
3327
3518
  };