@mtkruto/node 0.1.133 → 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 (162) 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 +16 -7
  4. package/esm/3_types.js +16 -7
  5. package/esm/4_constants.d.ts +1 -1
  6. package/esm/4_constants.js +1 -1
  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 +28 -0
  12. package/esm/client/0_utilities.js +10 -0
  13. package/esm/client/1_composer.d.ts +30 -0
  14. package/esm/client/{4_composer.js → 1_composer.js} +3 -2
  15. package/esm/client/2_client_plain.d.ts +1 -1
  16. package/esm/client/2_client_plain.js +1 -1
  17. package/{script/client/3_types.d.ts → esm/client/3_params.d.ts} +68 -177
  18. package/esm/client/3_params.js +1 -0
  19. package/esm/client/{5_client.d.ts → 4_client.d.ts} +57 -25
  20. package/esm/client/{5_client.js → 4_client.js} +347 -160
  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/3_utilities.d.ts +1 -0
  34. package/esm/tl/3_utilities.js +14 -0
  35. package/esm/tl/6_message.js +1 -1
  36. package/esm/types/0_authorization_state.d.ts +5 -0
  37. package/esm/types/0_authorization_state.js +1 -0
  38. package/esm/types/0_connection_state.d.ts +17 -0
  39. package/esm/types/0_connection_state.js +1 -0
  40. package/esm/types/0_login_url.d.ts +0 -4
  41. package/esm/types/0_mask_position.d.ts +0 -4
  42. package/esm/types/0_message_entity.d.ts +0 -2
  43. package/esm/types/0_message_identifier.d.ts +4 -0
  44. package/esm/types/0_message_identifier.js +1 -0
  45. package/esm/types/0_network_statistics_entry.d.ts +4 -0
  46. package/esm/types/0_network_statistics_entry.js +1 -0
  47. package/esm/types/0_reaction.d.ts +1 -0
  48. package/esm/types/0_reaction.js +13 -0
  49. package/esm/types/1__getters.d.ts +3 -0
  50. package/esm/types/1_chat_p.d.ts +1 -0
  51. package/esm/types/1_keyboard_button.d.ts +1 -23
  52. package/esm/types/1_network_statistics.d.ts +5 -0
  53. package/esm/types/1_network_statistics.js +1 -0
  54. package/esm/types/1_poll.d.ts +0 -13
  55. package/esm/types/1_reaction_count.d.ts +7 -0
  56. package/esm/types/1_reaction_count.js +6 -0
  57. package/esm/types/2_game.d.ts +0 -7
  58. package/esm/types/2_inline_keyboard_button.d.ts +0 -8
  59. package/esm/types/2_inline_query.d.ts +0 -6
  60. package/esm/types/2_message_interactions.d.ts +8 -0
  61. package/esm/types/2_message_interactions.js +1 -0
  62. package/esm/types/2_message_reaction_count.d.ts +8 -0
  63. package/esm/types/2_message_reaction_count.js +1 -0
  64. package/esm/types/2_reply_keyboard_markup.d.ts +0 -7
  65. package/esm/types/3_inline_keyboard_markup.d.ts +0 -2
  66. package/{script/types/3_message.d.ts → esm/types/4_message.d.ts} +225 -7
  67. package/esm/types/{3_message.js → 4_message.js} +14 -24
  68. package/{script/types/4_callback_query.d.ts → esm/types/5_callback_query.d.ts} +1 -1
  69. package/esm/types/{4_chat.d.ts → 5_chat.d.ts} +3 -3
  70. package/esm/types/{4_chat.js → 5_chat.js} +2 -2
  71. package/esm/types/6_update.d.ts +134 -0
  72. package/esm/types/6_update.js +1 -0
  73. package/package.json +1 -1
  74. package/script/3_errors.d.ts +519 -510
  75. package/script/3_errors.js +533 -520
  76. package/script/3_types.d.ts +16 -7
  77. package/script/3_types.js +16 -7
  78. package/script/4_constants.d.ts +1 -1
  79. package/script/4_constants.js +1 -1
  80. package/script/4_errors.d.ts +7 -12
  81. package/script/4_errors.js +5 -6
  82. package/script/5_client.d.ts +3 -3
  83. package/script/5_client.js +3 -3
  84. package/script/client/0_utilities.d.ts +28 -0
  85. package/script/client/0_utilities.js +12 -1
  86. package/script/client/1_composer.d.ts +30 -0
  87. package/script/client/{4_composer.js → 1_composer.js} +5 -4
  88. package/script/client/2_client_plain.d.ts +1 -1
  89. package/script/client/2_client_plain.js +2 -2
  90. package/{esm/client/3_types.d.ts → script/client/3_params.d.ts} +68 -177
  91. package/script/client/3_params.js +2 -0
  92. package/script/client/{5_client.d.ts → 4_client.d.ts} +57 -25
  93. package/script/client/{5_client.js → 4_client.js} +353 -166
  94. package/script/client/5_composer.d.ts +4 -0
  95. package/script/client/{6_composer.js → 5_composer.js} +2 -2
  96. package/script/storage/0_storage.d.ts +4 -1
  97. package/script/storage/0_storage.js +36 -7
  98. package/script/storage/1_storage_indexed_db.d.ts +6 -2
  99. package/script/storage/1_storage_indexed_db.js +7 -5
  100. package/script/storage/1_storage_local_storage.d.ts +1 -1
  101. package/script/storage/1_storage_local_storage.js +1 -1
  102. package/script/storage/1_storage_memory.d.ts +1 -1
  103. package/script/storage/1_storage_memory.js +1 -1
  104. package/script/storage/1_storage_session_storage.d.ts +1 -1
  105. package/script/storage/1_storage_session_storage.js +1 -1
  106. package/script/tl/3_utilities.d.ts +1 -0
  107. package/script/tl/3_utilities.js +16 -1
  108. package/script/tl/6_message.js +1 -1
  109. package/script/types/0_authorization_state.d.ts +5 -0
  110. package/script/types/0_authorization_state.js +2 -0
  111. package/script/types/0_connection_state.d.ts +17 -0
  112. package/script/types/0_connection_state.js +2 -0
  113. package/script/types/0_login_url.d.ts +0 -4
  114. package/script/types/0_mask_position.d.ts +0 -4
  115. package/script/types/0_message_entity.d.ts +0 -2
  116. package/script/types/0_message_identifier.d.ts +4 -0
  117. package/script/types/0_message_identifier.js +2 -0
  118. package/script/types/0_network_statistics_entry.d.ts +4 -0
  119. package/script/types/0_network_statistics_entry.js +2 -0
  120. package/script/types/0_reaction.d.ts +1 -0
  121. package/script/types/0_reaction.js +15 -1
  122. package/script/types/1__getters.d.ts +3 -0
  123. package/script/types/1_chat_p.d.ts +1 -0
  124. package/script/types/1_keyboard_button.d.ts +1 -23
  125. package/script/types/1_network_statistics.d.ts +5 -0
  126. package/script/types/1_network_statistics.js +2 -0
  127. package/script/types/1_poll.d.ts +0 -13
  128. package/script/types/1_reaction_count.d.ts +7 -0
  129. package/script/types/1_reaction_count.js +10 -0
  130. package/script/types/2_game.d.ts +0 -7
  131. package/script/types/2_inline_keyboard_button.d.ts +0 -8
  132. package/script/types/2_inline_query.d.ts +0 -6
  133. package/script/types/2_message_interactions.d.ts +8 -0
  134. package/script/types/2_message_interactions.js +2 -0
  135. package/script/types/2_message_reaction_count.d.ts +8 -0
  136. package/script/types/2_message_reaction_count.js +2 -0
  137. package/script/types/2_reply_keyboard_markup.d.ts +0 -7
  138. package/script/types/3_inline_keyboard_markup.d.ts +0 -2
  139. package/{esm/types/3_message.d.ts → script/types/4_message.d.ts} +225 -7
  140. package/script/types/{3_message.js → 4_message.js} +15 -25
  141. package/{esm/types/4_callback_query.d.ts → script/types/5_callback_query.d.ts} +1 -1
  142. package/script/types/{4_chat.d.ts → 5_chat.d.ts} +3 -3
  143. package/script/types/{4_chat.js → 5_chat.js} +3 -3
  144. package/script/types/6_update.d.ts +134 -0
  145. package/script/types/6_update.js +2 -0
  146. package/esm/client/3_types.js +0 -11
  147. package/esm/client/4_composer.d.ts +0 -31
  148. package/esm/client/6_composer.d.ts +0 -4
  149. package/esm/client/6_composer.js +0 -3
  150. package/script/client/3_types.js +0 -15
  151. package/script/client/4_composer.d.ts +0 -31
  152. package/script/client/6_composer.d.ts +0 -4
  153. /package/esm/client/{1_client_abstract.d.ts → 0_client_abstract.d.ts} +0 -0
  154. /package/esm/client/{1_client_abstract.js → 0_client_abstract.js} +0 -0
  155. /package/esm/types/{0_audio.d.ts → 1_audio.d.ts} +0 -0
  156. /package/esm/types/{0_audio.js → 1_audio.js} +0 -0
  157. /package/esm/types/{4_callback_query.js → 5_callback_query.js} +0 -0
  158. /package/script/client/{1_client_abstract.d.ts → 0_client_abstract.d.ts} +0 -0
  159. /package/script/client/{1_client_abstract.js → 0_client_abstract.js} +0 -0
  160. /package/script/types/{0_audio.d.ts → 1_audio.d.ts} +0 -0
  161. /package/script/types/{0_audio.js → 1_audio.js} +0 -0
  162. /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_channelUpdateQueues, _Client_processChannelUpdate, _Client_queueChannelUpdate, _Client_handlePtsUpdate, _Client_ptsUpdateQueue, _Client_queuePtsUpdate, _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_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 { assertMessageType, botCommandScopeToTlObject, constructCallbackQuery, constructChat, constructChat2, constructChat3, constructChat4, constructChosenInlineResult, constructDocument, constructInlineQuery, constructMessage, constructMessageReaction, constructUser, FileID, FileType, FileUniqueID, FileUniqueType, getChatOrder, inlineQueryResultToTlObject, messageEntityToTlObject, reactionToTlObject, 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,24 +180,29 @@ 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);
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);
201
206
  const context = {
202
207
  ...update,
203
208
  client: this,
@@ -210,131 +215,141 @@ export class Client extends ClientAbstract {
210
215
  return () => update;
211
216
  },
212
217
  reply: (text, params) => {
213
- const effectiveMessage = mustGetMsg();
214
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
215
- 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 });
216
221
  },
