@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
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  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");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- 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;
13
+ 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;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.Client = exports.ConnectionError = exports.restartAuth = exports.skipInvoke = exports.handleMigrationError = void 0;
16
16
  const _0_deps_js_1 = require("../0_deps.js");
@@ -20,14 +20,13 @@ const _3_storage_js_1 = require("../3_storage.js");
20
20
  const _3_types_js_1 = require("../3_types.js");
21
21
  const _4_constants_js_1 = require("../4_constants.js");
22
22
  const _4_errors_js_1 = require("../4_errors.js");
23
+ const _0_client_abstract_js_1 = require("./0_client_abstract.js");
23
24
  const _0_html_js_1 = require("./0_html.js");
24
25
  const _0_message_js_1 = require("./0_message.js");
25
26
  const _0_password_js_1 = require("./0_password.js");
26
27
  const _0_utilities_js_1 = require("./0_utilities.js");
27
- const _1_client_abstract_js_1 = require("./1_client_abstract.js");
28
+ const _1_composer_js_1 = require("./1_composer.js");
28
29
  const _2_client_plain_js_1 = require("./2_client_plain.js");
29
- const _3_types_js_2 = require("./3_types.js");
30
- const _4_composer_js_1 = require("./4_composer.js");
31
30
  const d = (0, _0_deps_js_1.debug)("Client");
32
31
  const dGap = (0, _0_deps_js_1.debug)("Client/recoverUpdateGap");
33
32
  const dGapC = (0, _0_deps_js_1.debug)("Client/recoverChannelUpdateGap");
@@ -47,7 +46,7 @@ exports.restartAuth = Symbol();
47
46
  class ConnectionError extends Error {
48
47
  }
49
48
  exports.ConnectionError = ConnectionError;
