@mtkruto/node 0.1.139 → 0.1.140

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