217
222
  replyPoll: (question, options, params) => {
218
- const effectiveMessage = mustGetMsg();
219
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
220
- 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 });
221
226
  },
222
227
  replyPhoto: (photo, params) => {
223
- const effectiveMessage = mustGetMsg();
224
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
225
- 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 });
226
231
  },
227
232
  replyDocument: (document, params) => {
228
- const effectiveMessage = mustGetMsg();
229
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
230
- 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 });
231
236
  },
232
237
  replyContact: (firstName, number, params) => {
233
- const effectiveMessage = mustGetMsg();
234
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
235
- 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 });
236
241
  },
237
242
  replyLocation: (latitude, longitude, params) => {
238
- const effectiveMessage = mustGetMsg();
239
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
240
- 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 });
241
246
  },
242
247
  replyDice: (params) => {
243
- const effectiveMessage = mustGetMsg();
244
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
245
- 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 });
246
251
  },
247
252
  replyVenue: (latitude, longitude, title, address, params) => {
248
- const effectiveMessage = mustGetMsg();
249
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
250
- 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 });
251
256
  },
252
257
  replyVideo: (video, params) => {
253
- const effectiveMessage = mustGetMsg();
254
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
255
- return this.sendVideo(effectiveMessage.chat.id, video, { ...params, replyToMessageId });
258
+ const { chatId, messageId } = mustGetMsg();
259
+ const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
260
+ return this.sendVideo(chatId, video, { ...params, replyToMessageId });
256
261
  },