50
- class Client extends _1_client_abstract_js_1.ClientAbstract {
49
+ class Client extends _0_client_abstract_js_1.ClientAbstract {
51
50
  /**
52
51
  * Constructs the client.
53
52
  *
@@ -76,6 +75,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
76
75
  _Client_promises.set(this, new Map());
77
76
  _Client_toAcknowledge.set(this, new Set());
78
77
  _Client_updateState.set(this, void 0);
78
+ _Client_guaranteeUpdateDelivery.set(this, void 0);
79
79
  Object.defineProperty(this, "storage", {
80
80
  enumerable: true,
81
81
  configurable: true,
@@ -185,24 +185,29 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
185
185
  })
186
186
  });
187
187
  _Client_constructContext.set(this, async (update) => {
188
- const msg = update.message ?? update.editedMessage ?? update.callbackQuery?.message;
188
+ const msg = "message" in update ? update.message : "editedMessage" in update ? update.editedMessage : "callbackQuery" in update ? update.callbackQuery.message : undefined;
189
+ const reactions = "messageInteractions" in update ? update.messageInteractions : undefined;
189
190
  const mustGetMsg = () => {
190
191
  if (msg !== undefined) {
191
- return msg;
192
+ return { chatId: msg.chat.id, messageId: msg.id };
193
+ }
194
+ else if (reactions !== undefined) {
195
+ return { chatId: reactions.chatId, messageId: reactions.messageId };
192
196
  }
193
197
  else {
194
198
  (0, _1_utilities_js_1.UNREACHABLE)();
195
199
  }
196
200
  };
197
201
  const chat = msg?.chat;
198
- const from = update.callbackQuery?.from ?? update.inlineQuery?.from ?? update.message?.from ?? update.editedMessage?.from;
202
+ 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;
199
203
  const senderChat = msg?.senderChat;
200
- const getReplyToMessageId = (quote, effectiveMessage) => {
201
- const shouldQuote = quote === undefined ? effectiveMessage.chat.type != "private" : quote;
202
- const replyToMessageId = shouldQuote ? effectiveMessage.id : undefined;
204
+ const getReplyToMessageId = (quote, chatId, messageId) => {
205
+ const isPrivate = chatId > 0;
206
+ const shouldQuote = quote === undefined ? !isPrivate : quote;
207
+ const replyToMessageId = shouldQuote ? messageId : undefined;
203
208
  return replyToMessageId;
204
209
  };
205
- 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);
210
+ 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
211
  const context = {
207
212
  ...update,
208
213
  client: this,
@@ -215,131 +220,141 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
215
220
  return () => update;
216
221
  },
217
222
  reply: (text, params) => {
218
- const effectiveMessage = mustGetMsg();
219
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
220
- return this.sendMessage(effectiveMessage.chat.id, text, { ...params, replyToMessageId });
223
+ const { chatId, messageId } = mustGetMsg();
224
+ const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
225
+ return this.sendMessage(chatId, text, { ...params, replyToMessageId });
221
226
  },
222
227
  replyPoll: (question, options, params) => {
223
- const effectiveMessage = mustGetMsg();
224
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
225
- return this.sendPoll(effectiveMessage.chat.id, question, options, { ...params, replyToMessageId });
228
+ const { chatId, messageId } = mustGetMsg();
229
+ const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
230
+ return this.sendPoll(chatId, question, options, { ...params, replyToMessageId });
226
231
  },
227
232
  replyPhoto: (photo, params) => {
228
- const effectiveMessage = mustGetMsg();
229
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
230
- return this.sendPhoto(effectiveMessage.chat.id, photo, { ...params, replyToMessageId });
233
+ const { chatId, messageId } = mustGetMsg();
234
+ const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
235
+ return this.sendPhoto(chatId, photo, { ...params, replyToMessageId });
231
236
  },
232
237
  replyDocument: (document, params) => {
233
- const effectiveMessage = mustGetMsg();
234
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
235
- return this.sendDocument(effectiveMessage.chat.id, document, { ...params, replyToMessageId });
238
+ const { chatId, messageId } = mustGetMsg();
239
+ const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
240
+ return this.sendDocument(chatId, document, { ...params, replyToMessageId });
236
241
  },
237
242
  replyContact: (firstName, number, params) => {
238
- const effectiveMessage = mustGetMsg();
239
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
240
- return this.sendContact(effectiveMessage.chat.id, firstName, number, { ...params, replyToMessageId });
243
+ const { chatId, messageId } = mustGetMsg();
244
+ const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
245
+ return this.sendContact(chatId, firstName, number, { ...params, replyToMessageId });
241
246
  },
242
247
  replyLocation: (latitude, longitude, params) => {
243
- const effectiveMessage = mustGetMsg();
244
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
245
- return this.sendLocation(effectiveMessage.chat.id, latitude, longitude, { ...params, replyToMessageId });
248
+ const { chatId, messageId } = mustGetMsg();
249
+ const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
250
+ return this.sendLocation(chatId, latitude, longitude, { ...params, replyToMessageId });
246
251
  },
247
252
  replyDice: (params) => {
248
- const effectiveMessage = mustGetMsg();
249
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
250
- return this.sendDice(effectiveMessage.chat.id, { ...params, replyToMessageId });
253
+ const { chatId, messageId } = mustGetMsg();
254
+ const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
255
+ return this.sendDice(chatId, { ...params, replyToMessageId });
251
256
  },
252
257
  replyVenue: (latitude, longitude, title, address, params) => {
253
- const effectiveMessage = mustGetMsg();
254
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
255
- return this.sendVenue(effectiveMessage.chat.id, latitude, longitude, title, address, { ...params, replyToMessageId });
258
+ const { chatId, messageId } = mustGetMsg();
259
+ const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
260
+ return this.sendVenue(chatId, latitude, longitude, title, address, { ...params, replyToMessageId });
256
261
  },
257
262
  replyVideo: (video, params) => {
258
- const effectiveMessage = mustGetMsg();
259
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
260
- return this.sendVideo(effectiveMessage.chat.id, video, { ...params, replyToMessageId });
263
+ const { chatId, messageId } = mustGetMsg();
264
+ const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
265
+ return this.sendVideo(chatId, video, { ...params, replyToMessageId });
261
266
  },
262
267
  replyAnimation: (document, params) => {
263
- const effectiveMessage = mustGetMsg();
264
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
265
- return this.sendAnimation(effectiveMessage.chat.id, document, { ...params, replyToMessageId });
268
+ const { chatId, messageId } = mustGetMsg();
269
+ const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
270
+ return this.sendAnimation(chatId, document, { ...params, replyToMessageId });
266
271
  },
267
272
  replyVoice: (document, params) => {
268
- const effectiveMessage = mustGetMsg();
269
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
270
- return this.sendVoice(effectiveMessage.chat.id, document, { ...params, replyToMessageId });
273
+ const { chatId, messageId } = mustGetMsg();
274
+ const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
275
+ return this.sendVoice(chatId, document, { ...params, replyToMessageId });
271
276
  },
272
277
  replyAudio: (document, params) => {
273
- const effectiveMessage = mustGetMsg();
274
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
275
- return this.sendAudio(effectiveMessage.chat.id, document, { ...params, replyToMessageId });
278
+ const { chatId, messageId } = mustGetMsg();
279
+ const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
280
+ return this.sendAudio(chatId, document, { ...params, replyToMessageId });
276
281
  },
277
282
  replyVideoNote: (videoNote, params) => {
278
- const effectiveMessage = mustGetMsg();
279
- const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
280
- return this.sendVideoNote(effectiveMessage.chat.id, videoNote, { ...params, replyToMessageId });
283
+ const { chatId, messageId } = mustGetMsg();
284
+ const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
285
+ return this.sendVideoNote(chatId, videoNote, { ...params, replyToMessageId });
281
286
  },
282
287
  delete: () => {
283
- const effectiveMessage = mustGetMsg();
284
- return this.deleteMessage(effectiveMessage.chat.id, effectiveMessage.id);
288
+ const { chatId, messageId } = mustGetMsg();
289
+ return this.deleteMessage(chatId, messageId);
285
290
  },
286
291
  forward: (to, params) => {
287
- const effectiveMessage = mustGetMsg();
288
- return this.forwardMessage(effectiveMessage.chat.id, to, effectiveMessage.id, params);
292
+ const { chatId, messageId } = mustGetMsg();
293
+ return this.forwardMessage(chatId, to, messageId, params);
294
+ },
295
+ react: (reactions, params) => {
296
+ const { chatId, messageId } = mustGetMsg();
297
+ return this.setReactions(chatId, messageId, reactions, params);
289
298
  },
290
299
  answerCallbackQuery: (params) => {
291
- const { callbackQuery } = update;
292
- if (callbackQuery === undefined) {
300
+ if (!("callbackQuery" in update)) {
293
301
  (0, _1_utilities_js_1.UNREACHABLE)();
294
302
  }
295
- return this.answerCallbackQuery(callbackQuery.id, params);
303
+ return this.answerCallbackQuery(update.callbackQuery.id, params);
296
304
  },
297
305
  answerInlineQuery: (results, params) => {
298
- const { inlineQuery } = update;
299
- if (inlineQuery == undefined) {
306
+ if (!("inlineQuery" in update)) {
300
307
  (0, _1_utilities_js_1.UNREACHABLE)();
301
308
  }
302
- return this.answerInlineQuery(inlineQuery.id, results, params);
309
+ return this.answerInlineQuery(update.inlineQuery.id, results, params);
303
310
  },
304
311
  sendChatAction: (chatAction, params) => {
305
- const effectiveMessage = mustGetMsg();
306
- return this.sendChatAction(effectiveMessage.chat.id, chatAction, params);
312
+ const { chatId } = mustGetMsg();
313
+ return this.sendChatAction(chatId, chatAction, params);
307
314
  },
308
315
  editMessageText: (messageId, text, params) => {
309
- const effectiveMessage = mustGetMsg();
310
- return this.editMessageText(effectiveMessage.chat.id, messageId, text, params);
316
+ const { chatId } = mustGetMsg();
317
+ return this.editMessageText(chatId, messageId, text, params);
311
318
  },
312
319
  getMessage: (messageId) => {
313
- const effectiveMessage = mustGetMsg();
314
- return this.getMessage(effectiveMessage.chat.id, messageId);
320
+ const { chatId } = mustGetMsg();
321
+ return this.getMessage(chatId, messageId);
315
322
  },
316
323
  getMessages: (messageIds) => {
317
- const effectiveMessage = mustGetMsg();
318
- return this.getMessages(effectiveMessage.chat.id, messageIds);
324
+ const { chatId } = mustGetMsg();
325
+ return this.getMessages(chatId, messageIds);
319
326
  },
320
327
  forwardMessage: (to, messageId, params) => {
321
- const effectiveMessage = mustGetMsg();
322
- return this.forwardMessage(effectiveMessage.chat.id, to, messageId, params);
328
+ const { chatId } = mustGetMsg();
329
+ return this.forwardMessage(chatId, to, messageId, params);
323
330
  },
324
331
  forwardMessages: (to, messageIds, params) => {
325
- const effectiveMessage = mustGetMsg();
326
- return this.forwardMessages(effectiveMessage.chat.id, to, messageIds, params);
332
+ const { chatId } = mustGetMsg();
333
+ return this.forwardMessages(chatId, to, messageIds, params);
327
334
  },
328
335
  deleteMessage: (messageId, params) => {
329
- const effectiveMessage = mustGetMsg();
330
- return this.deleteMessage(effectiveMessage.chat.id, messageId, params);
336
+ const { chatId } = mustGetMsg();
337
+ return this.deleteMessage(chatId, messageId, params);
331
338
  },
332
339
  deleteMessages: (messageIds, params) => {
333
- const effectiveMessage = mustGetMsg();
334
- return this.deleteMessages(effectiveMessage.chat.id, messageIds, params);
340
+ const { chatId } = mustGetMsg();
341
+ return this.deleteMessages(chatId, messageIds, params);
335
342
  },
336
343
  setAvailableReactions: (availableReactions) => {
337
- const effectiveMessage = mustGetMsg();
338
- return this.setAvailableReactions(effectiveMessage.chat.id, availableReactions);
344
+ const { chatId } = mustGetMsg();
345
+ return this.setAvailableReactions(chatId, availableReactions);
339
346
  },
340
347
  addReaction: (messageId, reaction, params) => {
341
- const effectiveMessage = mustGetMsg();
342
- return this.addReaction(effectiveMessage.chat.id, messageId, reaction, params);
348
+ const { chatId } = mustGetMsg();
349
+ return this.addReaction(chatId, messageId, reaction, params);
350
+ },
351
+ removeReaction: (messageId, reaction) => {
352
+ const { chatId } = mustGetMsg();
353
+ return this.removeReaction(chatId, messageId, reaction);
354
+ },
355
+ setReactions: (messageId, reactions, params) => {
356
+ const { chatId } = mustGetMsg();
357
+ return this.setReactions(chatId, messageId, reactions, params);
343
358
  },
344
359
  };
345
360
  return (0, _1_utilities_js_1.cleanObject)(context, false);
@@ -400,18 +415,20 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
400
415
  },
401
416
  })
402
417
  });
403
- _Client_handleUpdateQueue.set(this, new _1_utilities_js_1.Queue("handleUpdate"));
418
+ _Client_handleUpdateQueues.set(this, new Map());
404
419
  _Client_processUpdatesQueue.set(this, new _1_utilities_js_1.Queue("processUpdates"));
405
420
  _Client_channelUpdateQueues.set(this, new Map());
421
+ _Client_mainBoxId.set(this, 0n);
406
422
  _Client_ptsUpdateQueue.set(this, new _1_utilities_js_1.Queue("ptsUpdate"));
407
423
  _Client_lastUpdates.set(this, new Date());
408
424
  _Client_lastGetMe.set(this, null);
425
+ _Client_handleUpdatesSet.set(this, new Set());
409
426
  _Client_usernameResolver.set(this, async (v) => {
410
427
  const inputPeer = await this.getInputPeer(v).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.InputPeerUser));
411
428
  return new _2_tl_js_1.types.InputUser(inputPeer);
412
429
  });
413
430
  //#region Composer
414
- _Client_handle.set(this, _4_composer_js_1.skip);
431
+ _Client_handle.set(this, _1_composer_js_1.skip);
415
432
  _Client_chats.set(this, new Map());
416
433
  _Client_archivedChats.set(this, new Map());
417
434
  _Client_chatsLoadedFromStorage.set(this, false);
@@ -431,6 +448,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
431
448
  __classPrivateFieldSet(this, _Client_autoStart, params?.autoStart ?? true, "f");
432
449
  __classPrivateFieldSet(this, _Client_ignoreOutgoing, params?.ignoreOutgoing ?? null, "f");
433
450
  __classPrivateFieldSet(this, _Client_prefixes, params?.prefixes, "f");
451
+ __classPrivateFieldSet(this, _Client_guaranteeUpdateDelivery, params?.guaranteeUpdateDelivery ?? false, "f");
434
452
  const transportProvider = this.transportProvider;
435
453
  this.transportProvider = (params) => {
436
454
  const transport = transportProvider(params);
@@ -495,7 +513,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
495
513
  */
496
514
  async setDc(dc) {
497
515
  if (!__classPrivateFieldGet(this, _Client_storageInited, "f")) {
498
- await this.storage.init();
516
+ await this.storage.initialize();
499
517
  __classPrivateFieldSet(this, _Client_storageInited, true, "f");
500
518
  }
501
519
  if (await this.storage.getDc() != dc) {
@@ -517,7 +535,10 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
517
535
  const release = await __classPrivateFieldGet(this, _Client_connectMutex, "f").acquire();
518
536
  try {
519
537
  if (!__classPrivateFieldGet(this, _Client_storageInited, "f")) {
520
- await this.storage.init();
538
+ await this.storage.initialize();
539
+ if (!__classPrivateFieldGet(this, _Client_guaranteeUpdateDelivery, "f")) {
540
+ await this.storage.deleteUpdates();
541
+ }
521
542
  __classPrivateFieldSet(this, _Client_storageInited, true, "f");
522
543
  }
523
544
  const authKey = await this.storage.getAuthKey();
@@ -560,8 +581,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
560
581
  release();
561
582
  }
562
583
  }
563
- 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) {
564
- __classPrivateFieldGet(this, _Client_handleUpdateQueue, "f").add(async () => {
584
+ 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) {
585
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_getHandleUpdateQueue).call(this, __classPrivateFieldGet(this, _Client_mainBoxId, "f")).add(async () => {
565
586
  await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { connectionState }), _0_utilities_js_1.resolve);
566
587
  });
567
588
  __classPrivateFieldSet(this, _Client_lastPropagatedConnectionState, connectionState, "f");
@@ -892,11 +913,11 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
892
913
  dRecv("RPCResult: %s", (typeof result === "object" && _2_tl_js_1.name in result) ? result[_2_tl_js_1.name] : result.constructor.name);
893
914
  }
894
915
  const messageId = message.body.messageId;
916
+ const promise = __classPrivateFieldGet(this, _Client_promises, "f").get(messageId);
895
917
  const resolvePromise = () => {
896
- const promise = __classPrivateFieldGet(this, _Client_promises, "f").get(messageId);
897
918
  if (promise) {
898
919
  if (result instanceof _2_tl_js_1.types.Rpc_error) {
899
- promise.reject((0, _4_errors_js_1.upgradeInstance)(result));
920
+ promise.reject((0, _4_errors_js_1.upgradeInstance)(result, promise.call));
900
921
  }
901
922
  else {
902
923
  promise.resolve(result);
@@ -906,7 +927,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
906
927
  };
907
928
  if (result instanceof _2_tl_js_1.types._Updates || result instanceof _2_tl_js_1.types._Update) {
908
929
  __classPrivateFieldGet(this, _Client_processUpdatesQueue, "f").add(async () => {
909
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, result, true);
930
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, result, true, promise?.call);
910
931
  resolvePromise();
911
932
  });
912
933
  }
@@ -1007,13 +1028,14 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1007
1028
  }