257
262
  replyAnimation: (document, params) => {
258
- const effectiveMessage = mustGetMsg();
259
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
260
- 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 });
261
266
  },
262
267
  replyVoice: (document, params) => {
263
- const effectiveMessage = mustGetMsg();
264
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
265
- 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 });
266
271
  },
267
272
  replyAudio: (document, params) => {
268
- const effectiveMessage = mustGetMsg();
269
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
270
- 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 });
271
276
  },
272
277
  replyVideoNote: (videoNote, params) => {
273
- const effectiveMessage = mustGetMsg();
274
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
275
- 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 });
276
281
  },
277
282
  delete: () => {
278
- const effectiveMessage = mustGetMsg();
279
- return this.deleteMessage(effectiveMessage.chat.id, effectiveMessage.id);
283
+ const { chatId, messageId } = mustGetMsg();
284
+ return this.deleteMessage(chatId, messageId);
280
285
  },
281
286
  forward: (to, params) => {
282
- const effectiveMessage = mustGetMsg();
283
- 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);
284
293
  },
285
294
  answerCallbackQuery: (params) => {
286
- const { callbackQuery } = update;
287
- if (callbackQuery === undefined) {
295
+ if (!("callbackQuery" in update)) {
288
296
  UNREACHABLE();
289
297
  }
290
- return this.answerCallbackQuery(callbackQuery.id, params);
298
+ return this.answerCallbackQuery(update.callbackQuery.id, params);
291
299
  },
292
300
  answerInlineQuery: (results, params) => {
293
- const { inlineQuery } = update;
294
- if (inlineQuery == undefined) {
301
+ if (!("inlineQuery" in update)) {
295
302
  UNREACHABLE();
296
303
  }
297
- return this.answerInlineQuery(inlineQuery.id, results, params);
304
+ return this.answerInlineQuery(update.inlineQuery.id, results, params);
298
305
  },
299
306
  sendChatAction: (chatAction, params) => {
300
- const effectiveMessage = mustGetMsg();
301
- return this.sendChatAction(effectiveMessage.chat.id, chatAction, params);
307
+ const { chatId } = mustGetMsg();
308
+ return this.sendChatAction(chatId, chatAction, params);
302
309
  },
303
310
  editMessageText: (messageId, text, params) => {
304
- const effectiveMessage = mustGetMsg();
305
- return this.editMessageText(effectiveMessage.chat.id, messageId, text, params);
311
+ const { chatId } = mustGetMsg();
312
+ return this.editMessageText(chatId, messageId, text, params);
306
313
  },
307
314
  getMessage: (messageId) => {
308
- const effectiveMessage = mustGetMsg();
309
- return this.getMessage(effectiveMessage.chat.id, messageId);
315
+ const { chatId } = mustGetMsg();
316
+ return this.getMessage(chatId, messageId);
310
317
  },
311
318
  getMessages: (messageIds) => {
312
- const effectiveMessage = mustGetMsg();
313
- return this.getMessages(effectiveMessage.chat.id, messageIds);
319
+ const { chatId } = mustGetMsg();
320
+ return this.getMessages(chatId, messageIds);
314
321
  },
315
322
  forwardMessage: (to, messageId, params) => {
316
- const effectiveMessage = mustGetMsg();
317
- return this.forwardMessage(effectiveMessage.chat.id, to, messageId, params);
323
+ const { chatId } = mustGetMsg();
324
+ return this.forwardMessage(chatId, to, messageId, params);
318
325
  },
319
326
  forwardMessages: (to, messageIds, params) => {
320
- const effectiveMessage = mustGetMsg();
321
- return this.forwardMessages(effectiveMessage.chat.id, to, messageIds, params);
327
+ const { chatId } = mustGetMsg();
328
+ return this.forwardMessages(chatId, to, messageIds, params);
322
329
  },
323
330
  deleteMessage: (messageId, params) => {
324
- const effectiveMessage = mustGetMsg();
325
- return this.deleteMessage(effectiveMessage.chat.id, messageId, params);
331
+ const { chatId } = mustGetMsg();
332
+ return this.deleteMessage(chatId, messageId, params);
326
333
  },
327
334
  deleteMessages: (messageIds, params) => {
328
- const effectiveMessage = mustGetMsg();
329
- return this.deleteMessages(effectiveMessage.chat.id, messageIds, params);
335
+ const { chatId } = mustGetMsg();
336
+ return this.deleteMessages(chatId, messageIds, params);
330
337
  },
331
338
  setAvailableReactions: (availableReactions) => {
332
- const effectiveMessage = mustGetMsg();
333
- return this.setAvailableReactions(effectiveMessage.chat.id, availableReactions);
339
+ const { chatId } = mustGetMsg();
340
+ return this.setAvailableReactions(chatId, availableReactions);
334
341
  },
335
342
  addReaction: (messageId, reaction, params) => {
336
- const effectiveMessage = mustGetMsg();
337
- return this.addReaction(effectiveMessage.chat.id, messageId, reaction, params);
343
+ const { chatId } = mustGetMsg();
344
+ return this.addReaction(chatId, messageId, reaction, params);
345
+ },
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
354
  };
340
355
  return cleanObject(context, false);
@@ -395,12 +410,14 @@ export class Client extends ClientAbstract {
395
410
  },
396
411
  })