1008
1029
  },
1009
1030
  reject: () => { },
1031
+ call: function_,
1010
1032
  });
1011
1033
  return;
1012
1034
  }
1013
1035
  let result;
1014
1036
  try {
1015
1037
  result = await new Promise((resolve, reject) => {
1016
- __classPrivateFieldGet(this, _Client_promises, "f").set(message.id, { resolve, reject });
1038
+ __classPrivateFieldGet(this, _Client_promises, "f").set(message.id, { resolve, reject, call: function_ });
1017
1039
  });
1018
1040
  }
1019
1041
  catch (err) {
@@ -1074,6 +1096,15 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1074
1096
  }
1075
1097
  }
1076
1098
  }
1099
+ }, _Client_getHandleUpdateQueue = function _Client_getHandleUpdateQueue(boxId) {
1100
+ let queue = __classPrivateFieldGet(this, _Client_handleUpdateQueues, "f").get(boxId);
1101
+ if (queue !== undefined) {
1102
+ return queue;
1103
+ }
1104
+ else {
1105
+ queue = new _1_utilities_js_1.Queue(`handleUpdate-${boxId}`);
1106
+ return queue;
1107
+ }
1077
1108
  }, _Client_checkGap = async function _Client_checkGap(pts, ptsCount) {
1078
1109
  const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
1079
1110
  if (localState.pts + ptsCount < pts) {
@@ -1087,7 +1118,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1087
1118
  if (localPts + ptsCount < pts) {
1088
1119
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverChannelUpdateGap).call(this, channelId, "processUpdates");
1089
1120
  }
1090
- }, _Client_processChannelUpdate = async function _Client_processChannelUpdate(update, checkGap) {
1121
+ }, _Client_processChannelPtsUpdateInner = async function _Client_processChannelPtsUpdateInner(update, checkGap) {
1091
1122
  const channelId = update instanceof _2_tl_js_1.types.UpdateNewChannelMessage || update instanceof _2_tl_js_1.types.UpdateEditChannelMessage ? update.message.peer_id[_2_tl_js_1.as](_2_tl_js_1.types.PeerChannel).channel_id : update.channel_id;
1092
1123
  if (update instanceof _2_tl_js_1.types.UpdateChannelTooLong) {
1093
1124
  if (update.pts != undefined) {
@@ -1107,11 +1138,23 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1107
1138
  return;
1108
1139
  }
1109
1140
  }
1110
- await this.storage.setChannelPts(channelId, update.pts);
1111
- __classPrivateFieldGet(this, _Client_handleUpdateQueue, "f").add(async () => {
1112
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleUpdate).call(this, update);
1141
+ if (__classPrivateFieldGet(this, _Client_guaranteeUpdateDelivery, "f")) {
1142
+ await this.storage.setUpdate(channelId, update);
1143
+ }
1144
+ if (update.pts != 0) {
1145
+ await this.storage.setChannelPts(channelId, update.pts);
1146
+ }
1147
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_queueUpdate).call(this, update, channelId, true);
1148
+ }, _Client_queueUpdate = function _Client_queueUpdate(update, boxId, pts) {
1149
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_getHandleUpdateQueue).call(this, boxId).add(async () => {
1150
+ if (__classPrivateFieldGet(this, _Client_guaranteeUpdateDelivery, "f") && pts) {
1151
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleStoredUpdates).call(this, boxId);
1152
+ }
1153
+ else {
1154
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleUpdate).call(this, update);
1155
+ }
1113
1156
  });
1114
- }, _Client_queueChannelUpdate = function _Client_queueChannelUpdate(update, checkGap) {
1157
+ }, _Client_processChannelPtsUpdate = function _Client_processChannelPtsUpdate(update, checkGap) {
1115
1158
  const channelId = update instanceof _2_tl_js_1.types.UpdateNewChannelMessage || update instanceof _2_tl_js_1.types.UpdateEditChannelMessage ? update.message.peer_id[_2_tl_js_1.as](_2_tl_js_1.types.PeerChannel).channel_id : update.channel_id;
1116
1159
  let queue = __classPrivateFieldGet(this, _Client_channelUpdateQueues, "f").get(channelId);
1117
1160
  if (queue == undefined) {
@@ -1119,9 +1162,9 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1119
1162
  __classPrivateFieldGet(this, _Client_channelUpdateQueues, "f").set(channelId, queue);
1120
1163
  }
1121
1164
  queue.add(async () => {
1122
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChannelUpdate).call(this, update, checkGap);
1165
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChannelPtsUpdateInner).call(this, update, checkGap);
1123
1166
  });
1124
- }, _Client_handlePtsUpdate = async function _Client_handlePtsUpdate(update, checkGap) {
1167
+ }, _Client_processPtsUpdateInner = async function _Client_processPtsUpdateInner(update, checkGap) {
1125
1168
  const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
1126
1169
  if (update.pts != 0) {
1127
1170
  if (checkGap) {
@@ -1131,15 +1174,19 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1131
1174
  return;
1132
1175
  }
1133
1176
  }
1134
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdatePts).call(this, update.pts);
1135
- __classPrivateFieldGet(this, _Client_handleUpdateQueue, "f").add(async () => {
1136
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleUpdate).call(this, update);
1137
- });
1138
- }, _Client_queuePtsUpdate = function _Client_queuePtsUpdate(update, checkGap) {
1177
+ if (__classPrivateFieldGet(this, _Client_guaranteeUpdateDelivery, "f")) {
1178
+ await this.storage.setUpdate(__classPrivateFieldGet(this, _Client_mainBoxId, "f"), update);
1179
+ }
1180
+ console.log("set pts to", update.pts, "from", update);
1181
+ if (update.pts != 0) {
1182
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdatePts).call(this, update.pts);
1183
+ }
1184
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_queueUpdate).call(this, update, 0n, true);
1185
+ }, _Client_processPtsUpdate = function _Client_processPtsUpdate(update, checkGap) {
1139
1186
  __classPrivateFieldGet(this, _Client_ptsUpdateQueue, "f").add(async () => {
1140
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handlePtsUpdate).call(this, update, checkGap);
1187
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processPtsUpdateInner).call(this, update, checkGap);
1141
1188
  });