397
412
  });
398
- _Client_handleUpdateQueue.set(this, new Queue("handleUpdate"));
413
+ _Client_handleUpdateQueues.set(this, new Map());
399
414
  _Client_processUpdatesQueue.set(this, new Queue("processUpdates"));
400
415
  _Client_channelUpdateQueues.set(this, new Map());
416
+ _Client_mainBoxId.set(this, 0n);
401
417
  _Client_ptsUpdateQueue.set(this, new Queue("ptsUpdate"));
402
418
  _Client_lastUpdates.set(this, new Date());
403
419
  _Client_lastGetMe.set(this, null);
420
+ _Client_handleUpdatesSet.set(this, new Set());
404
421
  _Client_usernameResolver.set(this, async (v) => {
405
422
  const inputPeer = await this.getInputPeer(v).then((v) => v[as](types.InputPeerUser));
406
423
  return new types.InputUser(inputPeer);
@@ -426,6 +443,7 @@ export class Client extends ClientAbstract {
426
443
  __classPrivateFieldSet(this, _Client_autoStart, params?.autoStart ?? true, "f");
427
444
  __classPrivateFieldSet(this, _Client_ignoreOutgoing, params?.ignoreOutgoing ?? null, "f");
428
445
  __classPrivateFieldSet(this, _Client_prefixes, params?.prefixes, "f");
446
+ __classPrivateFieldSet(this, _Client_guaranteeUpdateDelivery, params?.guaranteeUpdateDelivery ?? false, "f");
429
447
  const transportProvider = this.transportProvider;
430
448
  this.transportProvider = (params) => {
431
449
  const transport = transportProvider(params);
@@ -490,7 +508,7 @@ export class Client extends ClientAbstract {
490
508
  */
491
509
  async setDc(dc) {
492
510
  if (!__classPrivateFieldGet(this, _Client_storageInited, "f")) {
493
- await this.storage.init();
511
+ await this.storage.initialize();
494
512
  __classPrivateFieldSet(this, _Client_storageInited, true, "f");
495
513
  }
496
514
  if (await this.storage.getDc() != dc) {
@@ -512,7 +530,10 @@ export class Client extends ClientAbstract {
512
530
  const release = await __classPrivateFieldGet(this, _Client_connectMutex, "f").acquire();
513
531
  try {
514
532
  if (!__classPrivateFieldGet(this, _Client_storageInited, "f")) {
515
- await this.storage.init();
533
+ await this.storage.initialize();
534
+ if (!__classPrivateFieldGet(this, _Client_guaranteeUpdateDelivery, "f")) {
535
+ await this.storage.deleteUpdates();
536
+ }
516
537
  __classPrivateFieldSet(this, _Client_storageInited, true, "f");
517
538
  }
518
539
  const authKey = await this.storage.getAuthKey();
@@ -555,8 +576,8 @@ export class Client extends ClientAbstract {
555
576
  release();
556
577
  }
557
578
  }
558
- 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_channelUpdateQueues = new WeakMap(), _Client_ptsUpdateQueue = 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) {
559
- __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 () => {
560
581
  await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { connectionState }), resolve);
561
582
  });
562
583
  __classPrivateFieldSet(this, _Client_lastPropagatedConnectionState, connectionState, "f");
@@ -887,11 +908,11 @@ export class Client extends ClientAbstract {
887
908
  dRecv("RPCResult: %s", (typeof result === "object" && name in result) ? result[name] : result.constructor.name);
888
909
  }
889
910
  const messageId = message.body.messageId;
911
+ const promise = __classPrivateFieldGet(this, _Client_promises, "f").get(messageId);
890
912
  const resolvePromise = () => {
891
- const promise = __classPrivateFieldGet(this, _Client_promises, "f").get(messageId);
892
913
  if (promise) {
893
914
  if (result instanceof types.Rpc_error) {
894
- promise.reject(upgradeInstance(result));
915
+ promise.reject(upgradeInstance(result, promise.call));
895
916
  }
896
917
  else {
897
918
  promise.resolve(result);
@@ -901,7 +922,7 @@ export class Client extends ClientAbstract {
901
922
  };
902
923
  if (result instanceof types._Updates || result instanceof types._Update) {
903
924
  __classPrivateFieldGet(this, _Client_processUpdatesQueue, "f").add(async () => {
904
- 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);
905
926
  resolvePromise();
906
927
  });
907
928
  }
@@ -1002,13 +1023,14 @@ export class Client extends ClientAbstract {
1002
1023
  }
1003
1024
  },
1004
1025
  reject: () => { },
1026
+ call: function_,
1005
1027
  });
1006
1028
  return;
1007
1029
  }
1008
1030
  let result;
1009
1031
  try {
1010
1032
  result = await new Promise((resolve, reject) => {
1011
- __classPrivateFieldGet(this, _Client_promises, "f").set(message.id, { resolve, reject });
1033
+ __classPrivateFieldGet(this, _Client_promises, "f").set(message.id, { resolve, reject, call: function_ });
1012
1034
  });
1013
1035
  }
1014
1036
  catch (err) {
@@ -1069,6 +1091,15 @@ export class Client extends ClientAbstract {
1069
1091
  }
1070
1092
  }
1071
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
+ }
1072
1103
  }, _Client_checkGap = async function _Client_checkGap(pts, ptsCount) {
1073
1104
  const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
1074
1105
  if (localState.pts + ptsCount < pts) {
@@ -1082,7 +1113,7 @@ export class Client extends ClientAbstract {
1082
1113
  if (localPts + ptsCount < pts) {
1083
1114
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverChannelUpdateGap).call(this, channelId, "processUpdates");
1084
1115
  }
1085
- }, _Client_processChannelUpdate = async function _Client_processChannelUpdate(update, checkGap) {
1116
+ }, _Client_processChannelPtsUpdateInner = async function _Client_processChannelPtsUpdateInner(update, checkGap) {
1086
1117
  const channelId = update instanceof types.UpdateNewChannelMessage || update instanceof types.UpdateEditChannelMessage ? update.message.peer_id[as](types.PeerChannel).channel_id : update.channel_id;
1087
1118
  if (update instanceof types.UpdateChannelTooLong) {
1088
1119
  if (update.pts != undefined) {
@@ -1102,11 +1133,23 @@ export class Client extends ClientAbstract {
1102
1133
  return;
1103
1134
  }
1104
1135
  }
1105
- await this.storage.setChannelPts(channelId, update.pts);
1106
- __classPrivateFieldGet(this, _Client_handleUpdateQueue, "f").add(async () => {
1107
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleUpdate).call(this, update);
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
+ }
1108
1151
  });
1109
- }, _Client_queueChannelUpdate = function _Client_queueChannelUpdate(update, checkGap) {
1152
+ }, _Client_processChannelPtsUpdate = function _Client_processChannelPtsUpdate(update, checkGap) {
1110
1153
  const channelId = update instanceof types.UpdateNewChannelMessage || update instanceof types.UpdateEditChannelMessage ? update.message.peer_id[as](types.PeerChannel).channel_id : update.channel_id;
1111
1154
  let queue = __classPrivateFieldGet(this, _Client_channelUpdateQueues, "f").get(channelId);
1112
1155
  if (queue == undefined) {
@@ -1114,9 +1157,9 @@ export class Client extends ClientAbstract {
1114
1157
  __classPrivateFieldGet(this, _Client_channelUpdateQueues, "f").set(channelId, queue);
1115
1158
  }
1116
1159
  queue.add(async () => {
1117
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChannelUpdate).call(this, update, checkGap);
1160
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChannelPtsUpdateInner).call(this, update, checkGap);
1118
1161
  });
1119
- }, _Client_handlePtsUpdate = async function _Client_handlePtsUpdate(update, checkGap) {
1162
+ }, _Client_processPtsUpdateInner = async function _Client_processPtsUpdateInner(update, checkGap) {
1120
1163
  const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
1121
1164
  if (update.pts != 0) {
1122
1165
  if (checkGap) {
@@ -1126,15 +1169,19 @@ export class Client extends ClientAbstract {
1126
1169
  return;
1127
1170
  }
1128
1171
  }
1129
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdatePts).call(this, update.pts);
1130
- __classPrivateFieldGet(this, _Client_handleUpdateQueue, "f").add(async () => {
1131
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleUpdate).call(this, update);
1132
- });
1133
- }, _Client_queuePtsUpdate = function _Client_queuePtsUpdate(update, checkGap) {
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) {
1134
1181
  __classPrivateFieldGet(this, _Client_ptsUpdateQueue, "f").add(async () => {
1135
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handlePtsUpdate).call(this, update, checkGap);
1182
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processPtsUpdateInner).call(this, update, checkGap);
1136
1183
  });