1142
- }, _Client_processUpdates = async function _Client_processUpdates(updates_, checkGap) {
1189
+ }, _Client_processUpdates = async function _Client_processUpdates(updates_, checkGap, call = null) {
1143
1190
  __classPrivateFieldSet(this, _Client_lastUpdates, new Date(), "f");
1144
1191
  /// First, individual updates (Update[1]) are extracted from Updates.[2]
1145
1192
  ///
@@ -1231,6 +1278,30 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1231
1278
  }),
1232
1279
  ];
1233
1280
  }
1281
+ else if (updates_ instanceof _2_tl_js_1.types.UpdateShortSentMessage) {
1282
+ if (!(call instanceof _2_tl_js_1.functions.messages.sendMessage)) {
1283
+ (0, _1_utilities_js_1.UNREACHABLE)();
1284
+ }
1285
+ updates = [
1286
+ new _2_tl_js_1.types.UpdateNewMessage({
1287
+ message: new _2_tl_js_1.types.Message({
1288
+ out: updates_.out,
1289
+ silent: call.silent,
1290
+ id: updates_.id,
1291
+ from_id: new _2_tl_js_1.types.PeerUser({ user_id: await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getSelfId).call(this).then(BigInt) }),
1292
+ peer_id: (0, _2_tl_js_1.inputPeerToPeer)(call.peer),
1293
+ message: call.message,
1294
+ media: updates_.media,
1295
+ date: updates_.date,
1296
+ // reply_to: call.reply_to, // TODO?
1297
+ entities: updates_.entities,
1298
+ ttl_period: updates_.ttl_period,
1299
+ }),
1300
+ pts: updates_.pts,
1301
+ pts_count: updates_.pts_count,
1302
+ }),
1303
+ ];
1304
+ }
1234
1305
  else if (updates_ instanceof _2_tl_js_1.types.UpdatesTooLong) {
1235
1306
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverUpdateGap).call(this, "updatesTooLong");
1236
1307
  return;
@@ -1264,15 +1335,13 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1264
1335
  }
1265
1336
  }
1266
1337
  else if ((0, _0_utilities_js_1.isPtsUpdate)(update)) {
1267
- __classPrivateFieldGet(this, _Client_instances, "m", _Client_queuePtsUpdate).call(this, update, checkGap);
1338
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_processPtsUpdate).call(this, update, checkGap);
1268
1339
  }
1269
1340
  else if ((0, _0_utilities_js_1.isChannelPtsUpdate)(update)) {
1270
- __classPrivateFieldGet(this, _Client_instances, "m", _Client_queueChannelUpdate).call(this, update, checkGap);
1341
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChannelPtsUpdate).call(this, update, checkGap);
1271
1342
  }
1272
1343
  else {
1273
- __classPrivateFieldGet(this, _Client_handleUpdateQueue, "f").add(async () => {
1274
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleUpdate).call(this, update);
1275
- });
1344
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_queueUpdate).call(this, update, 0n, false);
1276
1345
  }
1277
1346
  }
1278
1347
  }, _Client_setUpdateStateDate = async function _Client_setUpdateStateDate(date) {
@@ -1603,7 +1672,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1603
1672
  }
1604
1673
  }
1605
1674
  }
1606
- else if (updates instanceof _2_tl_js_1.types.UpdateShortSentMessage || updates instanceof _2_tl_js_1.types.UpdateShortSentMessage) {
1675
+ else if (updates instanceof _2_tl_js_1.types.UpdateShortSentMessage) {
1607
1676
  const message = await this.getMessage(chatId, updates.id);
1608
1677
  if (message != null) {
1609
1678
  messages.push(message);
@@ -2145,13 +2214,13 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
2145
2214
  });
2146
2215
  }
2147
2216
  use(...middleware) {
2148
- const composer = new _4_composer_js_1.Composer(...middleware);
2149
- __classPrivateFieldSet(this, _Client_handle, (0, _4_composer_js_1.concat)(__classPrivateFieldGet(this, _Client_handle, "f"), (0, _4_composer_js_1.flatten)(composer)), "f");
2217
+ const composer = new _1_composer_js_1.Composer(...middleware);
2218
+ __classPrivateFieldSet(this, _Client_handle, (0, _1_composer_js_1.concat)(__classPrivateFieldGet(this, _Client_handle, "f"), (0, _1_composer_js_1.flatten)(composer)), "f");
2150
2219
  return composer;
2151
2220
  }
2152
2221
  branch(predicate, trueHandler_, falseHandler_) {
2153
- const trueHandler = (0, _4_composer_js_1.flatten)(trueHandler_);
2154
- const falseHandler = (0, _4_composer_js_1.flatten)(falseHandler_);
2222
+ const trueHandler = (0, _1_composer_js_1.flatten)(trueHandler_);
2223
+ const falseHandler = (0, _1_composer_js_1.flatten)(falseHandler_);
2155
2224
  return this.use(async (upd, next) => {
2156
2225
  if (await predicate(upd)) {
2157
2226
  await trueHandler(upd, next);
@@ -2162,8 +2231,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
2162
2231
  });
2163
2232
  }
2164
2233
  filter(predicate, ...middleware) {
2165
- const composer = new _4_composer_js_1.Composer(...middleware);
2166
- this.branch(predicate, composer, _4_composer_js_1.skip);
2234
+ const composer = new _1_composer_js_1.Composer(...middleware);
2235
+ this.branch(predicate, composer, _1_composer_js_1.skip);
2167
2236
  return composer;
2168
2237
  }
2169
2238
  on(filter, ...middleawre) {
@@ -2195,7 +2264,6 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
2195
2264
  else {
2196
2265
  return false;
2197
2266
  }
2198
- // deno-lint-ignore no-explicit-any
2199
2267
  }, ...middleawre);
2200
2268
  }
2201
2269
  command(commands, ...middleawre) {
@@ -2246,27 +2314,27 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
2246
2314
  *
2247
2315
  * @method
2248
2316
  */
2249
- async setMyDescription({ description, languageCode }) {
2317
+ async setMyDescription(params) {
2250
2318
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "setMyDescription");
2251
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { description, lang_code: languageCode ?? "" });
2319
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { description: params?.description, lang_code: params?.languageCode ?? "" });
2252
2320
  }
2253
2321
  /**
2254
2322
  * Set the bot's name in the given language. Bot-only.
2255
2323
  *
2256
2324
  * @method
2257
2325
  */
2258
- async setMyName({ name, languageCode }) {
2326
+ async setMyName(params) {
2259
2327
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "setMyName");
2260
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { name, lang_code: languageCode ?? "" });
2328
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { name: params?.name, lang_code: params?.languageCode ?? "" });
2261
2329
  }
2262
2330
  /**
2263
2331
  * Set the bot's short description in the given language. Bot-only.
2264
2332
  *
2265
2333
  * @method
2266
2334
  */
2267
- async setMyShortDescription({ shortDescription: about, languageCode }) {
2335
+ async setMyShortDescription(params) {
2268
2336
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "setMyShortDescription");
2269
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { about, lang_code: languageCode ?? "" });
2337
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { about: params?.shortDescription, lang_code: params?.languageCode ?? "" });
2270
2338
  }
2271
2339
  /**
2272
2340
  * Get the bot's description in the given language. Bot-only.
@@ -2641,7 +2709,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
2641
2709
  if (limit <= 0 || limit > 100) {
2642
2710
  limit = 100;
2643
2711
  }
2644
- const listId = (0, _3_types_js_2.getChatListId)(params?.from ?? "main");
2712
+ const listId = (0, _0_utilities_js_1.getChatListId)(params?.from ?? "main");
2645
2713
  let chats = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLoadedChats).call(this, listId);
2646
2714
  if (params?.after) {
2647
2715
  chats = chats
@@ -2838,21 +2906,48 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
2838
2906
  });
2839
2907
  }
2840
2908
  /**
2841
- * Add a reaction to a message.
2909
+ * Change reactions made to a message.
2910
+ *
2911
+ * @param chatId The identifier of the chat which the message belongs to.
2912
+ * @param messageId The identifier of the message to add the reaction to.
2913
+ * @param reactions The new reactions.
2914
+ */
2915
+ async setReactions(chatId, messageId, reactions, params) {
2916
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendReaction).call(this, chatId, messageId, reactions, params);
2917
+ }
2918
+ /**
2919
+ * Make a reaction to a message.
2842
2920
  *
2843
2921
  * @param chatId The identifier of the chat which the message belongs to.
2844
2922
  * @param messageId The identifier of the message to add the reaction to.
2845
2923
  * @param reaction The reaction to add.
2846
2924
  */
2847
2925
  async addReaction(chatId, messageId, reaction, params) {
2848
- // TODO: check storage and skip if already there
2849
- await this.api.messages.sendReaction({
2850
- peer: await this.getInputPeer(chatId),
2851
- msg_id: messageId,
2852
- reaction: [(0, _3_types_js_1.reactionToTlObject)(reaction)],
2853
- big: params?.big ? true : undefined,
2854
- add_to_recent: params?.addToRecents ? true : undefined,
2855
- });
2926
+ const chosenReactions = await this.getMessage(chatId, messageId).then((v) => v?.reactions ?? []).then((v) => v.filter((v) => v.chosen));
2927
+ for (const r of chosenReactions) {
2928
+ if ((0, _3_types_js_1.reactionEqual)(r.reaction, reaction)) {
2929
+ return;
2930
+ }
2931
+ }
2932
+ const reactions = [reaction, ...chosenReactions.map((v) => v.reaction)];
2933
+ await this.setReactions(chatId, messageId, reactions, params);
2934
+ }
2935
+ /**
2936
+ * Undo a reaction made to a message.
2937
+ *
2938
+ * @param chatId The identifier of the chat which the message belongs to.
2939
+ * @param messageId The identifier of the message which the reaction was made to.
2940
+ * @param reaction The reaction to remove.
2941
+ */
2942
+ async removeReaction(chatId, messageId, reaction) {
2943
+ const chosenReactions = await this.getMessage(chatId, messageId).then((v) => v?.reactions ?? []).then((v) => v.filter((v) => v.chosen));
2944
+ for (const r of chosenReactions) {
2945
+ if ((0, _3_types_js_1.reactionEqual)(r.reaction, reaction)) {
2946
+ const reactions = chosenReactions.filter((v) => v != r).map((v) => v.reaction);
2947
+ await this.setReactions(chatId, messageId, reactions);
2948
+ break;
2949
+ }
2950
+ }
2856
2951
  }
2857
2952
  }
2858
2953
  exports.Client = Client;
@@ -2865,9 +2960,40 @@ _a = Client, _Client_getMe = async function _Client_getMe() {
2865
2960
  __classPrivateFieldSet(this, _Client_lastGetMe, user, "f");
2866
2961
  return user;
2867
2962
  }
2868
- }, _Client_handleUpdate =
2869
- // TODO: log errors
2870
- async function _Client_handleUpdate(update) {
2963
+ }, _Client_handleStoredUpdates = async function _Client_handleStoredUpdates(boxId) {
2964
+ if (__classPrivateFieldGet(this, _Client_handleUpdatesSet, "f").has(boxId)) {
2965
+ return;
2966
+ }
2967
+ __classPrivateFieldGet(this, _Client_handleUpdatesSet, "f").add(boxId);
2968
+ do {
2969
+ const maybeUpdate = await this.storage.getFirstUpdate(boxId);
2970
+ if (maybeUpdate == null) {
2971
+ break;
2972
+ }
2973
+ const [key, update] = maybeUpdate;
2974
+ for (let i = 0; i < 100; ++i) {
2975
+ try {
2976
+ const handle = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleUpdate).call(this, update);
2977
+ handle: for (let i = 0; i < 2; ++i) {
2978
+ try {
2979
+ await handle();
2980
+ break handle;
2981
+ }
2982
+ catch {
2983
+ continue handle;
2984
+ }
2985
+ }
2986
+ break;
2987
+ }
2988
+ catch (err) {
2989
+ d("#handleUpdate error: %o", err);
2990
+ }
2991
+ }
2992
+ await this.storage.set(key, null);
2993
+ } while (true);
2994
+ __classPrivateFieldGet(this, _Client_handleUpdatesSet, "f").delete(boxId);
2995
+ }, _Client_handleUpdate = async function _Client_handleUpdate(update) {
2996
+ const promises = new Array();
2871
2997
  if (update instanceof _2_tl_js_1.types.UpdateUserName) {
2872
2998
  await this.storage.updateUsernames("user", update.user_id, update.usernames.map((v) => v.username));
2873
2999
  const peer = new _2_tl_js_1.types.PeerUser(update);
@@ -2883,7 +3009,7 @@ async function _Client_handleUpdate(update) {
2883
3009
  if (update.message instanceof _2_tl_js_1.types.Message || update.message instanceof _2_tl_js_1.types.MessageService) {
2884
3010
  const chatId = (0, _2_tl_js_1.peerToChatId)(update.message.peer_id);
2885
3011
  await this.storage.setMessage(chatId, update.message.id, update.message);
2886
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId);
3012
+ promises.push((await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId))());
2887
3013
  }
2888
3014
  }