1137
- }, _Client_processUpdates = async function _Client_processUpdates(updates_, checkGap) {
1184
+ }, _Client_processUpdates = async function _Client_processUpdates(updates_, checkGap, call = null) {
1138
1185
  __classPrivateFieldSet(this, _Client_lastUpdates, new Date(), "f");
1139
1186
  /// First, individual updates (Update[1]) are extracted from Updates.[2]
1140
1187
  ///
@@ -1226,6 +1273,30 @@ export class Client extends ClientAbstract {
1226
1273
  }),
1227
1274
  ];
1228
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
+ }
1229
1300
  else if (updates_ instanceof types.UpdatesTooLong) {
1230
1301
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverUpdateGap).call(this, "updatesTooLong");
1231
1302
  return;
@@ -1259,15 +1330,13 @@ export class Client extends ClientAbstract {
1259
1330
  }
1260
1331
  }
1261
1332
  else if (isPtsUpdate(update)) {
1262
- __classPrivateFieldGet(this, _Client_instances, "m", _Client_queuePtsUpdate).call(this, update, checkGap);
1333
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_processPtsUpdate).call(this, update, checkGap);
1263
1334
  }
1264
1335
  else if (isChannelPtsUpdate(update)) {
1265
- __classPrivateFieldGet(this, _Client_instances, "m", _Client_queueChannelUpdate).call(this, update, checkGap);
1336
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChannelPtsUpdate).call(this, update, checkGap);
1266
1337
  }