2889
3015
  if (update instanceof _2_tl_js_1.types.UpdateMessageReactions) {
@@ -2892,16 +3018,34 @@ async function _Client_handleUpdate(update) {
2892
3018
  if (message instanceof _2_tl_js_1.types.Message) {
2893
3019
  message.reactions = update.reactions;
2894
3020
  await this.storage.setMessage(chatId, update.msg_id, message);
3021
+ const views = message.views ?? 0;
3022
+ const forwards = message.forwards ?? 0;
3023
+ const recentReactions = update.reactions.recent_reactions ?? [];
3024
+ const reactions = update.reactions.results.map((v) => (0, _3_types_js_1.constructMessageReaction)(v, recentReactions));
3025
+ 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 } }), _0_utilities_js_1.resolve))());
3026
+ }
3027
+ }
3028
+ else if (update instanceof _2_tl_js_1.types.UpdateChannelMessageViews || update instanceof _2_tl_js_1.types.UpdateChannelMessageForwards) {
3029
+ const chatId = (0, _2_tl_js_1.peerToChatId)(new _2_tl_js_1.types.PeerChannel(update));
3030
+ const message = await this.storage.getMessage(chatId, update.id);
3031
+ if (message instanceof _2_tl_js_1.types.Message) {
3032
+ if ("views" in update) {
3033
+ message.views = update.views;
3034
+ }
3035
+ if ("forwards" in update) {
3036
+ message.forwards = update.forwards;
3037
+ }
3038
+ const views = message.views ?? 0;
3039
+ const forwards = message.forwards ?? 0;
3040
+ const recentReactions = message.reactions?.recent_reactions ?? [];
3041
+ const reactions = message.reactions?.results.map((v) => (0, _3_types_js_1.constructMessageReaction)(v, recentReactions)) ?? [];
3042
+ 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 } }), _0_utilities_js_1.resolve))());
2895
3043
  }
2896
- const recentReactions = update.reactions.recent_reactions ?? [];
2897
- const reactions = update.reactions.results.map((v) => (0, _3_types_js_1.constructMessageReaction)(v, recentReactions));
2898
- await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { reactions: { chatId, messageId: update.msg_id, reactions } }), _0_utilities_js_1.resolve);
2899
3044
  }
2900
3045
  if (update instanceof _2_tl_js_1.types.UpdateNewMessage ||
2901
3046
  update instanceof _2_tl_js_1.types.UpdateNewChannelMessage ||
2902
3047
  update instanceof _2_tl_js_1.types.UpdateEditMessage ||
2903
3048
  update instanceof _2_tl_js_1.types.UpdateEditChannelMessage) {
2904
- const key = update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateNewChannelMessage ? "message" : "editedMessage";
2905
3049
  if (!(update.message instanceof _2_tl_js_1.types.MessageEmpty)) {
2906
3050
  const isOutgoing = update.message.out;
2907
3051
  let shouldIgnore = isOutgoing ? (await this.storage.getAccountType()) == "user" ? false : true : false;
@@ -2910,7 +3054,16 @@ async function _Client_handleUpdate(update) {
2910
3054
  }
2911
3055
  if (!shouldIgnore) {
2912
3056
  const message = await (0, _3_types_js_1.constructMessage)(update.message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this));
2913
- await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { [key]: message }), _0_utilities_js_1.resolve);
3057
+ promises.push((async () => {
3058
+ let context;
3059
+ if (update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateNewChannelMessage) {
3060
+ context = await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { message });
3061
+ }
3062
+ else {
3063
+ context = await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { editedMessage: message });
3064
+ }
3065
+ await __classPrivateFieldGet(this, _Client_handle, "f").call(this, context, _0_utilities_js_1.resolve);
3066
+ })());
2914
3067
  }
2915
3068
  }
2916
3069
  }
@@ -2919,16 +3072,21 @@ async function _Client_handleUpdate(update) {
2919
3072
  for (const messageId of update.messages) {
2920
3073
  const chatId = await this.storage.getMessageChat(messageId);
2921
3074
  if (chatId) {
2922
- const message = await this.storage.getMessage(chatId, messageId);
2923
- if (message != null && !(message instanceof _2_tl_js_1.types.MessageEmpty)) {
2924
- deletedMessages.push(await (0, _3_types_js_1.constructMessage)(message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this)));
2925
- }
2926
- await this.storage.setMessage(chatId, messageId, null);
2927
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId);
3075
+ deletedMessages.push({ chatId, messageId });
2928
3076
  }
2929
3077
  }
2930
3078
  if (deletedMessages.length > 0) {
2931
- await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { deletedMessages: deletedMessages }), _0_utilities_js_1.resolve);
3079
+ promises.push((async () => {
3080
+ try {
3081
+ await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { deletedMessages }), _0_utilities_js_1.resolve);
3082
+ }
3083
+ finally {
3084
+ for (const { chatId, messageId } of deletedMessages) {
3085
+ await this.storage.setMessage(chatId, messageId, null);
3086
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId);
3087
+ }
3088
+ }
3089
+ })());
2932
3090
  }
2933
3091
  }
2934
3092
  else if (update instanceof _2_tl_js_1.types.UpdateDeleteChannelMessages) {
@@ -2936,24 +3094,43 @@ async function _Client_handleUpdate(update) {
2936
3094
  const deletedMessages = new Array();
2937
3095
  for (const messageId of update.messages) {
2938
3096
  const message = await this.storage.getMessage(chatId, messageId);
2939
- if (message != null && !(message instanceof _2_tl_js_1.types.MessageEmpty)) {
2940
- deletedMessages.push(await (0, _3_types_js_1.constructMessage)(message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this)));
3097
+ if (message != null) {
3098
+ deletedMessages.push({ chatId, messageId });
2941
3099
  }
2942
- await this.storage.setMessage(chatId, messageId, null);
2943
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId);
2944
3100
  }
2945
3101
  if (deletedMessages.length > 0) {
2946
- await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { deletedMessages: deletedMessages }), _0_utilities_js_1.resolve);
3102
+ promises.push((async () => {
3103
+ try {
3104
+ await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { deletedMessages }), _0_utilities_js_1.resolve);
3105
+ }
3106
+ finally {
3107
+ for (const { chatId, messageId } of deletedMessages) {
3108
+ await this.storage.setMessage(chatId, messageId, null);
3109
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId);
3110
+ }
3111
+ }
3112
+ })());
2947
3113
  }
2948
3114
  }