1267
1338
  else {
1268
- __classPrivateFieldGet(this, _Client_handleUpdateQueue, "f").add(async () => {
1269
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleUpdate).call(this, update);
1270
- });
1339
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_queueUpdate).call(this, update, 0n, false);
1271
1340
  }
1272
1341
  }
1273
1342
  }, _Client_setUpdateStateDate = async function _Client_setUpdateStateDate(date) {
@@ -1598,7 +1667,7 @@ export class Client extends ClientAbstract {
1598
1667
  }
1599
1668
  }
1600
1669
  }
1601
- else if (updates instanceof types.UpdateShortSentMessage || updates instanceof types.UpdateShortSentMessage) {
1670
+ else if (updates instanceof types.UpdateShortSentMessage) {
1602
1671
  const message = await this.getMessage(chatId, updates.id);
1603
1672
  if (message != null) {
1604
1673
  messages.push(message);
@@ -2190,7 +2259,6 @@ export class Client extends ClientAbstract {
2190
2259
  else {
2191
2260
  return false;
2192
2261
  }
2193
- // deno-lint-ignore no-explicit-any
2194
2262
  }, ...middleawre);
2195
2263
  }
2196
2264
  command(commands, ...middleawre) {
@@ -2241,27 +2309,27 @@ export class Client extends ClientAbstract {
2241
2309
  *
2242
2310
  * @method
2243
2311
  */
2244
- async setMyDescription({ description, languageCode }) {
2312
+ async setMyDescription(params) {
2245
2313
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "setMyDescription");
2246
- 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 ?? "" });
2247
2315
  }
2248
2316
  /**
2249
2317
  * Set the bot's name in the given language. Bot-only.
2250
2318
  *
2251
2319
  * @method
2252
2320
  */
2253
- async setMyName({ name, languageCode }) {
2321
+ async setMyName(params) {
2254
2322
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "setMyName");
2255
- 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 ?? "" });
2256
2324
  }
2257
2325
  /**
2258
2326
  * Set the bot's short description in the given language. Bot-only.
2259
2327
  *
2260
2328
  * @method
2261
2329
  */