2949
3115
  if (update instanceof _2_tl_js_1.types.UpdateBotCallbackQuery || update instanceof _2_tl_js_1.types.UpdateInlineBotCallbackQuery) {
2950
- await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { callbackQuery: await (0, _3_types_js_1.constructCallbackQuery)(update, this[getEntity].bind(this), this[getMessageWithReply].bind(this)) }), _0_utilities_js_1.resolve);
3116
+ promises.push((async () => __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { callbackQuery: await (0, _3_types_js_1.constructCallbackQuery)(update, this[getEntity].bind(this), this[getMessageWithReply].bind(this)) }), _0_utilities_js_1.resolve))());
2951
3117
  }
2952
3118
  else if (update instanceof _2_tl_js_1.types.UpdateBotInlineQuery) {
2953
- await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { inlineQuery: await (0, _3_types_js_1.constructInlineQuery)(update, this[getEntity].bind(this)) }), _0_utilities_js_1.resolve);
3119
+ promises.push((async () => __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { inlineQuery: await (0, _3_types_js_1.constructInlineQuery)(update, this[getEntity].bind(this)) }), _0_utilities_js_1.resolve))());
2954
3120
  }
2955
3121
  else if (update instanceof _2_tl_js_1.types.UpdateBotInlineSend) {
2956
- await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { chosenInlineResult: await (0, _3_types_js_1.constructChosenInlineResult)(update, this[getEntity].bind(this)) }), _0_utilities_js_1.resolve);
3122
+ promises.push((async () => __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { chosenInlineResult: await (0, _3_types_js_1.constructChosenInlineResult)(update, this[getEntity].bind(this)) }), _0_utilities_js_1.resolve))());
3123
+ }
3124
+ else if (update instanceof _2_tl_js_1.types.UpdateBotMessageReactions) {
3125
+ const date = new Date(update.date * 1000);
3126
+ const reactions = update.reactions.map((v) => (0, _3_types_js_1.constructReactionCount)(v));
3127
+ const entity = await this[getEntity](update.peer);
3128
+ if (entity) {
3129
+ const chat = (0, _3_types_js_1.constructChatP)(entity);
3130
+ const messageId = update.msg_id;
3131
+ const messageReactionCount = { chat, messageId, date, reactions };
3132
+ promises.push((async () => __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { messageReactionCount }), _0_utilities_js_1.resolve))());
3133
+ }
2957
3134
  }
2958
3135
  if (update instanceof _2_tl_js_1.types.UpdatePinnedDialogs) {
2959
3136
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatePinnedChats).call(this, update);
@@ -2991,6 +3168,7 @@ async function _Client_handleUpdate(update) {
2991
3168
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updateOrAddChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
2992
3169
  }
2993
3170
  }
3171
+ return () => Promise.all(promises);
2994
3172
  }, _Client_constructReplyMarkup = async function _Client_constructReplyMarkup(params) {
2995
3173
  if (params?.replyMarkup) {
2996
3174
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "replyMarkup");
@@ -3097,7 +3275,7 @@ async function _Client_setMyInfo(info) {
3097
3275
  }
3098
3276
  const [chat] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
3099
3277
  const update = chat === undefined ? { deletedChat: { chatId } } : added ? { newChat: chat } : { editedChat: chat };
3100
- __classPrivateFieldGet(this, _Client_handleUpdateQueue, "f").add(async () => {
3278
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_getHandleUpdateQueue).call(this, __classPrivateFieldGet(this, _Client_mainBoxId, "f")).add(async () => {
3101
3279
  await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, update), _0_utilities_js_1.resolve);
3102
3280
  });
3103
3281
  }, _Client_reassignChatLastMessage = async function _Client_reassignChatLastMessage(chatId, add = false, sendUpdate = true) {
@@ -3105,11 +3283,11 @@ async function _Client_setMyInfo(info) {
3105
3283
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertUser).call(this, "");
3106
3284
  }
3107
3285
  catch {
3108
- return;
3286
+ return () => Promise.resolve();
3109
3287
  }
3110
3288
  const [chat, listId] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
3111
3289
  if (!chat && !add) {
3112
- return;
3290
+ return () => Promise.resolve();
3113
3291
  }
3114
3292
  const message_ = await this.storage.getLastMessage(chatId);
3115
3293
  if (message_ != null) {
@@ -3129,9 +3307,9 @@ async function _Client_setMyInfo(info) {
3129
3307
  await this.storage.setChat(listId, chatId, chat.pinned, chat.lastMessage?.id ?? 0, chat.lastMessage?.date ?? new Date(0));
3130
3308
  }
3131
3309
  if (sendUpdate) {
3132
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
3310
+ return () => __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
3133
3311
  }
3134
- return;
3312
+ return () => Promise.resolve();
3135
3313
  }
3136
3314
  const message = await this.getHistory(chatId, { limit: 1 }).then((v) => v[0]);
3137
3315
  if (message !== undefined) {
@@ -3149,17 +3327,18 @@ async function _Client_setMyInfo(info) {
3149
3327
  __classPrivateFieldGet(this, _Client_chats, "f").set(chatId, chat);
3150
3328
  }
3151
3329
  if (sendUpdate) {
3152
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
3330
+ return () => __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
3153
3331
  }
3154
- return;
3332
+ return () => Promise.resolve();
3155
3333
  }
3156
3334
  if (chat) {
3157
3335
  chat.order = (0, _3_types_js_1.getChatOrder)(undefined, chat.pinned);
3158
3336
  chat.lastMessage = undefined;
3159
3337
  if (sendUpdate) {
3160
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
3338
+ return () => __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
3161
3339
  }
3162
3340
  }
3341
+ return () => Promise.resolve();
3163
3342
  }, _Client_tryGetChatId = function _Client_tryGetChatId(username) {
3164
3343
  username = username.toLowerCase();
3165
3344
  for (const chat of __classPrivateFieldGet(this, _Client_chats, "f").values()) {
@@ -3334,4 +3513,12 @@ async function _Client_setMyInfo(info) {
3334
3513
  chats.set(chat.id, chat);
3335
3514
  await this.storage.setChat(listId, chat.id, chat.pinned, chat.lastMessage?.id ?? 0, chat.lastMessage?.date ?? new Date(0));
3336
3515
  }
3516
+ }, _Client_sendReaction = async function _Client_sendReaction(chatId, messageId, reactions, params) {
3517
+ await this.api.messages.sendReaction({
3518
+ peer: await this.getInputPeer(chatId),
3519
+ msg_id: messageId,
3520
+ reaction: reactions.map((v) => (0, _3_types_js_1.reactionToTlObject)(v)),
3521
+ big: params?.big ? true : undefined,
3522
+ add_to_recent: params?.addToRecents ? true : undefined,
3523
+ });
3337
3524
  };