2262
- async setMyShortDescription({ shortDescription: about, languageCode }) {
2330
+ async setMyShortDescription(params) {
2263
2331
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "setMyShortDescription");
2264
- 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 ?? "" });
2265
2333
  }
2266
2334
  /**
2267
2335
  * Get the bot's description in the given language. Bot-only.
@@ -2833,21 +2901,48 @@ export class Client extends ClientAbstract {
2833
2901
  });
2834
2902
  }
2835
2903
  /**
2836
- * 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.
2837
2915
  *
2838
2916
  * @param chatId The identifier of the chat which the message belongs to.
2839
2917
  * @param messageId The identifier of the message to add the reaction to.
2840
2918
  * @param reaction The reaction to add.
2841
2919
  */
2842
2920
  async addReaction(chatId, messageId, reaction, params) {
2843
- // TODO: check storage and skip if already there
2844
- await this.api.messages.sendReaction({
2845
- peer: await this.getInputPeer(chatId),
2846
- msg_id: messageId,
2847
- reaction: [reactionToTlObject(reaction)],
2848
- big: params?.big ? true : undefined,
2849
- add_to_recent: params?.addToRecents ? true : undefined,
2850
- });
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
+ }
2851
2946
  }
2852
2947
  }
2853
2948
  _a = Client, _Client_getMe = async function _Client_getMe() {
@@ -2859,9 +2954,40 @@ _a = Client, _Client_getMe = async function _Client_getMe() {
2859
2954
  __classPrivateFieldSet(this, _Client_lastGetMe, user, "f");
2860
2955
  return user;
2861
2956
  }
2862
- }, _Client_handleUpdate =
2863
- // TODO: log errors
2864
- async function _Client_handleUpdate(update) {
2957
+ }, _Client_handleStoredUpdates = async function _Client_handleStoredUpdates(boxId) {
2958
+ if (__classPrivateFieldGet(this, _Client_handleUpdatesSet, "f").has(boxId)) {
2959
+ return;
2960
+ }
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();
2865
2991
  if (update instanceof types.UpdateUserName) {
2866
2992
  await this.storage.updateUsernames("user", update.user_id, update.usernames.map((v) => v.username));
2867
2993
  const peer = new types.PeerUser(update);
@@ -2877,7 +3003,7 @@ async function _Client_handleUpdate(update) {
2877
3003
  if (update.message instanceof types.Message || update.message instanceof types.MessageService) {
2878
3004
  const chatId = peerToChatId(update.message.peer_id);
2879
3005
  await this.storage.setMessage(chatId, update.message.id, update.message);
2880
- 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))());
2881
3007
  }
2882
3008
  }
2883
3009
  if (update instanceof types.UpdateMessageReactions) {
@@ -2886,16 +3012,34 @@ async function _Client_handleUpdate(update) {
2886
3012
  if (message instanceof types.Message) {
2887
3013
  message.reactions = update.reactions;
2888
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))());
2889
3037
  }
2890
- const recentReactions = update.reactions.recent_reactions ?? [];
2891
- const reactions = update.reactions.results.map((v) => constructMessageReaction(v, recentReactions));
2892
- await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { reactions: { chatId, messageId: update.msg_id, reactions } }), resolve);
2893
3038
  }
2894
3039
  if (update instanceof types.UpdateNewMessage ||
2895
3040
  update instanceof types.UpdateNewChannelMessage ||
2896
3041
  update instanceof types.UpdateEditMessage ||
2897
3042
  update instanceof types.UpdateEditChannelMessage) {
2898
- const key = update instanceof types.UpdateNewMessage || update instanceof types.UpdateNewChannelMessage ? "message" : "editedMessage";
2899
3043
  if (!(update.message instanceof types.MessageEmpty)) {
2900
3044
  const isOutgoing = update.message.out;
2901
3045
  let shouldIgnore = isOutgoing ? (await this.storage.getAccountType()) == "user" ? false : true : false;
@@ -2904,7 +3048,16 @@ async function _Client_handleUpdate(update) {
2904
3048
  }
2905
3049
  if (!shouldIgnore) {
2906
3050
  const message = await constructMessage(update.message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this));
2907
- 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
+ })());
2908
3061
  }
2909
3062
  }
2910
3063
  }
@@ -2913,16 +3066,21 @@ async function _Client_handleUpdate(update) {
2913
3066
  for (const messageId of update.messages) {
2914
3067
  const chatId = await this.storage.getMessageChat(messageId);
2915
3068
  if (chatId) {
2916
- const message = await this.storage.getMessage(chatId, messageId);
2917
- if (message != null && !(message instanceof types.MessageEmpty)) {
2918
- deletedMessages.push(await constructMessage(message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this)));
2919
- }
2920
- await this.storage.setMessage(chatId, messageId, null);
2921
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId);
3069
+ deletedMessages.push({ chatId, messageId });
2922
3070
  }
2923
3071
  }
2924
3072
  if (deletedMessages.length > 0) {
2925
- 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
+ })());
2926
3084
  }
2927
3085
  }
2928
3086
  else if (update instanceof types.UpdateDeleteChannelMessages) {
@@ -2930,24 +3088,43 @@ async function _Client_handleUpdate(update) {
2930
3088
  const deletedMessages = new Array();
2931
3089
  for (const messageId of update.messages) {
2932
3090
  const message = await this.storage.getMessage(chatId, messageId);
2933
- if (message != null && !(message instanceof types.MessageEmpty)) {
2934
- 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 });
2935
3093
  }
2936
- await this.storage.setMessage(chatId, messageId, null);
2937
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId);
2938
3094
  }
2939
3095
  if (deletedMessages.length > 0) {
2940
- 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
+ })());
2941
3107
  }
2942
3108
  }
2943
3109
  if (update instanceof types.UpdateBotCallbackQuery || update instanceof types.UpdateInlineBotCallbackQuery) {
2944
- 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))());
2945
3111
  }
2946
3112
  else if (update instanceof types.UpdateBotInlineQuery) {
2947
- 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))());
2948
3114
  }
2949
3115
  else if (update instanceof types.UpdateBotInlineSend) {
2950
- 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
+ }
2951
3128
  }
2952
3129
  if (update instanceof types.UpdatePinnedDialogs) {
2953
3130
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatePinnedChats).call(this, update);
@@ -2985,6 +3162,7 @@ async function _Client_handleUpdate(update) {
2985
3162
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updateOrAddChat).call(this, peerToChatId(peer));
2986
3163
  }
2987
3164
  }
3165
+ return () => Promise.all(promises);
2988
3166
  }, _Client_constructReplyMarkup = async function _Client_constructReplyMarkup(params) {
2989
3167
  if (params?.replyMarkup) {
2990
3168
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "replyMarkup");
@@ -3091,7 +3269,7 @@ async function _Client_setMyInfo(info) {
3091
3269
  }
3092
3270
  const [chat] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
3093
3271
  const update = chat === undefined ? { deletedChat: { chatId } } : added ? { newChat: chat } : { editedChat: chat };
3094
- __classPrivateFieldGet(this, _Client_handleUpdateQueue, "f").add(async () => {
3272
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_getHandleUpdateQueue).call(this, __classPrivateFieldGet(this, _Client_mainBoxId, "f")).add(async () => {
3095
3273
  await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, update), resolve);
3096
3274
  });
3097
3275
  }, _Client_reassignChatLastMessage = async function _Client_reassignChatLastMessage(chatId, add = false, sendUpdate = true) {
@@ -3099,11 +3277,11 @@ async function _Client_setMyInfo(info) {
3099
3277
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertUser).call(this, "");
3100
3278
  }
3101
3279
  catch {
3102
- return;
3280
+ return () => Promise.resolve();
3103
3281
  }
3104
3282
  const [chat, listId] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
3105
3283
  if (!chat && !add) {
3106
- return;
3284
+ return () => Promise.resolve();
3107
3285
  }
3108
3286
  const message_ = await this.storage.getLastMessage(chatId);
3109
3287
  if (message_ != null) {
@@ -3123,9 +3301,9 @@ async function _Client_setMyInfo(info) {
3123
3301
  await this.storage.setChat(listId, chatId, chat.pinned, chat.lastMessage?.id ?? 0, chat.lastMessage?.date ?? new Date(0));
3124
3302
  }
3125
3303
  if (sendUpdate) {
3126
- 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);
3127
3305
  }
3128
- return;
3306
+ return () => Promise.resolve();
3129
3307
  }
3130
3308
  const message = await this.getHistory(chatId, { limit: 1 }).then((v) => v[0]);
3131
3309
  if (message !== undefined) {
@@ -3143,17 +3321,18 @@ async function _Client_setMyInfo(info) {
3143
3321
  __classPrivateFieldGet(this, _Client_chats, "f").set(chatId, chat);
3144
3322
  }
3145
3323
  if (sendUpdate) {
3146
- 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);
3147
3325
  }
3148
- return;
3326
+ return () => Promise.resolve();
3149
3327
  }
3150
3328
  if (chat) {
3151
3329
  chat.order = getChatOrder(undefined, chat.pinned);
3152
3330
  chat.lastMessage = undefined;
3153
3331
  if (sendUpdate) {
3154
- 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);
3155
3333
  }
3156
3334
  }
3335
+ return () => Promise.resolve();
3157
3336
  }, _Client_tryGetChatId = function _Client_tryGetChatId(username) {
3158
3337
  username = username.toLowerCase();
3159
3338
  for (const chat of __classPrivateFieldGet(this, _Client_chats, "f").values()) {
@@ -3328,4 +3507,12 @@ async function _Client_setMyInfo(info) {
3328
3507
  chats.set(chat.id, chat);
3329
3508
  await this.storage.setChat(listId, chat.id, chat.pinned, chat.lastMessage?.id ?? 0, chat.lastMessage?.date ?? new Date(0));
3330
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
+ });
3331
3518
  };