@mtkruto/node 0.1.138 → 0.1.140

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 -1699
  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 -1699
  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,409 +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
- console.log("set pts to", update.pts, "from", update);
1181
- if (update.pts != 0) {
1182
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdatePts).call(this, update.pts);
1183
- }
1184
- __classPrivateFieldGet(this, _Client_instances, "m", _Client_queueUpdate).call(this, update, 0n, true);
1185
- }, _Client_processPtsUpdate = function _Client_processPtsUpdate(update, checkGap) {
1186
- __classPrivateFieldGet(this, _Client_ptsUpdateQueue, "f").add(async () => {
1187
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processPtsUpdateInner).call(this, update, checkGap);
1188
- });
1189
- }, _Client_processUpdates = async function _Client_processUpdates(updates_, checkGap, call = null) {
1190
- __classPrivateFieldSet(this, _Client_lastUpdates, new Date(), "f");
1191
- /// First, individual updates (Update[1]) are extracted from Updates.[2]
1192
- ///
1193
- /// If an updatesTooLong[3] was received, an update gap recovery is initiated and no further action will be taken.
1194
- ///
1195
- /// [1]: https://core.telegram.org/type/Update
1196
- /// [2]: https://core.telegram.org/type/Updates
1197
- /// [3]: https://core.telegram.org/constructor/updatesTooLong
1198
- let updates;
1199
- if (updates_ instanceof _2_tl_js_1.types.UpdatesCombined || updates_ instanceof _2_tl_js_1.types.Updates) {
1200
- updates = updates_.updates;
1201
- const seq = updates_.seq;
1202
- const seqStart = "seq_start" in updates_ ? updates_.seq_start : updates_.seq;
1203
- if (checkGap) {
1204
- if (seqStart == 0) {
1205
- checkGap = false;
1206
- d("seqStart=0");
1207
- }
1208
- else {
1209
- const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
1210
- const localSeq = localState.seq;
1211
- if (localSeq + 1 == seqStart) {
1212
- // The update sequence can be applied.
1213
- localState.seq = seq;
1214
- localState.date = updates_.date;
1215
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdateStateDate).call(this, updates_.date);
1216
- await this.storage.setState(localState);
1217
- }
1218
- else if (localSeq + 1 > seqStart) {
1219
- // The update sequence was already applied, and must be ignored.
1220
- d("localSeq + 1 > seqStart");
1221
- return;
1222
- }
1223
- else if (localSeq + 1 < seqStart) {
1224
- // There's an updates gap that must be filled.
1225
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverUpdateGap).call(this, "localSeq + 1 < seqStart");
1226
- }
1227
- }
1228
- }
1229
- }
1230
- else if (updates_ instanceof _2_tl_js_1.types.UpdateShort) {
1231
- updates = [updates_.update];
1232
- }
1233
- else if (updates_ instanceof _2_tl_js_1.types.UpdateShortMessage) {
1234
- updates = [
1235
- new _2_tl_js_1.types.UpdateNewMessage({
1236
- message: new _2_tl_js_1.types.Message({
1237
- out: updates_.out,
1238
- mentioned: updates_.mentioned,
1239
- media_unread: updates_.media_unread,
1240
- silent: updates_.silent,
1241
- id: updates_.id,
1242
- 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 }),
1243
- peer_id: new _2_tl_js_1.types.PeerUser({ user_id: updates_.user_id }),
1244
- message: updates_.message,
1245
- date: updates_.date,
1246
- fwd_from: updates_.fwd_from,
1247
- via_bot_id: updates_.via_bot_id,
1248
- reply_to: updates_.reply_to,
1249
- entities: updates_.entities,
1250
- ttl_period: updates_.ttl_period,
1251
- }),
1252
- pts: updates_.pts,
1253
- pts_count: updates_.pts_count,
1254
- }),
1255
- ];
1256
- }
1257
- else if (updates_ instanceof _2_tl_js_1.types.UpdateShortChatMessage) {
1258
- updates = [
1259
- new _2_tl_js_1.types.UpdateNewMessage({
1260
- message: new _2_tl_js_1.types.Message({
1261
- out: updates_.out,
1262
- mentioned: updates_.mentioned,
1263
- media_unread: updates_.media_unread,
1264
- silent: updates_.silent,
1265
- id: updates_.id,
1266
- from_id: new _2_tl_js_1.types.PeerUser({ user_id: updates_.from_id }),
1267
- peer_id: new _2_tl_js_1.types.PeerChat({ chat_id: updates_.chat_id }),
1268
- fwd_from: updates_.fwd_from,
1269
- via_bot_id: updates_.via_bot_id,
1270
- reply_to: updates_.reply_to,
1271
- date: updates_.date,
1272
- message: updates_.message,
1273
- entities: updates_.entities,
1274
- ttl_period: updates_.ttl_period,
1275
- }),
1276
- pts: updates_.pts,
1277
- pts_count: updates_.pts_count,
1278
- }),
1279
- ];
1280
- }
1281
- else if (updates_ instanceof _2_tl_js_1.types.UpdateShortSentMessage) {
1282
- if (!(call instanceof _2_tl_js_1.functions.messages.sendMessage)) {
1283
- (0, _1_utilities_js_1.UNREACHABLE)();
1284
- }
1285
- updates = [
1286
- new _2_tl_js_1.types.UpdateNewMessage({
1287
- message: new _2_tl_js_1.types.Message({
1288
- out: updates_.out,
1289
- silent: call.silent,
1290
- id: updates_.id,
1291
- from_id: new _2_tl_js_1.types.PeerUser({ user_id: await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getSelfId).call(this).then(BigInt) }),
1292
- peer_id: (0, _2_tl_js_1.inputPeerToPeer)(call.peer),
1293
- message: call.message,
1294
- media: updates_.media,
1295
- date: updates_.date,
1296
- // reply_to: call.reply_to, // TODO?
1297
- entities: updates_.entities,
1298
- ttl_period: updates_.ttl_period,
1299
- }),
1300
- pts: updates_.pts,
1301
- pts_count: updates_.pts_count,
1302
- }),
1303
- ];
1304
- }
1305
- else if (updates_ instanceof _2_tl_js_1.types.UpdatesTooLong) {
1306
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverUpdateGap).call(this, "updatesTooLong");
1307
- return;
1308
- }
1309
- else if (updates_ instanceof _2_tl_js_1.types._Update) {
1310
- updates = [updates_];
1311
- }
1312
- else {
1313
- (0, _1_utilities_js_1.UNREACHABLE)();
1314
- }
1315
- /// We process the updates when we are sure there is no gap.
1316
- if (updates_ instanceof _2_tl_js_1.types.Updates || updates_ instanceof _2_tl_js_1.types.UpdatesCombined) {
1317
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, updates_.chats);
1318
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, updates_.users);
1319
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdateStateDate).call(this, updates_.date);
1320
- }
1321
- else if (updates_ instanceof _2_tl_js_1.types.UpdateShort ||
1322
- updates_ instanceof _2_tl_js_1.types.UpdateShortMessage ||
1323
- updates_ instanceof _2_tl_js_1.types.UpdateShortChatMessage ||
1324
- updates_ instanceof _2_tl_js_1.types.UpdateShortSentMessage) {
1325
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdateStateDate).call(this, updates_.date);
1326
- }
1327
- for (const update of updates) {
1328
- if (update instanceof _2_tl_js_1.types.UpdatePtsChanged) {
1329
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchState).call(this, "updatePtsChanged");
1330
- if (__classPrivateFieldGet(this, _Client_updateState, "f")) {
1331
- await this.storage.setState(__classPrivateFieldGet(this, _Client_updateState, "f"));
1332
- }
1333
- else {
1334
- (0, _1_utilities_js_1.UNREACHABLE)();
1335
- }
1336
- }
1337
- else if ((0, _0_utilities_js_1.isPtsUpdate)(update)) {
1338
- __classPrivateFieldGet(this, _Client_instances, "m", _Client_processPtsUpdate).call(this, update, checkGap);
1339
- }
1340
- else if ((0, _0_utilities_js_1.isChannelPtsUpdate)(update)) {
1341
- __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChannelPtsUpdate).call(this, update, checkGap);
1342
- }
1343
- else {
1344
- __classPrivateFieldGet(this, _Client_instances, "m", _Client_queueUpdate).call(this, update, 0n, false);
1345
- }
1346
- }
1347
- }, _Client_setUpdateStateDate = async function _Client_setUpdateStateDate(date) {
1348
- const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
1349
- localState.date = date;
1350
- await this.storage.setState(localState);
1351
- }, _Client_setUpdatePts = async function _Client_setUpdatePts(pts) {
1352
- const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
1353
- localState.pts = pts;
1354
- await this.storage.setState(localState);
1355
- }, _Client_getLocalState = async function _Client_getLocalState() {
1356
- let localState = await this.storage.getState();
1357
- if (!localState) {
1358
- if (__classPrivateFieldGet(this, _Client_updateState, "f")) {
1359
- localState = __classPrivateFieldGet(this, _Client_updateState, "f");
1360
- await this.storage.setState(localState);
1361
- }
1362
- else {
1363
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchState).call(this, "getLocalState");
1364
- if (__classPrivateFieldGet(this, _Client_updateState, "f")) {
1365
- localState = __classPrivateFieldGet(this, _Client_updateState, "f");
1366
- await this.storage.setState(localState);
1367
- }
1368
- else {
1369
- (0, _1_utilities_js_1.UNREACHABLE)();
1370
- }
1371
- }
1372
- }
1373
- return localState;
1374
- }, _Client_recoverUpdateGap = async function _Client_recoverUpdateGap(source) {
1375
- dGap("recovering from update gap [%s]", source);
1376
- __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateConnectionState).call(this, "updating");
1377
- try {
1378
- let state = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
1379
- while (true) {
1380
- const difference = await this.api.updates.getDifference({ pts: state.pts, date: state.date, qts: state.qts ?? 0 });
1381
- if (difference instanceof _2_tl_js_1.types.updates.Difference || difference instanceof _2_tl_js_1.types.updates.DifferenceSlice) {
1382
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, difference.chats);
1383
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, difference.users);
1384
- for (const message of difference.new_messages) {
1385
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, new _2_tl_js_1.types.UpdateNewMessage({ message, pts: 0, pts_count: 0 }), false);
1386
- }
1387
- for (const update of difference.other_updates) {
1388
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, update, false);
1389
- }
1390
- if (difference instanceof _2_tl_js_1.types.updates.Difference) {
1391
- await this.storage.setState(difference.state);
1392
- dGap("recovered from update gap");
1393
- break;
1394
- }
1395
- else if (difference instanceof _2_tl_js_1.types.updates.DifferenceSlice) {
1396
- state = difference.intermediate_state;
1397
- }
1398
- else {
1399
- (0, _1_utilities_js_1.UNREACHABLE)();
1400
- }
1401
- }
1402
- else if (difference instanceof _2_tl_js_1.types.updates.DifferenceTooLong) {
1403
- await this.storage.deleteMessages();
1404
- await this.storage.removeChats(0);
1405
- await this.storage.removeChats(1);
1406
- state.pts = difference.pts;
1407
- dGap("received differenceTooLong");
1408
- }
1409
- else if (difference instanceof _2_tl_js_1.types.updates.DifferenceEmpty) {
1410
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdateStateDate).call(this, difference.date);
1411
- dGap("there was no update gap");
1412
- break;
1413
- }
1414
- else {
1415
- (0, _1_utilities_js_1.UNREACHABLE)();
1416
- }
1417
- }
1418
- }
1419
- finally {
1420
- this.stateChangeHandler(this.connected);
1421
- __classPrivateFieldSet(this, _Client_lastUpdates, new Date(), "f");
1422
- }
1423
- }, _Client_recoverChannelUpdateGap = async function _Client_recoverChannelUpdateGap(channelId, source) {
1424
- dGapC("recovering channel update gap [%o, %s]", channelId, source);
1425
- const pts_ = await this.storage.getChannelPts(channelId);
1426
- let pts = pts_ == null ? 1 : pts_;
1427
- while (true) {
1428
- 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));
1429
- const difference = await this.api.updates.getChannelDifference({
1430
- pts,
1431
- channel: new _2_tl_js_1.types.InputChannel({ channel_id: channelId, access_hash }),
1432
- filter: new _2_tl_js_1.types.ChannelMessagesFilterEmpty(),
1433
- limit: await this.storage.getAccountType() == "user" ? _4_constants_js_1.CHANNEL_DIFFERENCE_LIMIT_USER : _4_constants_js_1.CHANNEL_DIFFERENCE_LIMIT_BOT,
1434
- });
1435
- if (difference instanceof _2_tl_js_1.types.updates.ChannelDifference) {
1436
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, difference.chats);
1437
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, difference.users);
1438
- for (const message of difference.new_messages) {
1439
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, new _2_tl_js_1.types.UpdateNewChannelMessage({ message, pts: 0, pts_count: 0 }), false);
1440
- }
1441
- for (const update of difference.other_updates) {
1442
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, update, false);
1443
- }
1444
- await this.storage.setChannelPts(channelId, difference.pts);
1445
- dGapC("recovered from update gap [%o, %s]", channelId, source);
1446
- break;
1447
- }
1448
- else if (difference instanceof _2_tl_js_1.types.updates.ChannelDifferenceTooLong) {
1449
- // TODO: invalidate messages
1450
- dGapC("received channelDifferenceTooLong");
1451
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, difference.chats);
1452
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, difference.users);
1453
- for (const message of difference.messages) {
1454
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, new _2_tl_js_1.types.UpdateNewChannelMessage({ message, pts: 0, pts_count: 0 }), false);
1455
- }
1456
- const pts_ = difference.dialog[_2_tl_js_1.as](_2_tl_js_1.types.Dialog).pts;
1457
- if (pts_ != undefined) {
1458
- pts = pts_;
1459
- }
1460
- else {
1461
- (0, _1_utilities_js_1.UNREACHABLE)();
1462
- }
1463
- dGapC("processed channelDifferenceTooLong");
1464
- }
1465
- else if (difference instanceof _2_tl_js_1.types.updates.ChannelDifferenceEmpty) {
1466
- dGapC("there was no update gap");
1467
- break;
1468
- }
1469
- }
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;
1470
1169
  }, _Client_getChannelAccessHash = async function _Client_getChannelAccessHash(channelId) {
1471
1170
  const channels = await this.api.channels.getChannels({ id: [new _2_tl_js_1.types.InputChannel({ channel_id: channelId, access_hash: 0n })] });
1472
1171
  return channels.chats[0][_2_tl_js_1.as](_2_tl_js_1.types.Channel).access_hash ?? 0n;
@@ -1487,8 +1186,8 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1487
1186
  }
1488
1187
  else {
1489
1188
  const resolved = await this.api.contacts.resolveUsername({ username: id });
1490
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, resolved.chats);
1491
- 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);
1492
1191
  if (resolved.peer instanceof _2_tl_js_1.types.PeerUser) {
1493
1192
  userId = resolved.peer.user_id;
1494
1193
  }
@@ -1532,63 +1231,6 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1532
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)();
1533
1232
  return this.storage.getEntity(type, id);
1534
1233
  }
1535
- async processResult(result) {
1536
- if (result instanceof _2_tl_js_1.types.messages.Dialogs ||
1537
- result instanceof _2_tl_js_1.types.messages.DialogsSlice ||
1538
- result instanceof _2_tl_js_1.types.messages.Messages ||
1539
- result instanceof _2_tl_js_1.types.messages.MessagesSlice ||
1540
- result instanceof _2_tl_js_1.types.messages.ChannelMessages ||
1541
- result instanceof _2_tl_js_1.types.messages.ChatFull ||
1542
- result instanceof _2_tl_js_1.types.contacts.Found ||
1543
- result instanceof _2_tl_js_1.types.account.PrivacyRules ||
1544
- result instanceof _2_tl_js_1.types.contacts.ResolvedPeer ||
1545
- result instanceof _2_tl_js_1.types.channels.ChannelParticipants ||
1546
- result instanceof _2_tl_js_1.types.channels.ChannelParticipant ||
1547
- result instanceof _2_tl_js_1.types.messages.PeerDialogs ||
1548
- result instanceof _2_tl_js_1.types.contacts.TopPeers ||
1549
- result instanceof _2_tl_js_1.types.channels.AdminLogResults ||
1550
- result instanceof _2_tl_js_1.types.help.RecentMeUrls ||
1551
- result instanceof _2_tl_js_1.types.messages.InactiveChats ||
1552
- result instanceof _2_tl_js_1.types.help.PromoData ||
1553
- result instanceof _2_tl_js_1.types.messages.MessageViews ||
1554
- result instanceof _2_tl_js_1.types.messages.DiscussionMessage ||
1555
- result instanceof _2_tl_js_1.types.phone.GroupCall ||
1556
- result instanceof _2_tl_js_1.types.phone.GroupParticipants ||
1557
- result instanceof _2_tl_js_1.types.phone.JoinAsPeers ||
1558
- result instanceof _2_tl_js_1.types.messages.SponsoredMessages ||
1559
- result instanceof _2_tl_js_1.types.messages.SearchResultsCalendar ||
1560
- result instanceof _2_tl_js_1.types.channels.SendAsPeers ||
1561
- result instanceof _2_tl_js_1.types.users.UserFull ||
1562
- result instanceof _2_tl_js_1.types.messages.PeerSettings ||
1563
- result instanceof _2_tl_js_1.types.messages.MessageReactionsList ||
1564
- result instanceof _2_tl_js_1.types.messages.ForumTopics ||
1565
- result instanceof _2_tl_js_1.types.account.AutoSaveSettings ||
1566
- result instanceof _2_tl_js_1.types.chatlists.ExportedInvites ||
1567
- result instanceof _2_tl_js_1.types.chatlists.ChatlistInviteAlready ||
1568
- result instanceof _2_tl_js_1.types.chatlists.ChatlistInvite ||
1569
- result instanceof _2_tl_js_1.types.chatlists.ChatlistUpdates ||
1570
- result instanceof _2_tl_js_1.types.messages.Chats ||
1571
- result instanceof _2_tl_js_1.types.messages.ChatsSlice) {
1572
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, result.chats);
1573
- if ("users" in result) {
1574
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, result.users);
1575
- }
1576
- if ("messages" in result) {
1577
- for (const message of result.messages) {
1578
- if (message instanceof _2_tl_js_1.types.Message || message instanceof _2_tl_js_1.types.MessageService) {
1579
- await this.storage.setMessage((0, _2_tl_js_1.peerToChatId)(message.peer_id), message.id, message);
1580
- }
1581
- }
1582
- }
1583
- }
1584
- if (result instanceof _2_tl_js_1.types.messages.Messages) {
1585
- for (const message of result.messages) {
1586
- if (message instanceof _2_tl_js_1.types.Message || message instanceof _2_tl_js_1.types.MessageService) {
1587
- await this.storage.setMessage((0, _2_tl_js_1.peerToChatId)(message.peer_id), message.id, message);
1588
- }
1589
- }
1590
- }
1591
- }
1592
1234
  /**
1593
1235
  * Send a text message.
1594
1236
  *
@@ -1598,50 +1240,30 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1598
1240
  * @returns The sent text message.
1599
1241
  */
1600
1242
  async sendMessage(chatId, text, params) {
1601
- const [message, entities] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_parseText).call(this, text, params);
1602
- const replyMarkup = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params);
1603
- const peer = await this.getInputPeer(chatId);
1604
- const randomId = (0, _1_utilities_js_1.getRandomId)();
1605
- const noWebpage = params?.disableWebPagePreview ? true : undefined;
1606
- const silent = params?.disableNotification ? true : undefined;
1607
- const noforwards = params?.protectContent ? true : undefined;
1608
- const sendAs = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_resolveSendAs).call(this, params);
1609
- const result = await this.api.messages.sendMessage({
1610
- peer,
1611
- random_id: randomId,
1612
- message,
1613
- no_webpage: noWebpage,
1614
- silent,
1615
- noforwards,
1616
- reply_to: __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyTo).call(this, params),
1617
- send_as: sendAs,
1618
- entities,
1619
- reply_markup: replyMarkup,
1620
- });
1621
- const message_ = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
1622
- return (0, _3_types_js_1.assertMessageType)(message_, "text");
1243
+ return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendMessage(chatId, text, params);
1623
1244
  }
1624
1245
  /**
1625
1246
  * Edit a message's text.
1626
1247
  *
1627
1248
  * @method
1628
- * @param chatId The chat where the message is.
1629
- * @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.
1630
1251
  * @param text The new text of the message.
1631
1252
  * @returns The edited text message.
1632
1253
  */
1633
1254
  async editMessageText(chatId, messageId, text, params) {
1634
- const [message, entities] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_parseText).call(this, text, params);
1635
- const result = await this.api.messages.editMessage({
1636
- id: messageId,
1637
- peer: await this.getInputPeer(chatId),
1638
- entities,
1639
- message,
1640
- no_webpage: params?.disableWebPagePreview ? true : undefined,
1641
- reply_markup: await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params),
1642
- });
1643
- const message_ = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
1644
- 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);
1645
1267
  }
1646
1268
  /**
1647
1269
  * Retrieve multiple messages.
@@ -1655,101 +1277,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1655
1277
  * @returns The retrieved messages.
1656
1278
  */
1657
1279
  async getMessages(chatId, messageIds) {
1658
- return await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getMessagesInner).call(this, chatId, messageIds).then((v) => v.map((v) => v.message));
1659
- }
1660
- async [(_Client_updatesToMessages = async function _Client_updatesToMessages(chatId, updates) {
1661
- const messages = new Array();
1662
- if (updates instanceof _2_tl_js_1.types.Updates) {
1663
- for (const update of updates.updates) {
1664
- if ("message" in update && update.message instanceof _2_tl_js_1.types.MessageEmpty) {
1665
- continue;
1666
- }
1667
- if (update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateEditMessage) {
1668
- messages.push(await (0, _3_types_js_1.constructMessage)(update.message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this)));
1669
- }
1670
- else if (update instanceof _2_tl_js_1.types.UpdateNewChannelMessage || update instanceof _2_tl_js_1.types.UpdateEditChannelMessage) {
1671
- messages.push(await (0, _3_types_js_1.constructMessage)(update.message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this)));
1672
- }
1673
- }
1674
- }
1675
- else if (updates instanceof _2_tl_js_1.types.UpdateShortSentMessage) {
1676
- const message = await this.getMessage(chatId, updates.id);
1677
- if (message != null) {
1678
- messages.push(message);
1679
- }
1680
- }
1681
- return messages;
1682
- }, _Client_resolveSendAs = async function _Client_resolveSendAs(params) {
1683
- const sendAs = params?.sendAs;
1684
- if (sendAs !== undefined) {
1685
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertUser).call(this, "sendAs");
1686
- return sendAs ? await this.getInputPeer(sendAs) : undefined;
1687
- }
1688
- }, _Client_constructReplyTo = function _Client_constructReplyTo(params) {
1689
- const topMsgId = params?.messageThreadId;
1690
- const replyToMsgId = params?.replyToMessageId;
1691
- 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;
1692
- }, _Client_parseText = function _Client_parseText(text, params) {
1693
- const entities_ = params?.entities ?? [];
1694
- const parseMode = params?.parseMode ?? this.parseMode;
1695
- switch (parseMode) {
1696
- case null:
1697
- break;
1698
- case "HTML": {
1699
- const [newText, entitiesToPush] = (0, _0_html_js_1.parseHtml)(text);
1700
- text = newText;
1701
- for (const entity of entitiesToPush) {
1702
- entities_.push(entity);
1703
- }
1704
- break;
1705
- }
1706
- default:
1707
- (0, _1_utilities_js_1.UNREACHABLE)();
1708
- }
1709
- const entities = entities_?.length > 0 ? entities_.map((v) => (0, _3_types_js_1.messageEntityToTlObject)(v)) : undefined;
1710
- return [text, entities];
1711
- }, _Client_getMessagesInner = async function _Client_getMessagesInner(chatId_, messageIds) {
1712
- const peer = await this.getInputPeer(chatId_);
1713
- let messages_ = new Array();
1714
- const chatId = (0, _2_tl_js_1.peerToChatId)(peer);
1715
- let shouldFetch = false;
1716
- for (const messageId of messageIds) {
1717
- const message = await this.storage.getMessage(chatId, messageId);
1718
- if (message == null) {
1719
- messages_ = [];
1720
- shouldFetch = true;
1721
- break;
1722
- }
1723
- else {
1724
- messages_.push(message);
1725
- }
1726
- }
1727
- if (shouldFetch) {
1728
- if (peer instanceof _2_tl_js_1.types.InputPeerChannel) {
1729
- messages_ = await this.api.channels.getMessages({
1730
- channel: new _2_tl_js_1.types.InputChannel(peer),
1731
- id: messageIds.map((v) => new _2_tl_js_1.types.InputMessageID({ id: v })),
1732
- }).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.messages.ChannelMessages).messages);
1733
- }
1734
- else {
1735
- messages_ = await this.api.messages.getMessages({
1736
- id: messageIds.map((v) => new _2_tl_js_1.types.InputMessageID({ id: v })),
1737
- }).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.messages.Messages).messages);
1738
- }
1739
- }
1740
- const messages = new Array();
1741
- for (const message_ of messages_) {
1742
- if (message_ instanceof _2_tl_js_1.types.MessageEmpty) {
1743
- continue;
1744
- }
1745
- const message = await (0, _3_types_js_1.constructMessage)(message_, this[getEntity].bind(this), null, this[getStickerSetName].bind(this));
1746
- const isReplyToMessage = message_ instanceof _2_tl_js_1.types.Message && message_.reply_to instanceof _2_tl_js_1.types.MessageReplyHeader;
1747
- messages.push({ message, isReplyToMessage });
1748
- }
1749
- return messages;
1750
- }, getMessageWithReply)](chatId, messageId) {
1751
- const messages = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getMessagesInner).call(this, chatId, [messageId]);
1752
- return messages[0]?.message ?? null;
1280
+ return await __classPrivateFieldGet(this, _Client_messageManager, "f").getMessages(chatId, messageIds);
1753
1281
  }
1754
1282
  /**
1755
1283
  * Retrieve a single message.
@@ -1763,8 +1291,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1763
1291
  * @returns The retrieved message.
1764
1292
  */
1765
1293
  async getMessage(chatId, messageId) {
1766
- const messages = await this.getMessages(chatId, [messageId]);
1767
- return messages[0] ?? null;
1294
+ return await __classPrivateFieldGet(this, _Client_messageManager, "f").getMessage(chatId, messageId);
1768
1295
  }
1769
1296
  /**
1770
1297
  * Download a file.
@@ -1779,139 +1306,8 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1779
1306
  * @returns A generator yielding the contents of the file.
1780
1307
  */
1781
1308
  async *download(fileId, params) {
1782
- const fileId_ = _3_types_js_1.FileID.decode(fileId);
1783
- switch (fileId_.fileType) {
1784
- case _3_types_js_1.FileType.ChatPhoto: {
1785
- const big = fileId_.params.thumbnailSource == _3_types_js_1.ThumbnailSource.ChatPhotoBig;
1786
- const peer = await this.getInputPeer(fileId_.params.chatId);
1787
- const location = new _2_tl_js_1.types.InputPeerPhotoFileLocation({ big: big ? true : undefined, peer, photo_id: fileId_.params.mediaId });
1788
- for await (const chunk of __classPrivateFieldGet(this, _Client_instances, "m", _Client_downloadInner).call(this, location, fileId_.dcId, params)) {
1789
- yield chunk;
1790
- }
1791
- break;
1792
- }
1793
- case _3_types_js_1.FileType.Photo: {
1794
- if (fileId_.params.mediaId == undefined || fileId_.params.accessHash == undefined || fileId_.params.fileReference == undefined || fileId_.params.thumbnailSize == undefined) {
1795
- (0, _1_utilities_js_1.UNREACHABLE)();
1796
- }
1797
- const location = new _2_tl_js_1.types.InputPhotoFileLocation({
1798
- id: fileId_.params.mediaId,
1799
- access_hash: fileId_.params.accessHash,
1800
- file_reference: fileId_.params.fileReference,
1801
- thumb_size: fileId_.params.thumbnailSize,
1802
- });
1803
- for await (const chunk of __classPrivateFieldGet(this, _Client_instances, "m", _Client_downloadInner).call(this, location, fileId_.dcId, params)) {
1804
- yield chunk;
1805
- }
1806
- break;
1807
- }
1808
- case _3_types_js_1.FileType.Document:
1809
- case _3_types_js_1.FileType.Sticker:
1810
- case _3_types_js_1.FileType.VideoNote:
1811
- case _3_types_js_1.FileType.Video:
1812
- case _3_types_js_1.FileType.Audio:
1813
- case _3_types_js_1.FileType.Voice:
1814
- case _3_types_js_1.FileType.Animation: {
1815
- if (fileId_.params.mediaId == undefined || fileId_.params.accessHash == undefined || fileId_.params.fileReference == undefined || fileId_.params.thumbnailSize == undefined) {
1816
- (0, _1_utilities_js_1.UNREACHABLE)();
1817
- }
1818
- const location = new _2_tl_js_1.types.InputDocumentFileLocation({
1819
- id: fileId_.params.mediaId,
1820
- access_hash: fileId_.params.accessHash,
1821
- file_reference: fileId_.params.fileReference,
1822
- thumb_size: fileId_.params.thumbnailSize,
1823
- });
1824
- for await (const chunk of __classPrivateFieldGet(this, _Client_instances, "m", _Client_downloadInner).call(this, location, fileId_.dcId, params)) {
1825
- yield chunk;
1826
- }
1827
- break;
1828
- }
1829
- default:
1830
- (0, _1_utilities_js_1.UNREACHABLE)();
1831
- }
1832
- }
1833
- async [(_Client_downloadInner = async function* _Client_downloadInner(location, dcId, params) {
1834
- const id = "id" in location ? location.id : "photo_id" in location ? location.photo_id : null;
1835
- if (id != null) {
1836
- const partCount = await this.storage.getFile(id);
1837
- if (partCount != null && partCount > 0) {
1838
- for await (const part of this.storage.iterFileParts(id, partCount)) {
1839
- yield part;
1840
- }
1841
- return;
1842
- }
1843
- }
1844
- const chunkSize = params?.chunkSize ?? 1024 * 1024;
1845
- if ((0, _1_utilities_js_1.mod)(chunkSize, 1024) != 0) {
1846
- throw new Error("chunkSize must be divisible by 1024");
1847
- }
1848
- const client = new _a(dcId == this.dcId ? this.storage : this.storage.branch(`download_client_${dcId}`), this.apiId, this.apiHash, {
1849
- transportProvider: this.transportProvider,
1850
- appVersion: this.appVersion,
1851
- deviceModel: this.deviceModel,
1852
- langCode: this.langCode,
1853
- langPack: this.langPack,
1854
- systemLangCode: this.systemLangCode,
1855
- systemVersion: this.systemVersion,
1856
- cdn: true,
1857
- });
1858
- let dc = String(dcId);
1859
- if (this.dcId < 0) {
1860
- dc += "-test";
1861
- }
1862
- await client.setDc(dc);
1863
- await client.connect();
1864
- await __classPrivateFieldGet(client, _Client_instances, "m", _Client_initConnection).call(client);
1865
- client.invoke.use(async (ctx, next) => {
1866
- if (ctx.error instanceof _4_errors_js_1.AuthKeyUnregistered) {
1867
- try {
1868
- const exportedAuth = await this.api.auth.exportAuthorization({ dc_id: dcId });
1869
- await client.authorize(exportedAuth);
1870
- return true;
1871
- }
1872
- catch (err) {
1873
- throw err;
1874
- }
1875
- }
1876
- else {
1877
- return await next();
1878
- }
1879
- });
1880
- const limit = chunkSize;
1881
- let offset = 0n;
1882
- let part = 0;
1883
- while (true) {
1884
- const file = await (client ?? this).invoke(new _2_tl_js_1.functions.upload.getFile({ location, offset, limit }));
1885
- if (file instanceof _2_tl_js_1.types.upload.File) {
1886
- yield file.bytes;
1887
- if (id != null) {
1888
- await this.storage.saveFilePart(id, part, file.bytes);
1889
- }
1890
- ++part;
1891
- if (file.bytes.length < limit) {
1892
- if (id != null) {
1893
- await this.storage.setFilePartCount(id, part + 1);
1894
- }
1895
- break;
1896
- }
1897
- else {
1898
- offset += BigInt(file.bytes.length);
1899
- }
1900
- }
1901
- else {
1902
- (0, _1_utilities_js_1.UNREACHABLE)();
1903
- }
1904
- }
1905
- }, getStickerSetName)](inputStickerSet, hash = 0) {
1906
- const maybeStickerSetName = await this.storage.getStickerSetName(inputStickerSet.id, inputStickerSet.access_hash);
1907
- if (maybeStickerSetName != null && Date.now() - maybeStickerSetName[1].getTime() < _4_constants_js_1.STICKER_SET_NAME_TTL) {
1908
- return maybeStickerSetName[0];
1909
- }
1910
- else {
1911
- const stickerSet = await this.api.messages.getStickerSet({ stickerset: inputStickerSet, hash });
1912
- const name = stickerSet[_2_tl_js_1.as](_2_tl_js_1.types.messages.StickerSet).set.short_name;
1913
- await this.storage.updateStickerSetName(inputStickerSet.id, inputStickerSet.access_hash, name);
1914
- return name;
1309
+ for await (const chunk of __classPrivateFieldGet(this, _Client_fileManager, "f").download(fileId, params)) {
1310
+ yield chunk;
1915
1311
  }
1916
1312
  }
1917
1313
  /**
@@ -1924,19 +1320,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1924
1320
  * @returns The forwarded messages.
1925
1321
  */
1926
1322
  async forwardMessages(from, to, messageIds, params) {
1927
- const result = await this.api.messages.forwardMessages({
1928
- from_peer: await this.getInputPeer(from),
1929
- to_peer: await this.getInputPeer(to),
1930
- id: messageIds,
1931
- random_id: messageIds.map(() => (0, _1_utilities_js_1.getRandomId)()),
1932
- silent: params?.disableNotification || undefined,
1933
- top_msg_id: params?.messageThreadId,
1934
- noforwards: params?.disableNotification || undefined,
1935
- send_as: params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined,
1936
- drop_author: params?.dropSenderName || undefined,
1937
- drop_media_captions: params?.dropCaption || undefined,
1938
- });
1939
- 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);
1940
1324
  }
1941
1325
  /**
1942
1326
  * Forward a single message.
@@ -1971,7 +1355,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1971
1355
  * @param id ID of the callback query to answer.
1972
1356
  */
1973
1357
  async answerCallbackQuery(id, params) {
1974
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "answerCallbackQuery");
1358
+ await this.storage.assertBot("answerCallbackQuery");
1975
1359
  await this.api.messages.setBotCallbackAnswer({
1976
1360
  query_id: BigInt(id),
1977
1361
  cache_time: params?.cacheTime ?? 0,
@@ -1989,47 +1373,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1989
1373
  * @returns The sent poll.
1990
1374
  */
1991
1375
  async sendPoll(chatId, question, options, params) {
1992
- const peer = await this.getInputPeer(chatId);
1993
- const randomId = (0, _1_utilities_js_1.getRandomId)();
1994
- const silent = params?.disableNotification ? true : undefined;
1995
- const noforwards = params?.protectContent ? true : undefined;
1996
- const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined; // TODO: check default sendAs
1997
- const replyMarkup = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params);
1998
- const explanation = params?.explanation;
1999
- const parseResult = explanation !== undefined ? __classPrivateFieldGet(this, _Client_instances, "m", _Client_parseText).call(this, explanation, { parseMode: params?.explanationParseMode, entities: params?.explanationEntities }) : undefined;
2000
- const solution = parseResult === undefined ? undefined : parseResult[0];
2001
- const solutionEntities = parseResult === undefined ? undefined : parseResult[1];
2002
- const answers = options.map((v, i) => new _2_tl_js_1.types.PollAnswer({ option: new Uint8Array([i]), text: v }));
2003
- const poll = new _2_tl_js_1.types.Poll({
2004
- id: (0, _1_utilities_js_1.getRandomId)(),
2005
- answers,
2006
- question,
2007
- closed: params?.isClosed ? true : undefined,
2008
- close_date: params?.closeDate ? Math.floor(params.closeDate.getTime() / 1000) : undefined,
2009
- close_period: params?.openPeriod ? params.openPeriod : undefined,
2010
- multiple_choice: params?.allowMultipleAnswers ? true : undefined,
2011
- public_voters: params?.isAnonymous === false ? true : undefined,
2012
- quiz: params?.type == "quiz" ? true : undefined,
2013
- });
2014
- const media = new _2_tl_js_1.types.InputMediaPoll({
2015
- poll,
2016
- correct_answers: params?.correctOptionIndex ? [new Uint8Array([params.correctOptionIndex])] : undefined,
2017
- solution,
2018
- solution_entities: solutionEntities,
2019
- });
2020
- const result = await this.api.messages.sendMedia({
2021
- peer,
2022
- random_id: randomId,
2023
- silent,
2024
- noforwards,
2025
- reply_markup: replyMarkup,
2026
- reply_to: __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyTo).call(this, params),
2027
- send_as: sendAs,
2028
- media,
2029
- message: "",
2030
- });
2031
- const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
2032
- return (0, _3_types_js_1.assertMessageType)(message, "poll");
1376
+ return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendPoll(chatId, question, options, params);
2033
1377
  }
2034
1378
  /**
2035
1379
  * Send a chat action.
@@ -2087,89 +1431,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
2087
1431
  * @param contents The contents of the file.
2088
1432
  */
2089
1433
  async upload(contents, params) {
2090
- const isBig = contents.length > 1048576; // 10 MB
2091
- const chunkSize = params?.chunkSize ?? 512 * 1024;
2092
- if ((0, _1_utilities_js_1.mod)(chunkSize, 1024) != 0) {
2093
- throw new Error("chunkSize must be divisible by 1024");
2094
- }
2095
- const signal = params?.signal;
2096
- dUpload("uploading " + (isBig ? "big " : "") + "file of size " + contents.length + " with chunk size of " + chunkSize);
2097
- const fileId = (0, _1_utilities_js_1.getRandomId)();
2098
- const name = params?.fileName ?? fileId.toString();
2099
- const client = new _a(this.storage, this.apiId, this.apiHash, {
2100
- transportProvider: this.transportProvider,
2101
- appVersion: this.appVersion,
2102
- deviceModel: this.deviceModel,
2103
- langCode: this.langCode,
2104
- langPack: this.langPack,
2105
- systemLangCode: this.systemLangCode,
2106
- systemVersion: this.systemVersion,
2107
- cdn: true,
2108
- initialDc: this.initialDc,
2109
- autoStart: false,
2110
- });
2111
- signal?.addEventListener("abort", () => (0, _1_utilities_js_1.drop)(client.disconnect()));
2112
- __classPrivateFieldGet(client, _Client_state, "f").salt = __classPrivateFieldGet(this, _Client_state, "f").salt;
2113
- await client.connect();
2114
- let part = 0;
2115
- const partCount = Math.ceil(contents.length / chunkSize);
2116
- try {
2117
- main: for (; part < partCount; part++) {
2118
- chunk: while (true) {
2119
- try {
2120
- const start = part * chunkSize;
2121
- const end = start + chunkSize;
2122
- const bytes = contents.slice(start, end);
2123
- if (bytes.length == 0) {
2124
- continue main;
2125
- }
2126
- if (isBig) {
2127
- await client.invoke(new _2_tl_js_1.functions.upload.saveBigFilePart({ file_id: fileId, file_part: part, bytes, file_total_parts: partCount }));
2128
- }
2129
- else {
2130
- await client.invoke(new _2_tl_js_1.functions.upload.saveFilePart({ file_id: fileId, bytes, file_part: part }));
2131
- }
2132
- dUpload((part + 1) + " out of " + partCount + " chunks have been uploaded so far");
2133
- break chunk;
2134
- }
2135
- catch (err) {
2136
- if (signal?.aborted) {
2137
- break main;
2138
- }
2139
- if (err instanceof _4_errors_js_1.FloodWait) {
2140
- dUpload("got a flood wait of " + err.seconds + " seconds");
2141
- await new Promise((r) => setTimeout(r, err.seconds * 1000));
2142
- }
2143
- else if (err instanceof ConnectionError) {
2144
- while (true) {
2145
- try {
2146
- await new Promise((r) => setTimeout(r, 3000));
2147
- await client.connect();
2148
- }
2149
- catch {
2150
- if (signal?.aborted) {
2151
- break main;
2152
- }
2153
- }
2154
- }
2155
- }
2156
- else {
2157
- throw err;
2158
- }
2159
- }
2160
- }
2161
- }
2162
- }
2163
- finally {
2164
- (0, _1_utilities_js_1.drop)(client.disconnect());
2165
- }
2166
- dUpload("uploaded all " + partCount + " chunk(s)");
2167
- if (isBig) {
2168
- return new _2_tl_js_1.types.InputFileBig({ id: fileId, parts: contents.length / chunkSize, name });
2169
- }
2170
- else {
2171
- return new _2_tl_js_1.types.InputFile({ id: fileId, name, parts: part, md5_checksum: "" });
2172
- }
1434
+ return await __classPrivateFieldGet(this, _Client_fileManager, "f").upload(contents, params);
2173
1435
  }
2174
1436
  /**
2175
1437
  * Set the bot's commands in the given scope and/or language. Bot-only.
@@ -2237,7 +1499,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
2237
1499
  }
2238
1500
  on(filter, ...middleawre) {
2239
1501
  return this.filter((ctx) => {
2240
- return (0, _0_utilities_js_1.match)(filter, ctx);
1502
+ return (0, _0_filters_js_1.match)(filter, ctx);
2241
1503
  }, ...middleawre);
2242
1504
  }
2243
1505
  command(commands, ...middleawre) {
@@ -2289,7 +1551,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
2289
1551
  * @method
2290
1552
  */
2291
1553
  async setMyDescription(params) {
2292
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "setMyDescription");
1554
+ await this.storage.assertBot("setMyDescription");
2293
1555
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { description: params?.description, lang_code: params?.languageCode ?? "" });
2294
1556
  }
2295
1557
  /**
@@ -2298,7 +1560,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
2298
1560
  * @method
2299
1561
  */
2300
1562
  async setMyName(params) {
2301
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "setMyName");
1563
+ await this.storage.assertBot("setMyName");
2302
1564
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { name: params?.name, lang_code: params?.languageCode ?? "" });
2303
1565
  }
2304
1566
  /**
@@ -2307,7 +1569,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
2307
1569
  * @method
2308
1570
  */
2309
1571
  async setMyShortDescription(params) {
2310
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "setMyShortDescription");
1572
+ await this.storage.assertBot("setMyShortDescription");
2311
1573
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { about: params?.shortDescription, lang_code: params?.languageCode ?? "" });
2312
1574
  }
2313
1575
  /**
@@ -2316,7 +1578,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
2316
1578
  * @method
2317
1579
  */
2318
1580
  async getMyDescription(params) {
2319
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "getMyDescription");
1581
+ await this.storage.assertBot("getMyDescription");
2320
1582
  return await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getMyInfo).call(this, params?.languageCode).then((v) => v.description);
2321
1583
  }
2322
1584
  /**
@@ -2325,7 +1587,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
2325
1587
  * @method
2326
1588
  */
2327
1589
  async getMyName(params) {
2328
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "getMyName");
1590
+ await this.storage.assertBot("getMyName");
2329
1591
  return await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getMyInfo).call(this, params?.languageCode).then((v) => v.description);
2330
1592
  }
2331
1593
  /**
@@ -2334,34 +1596,28 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
2334
1596
  * @method
2335
1597
  */
2336
1598
  async getMyShortDescription(params) {
2337
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "getMyShortDescription");
1599
+ await this.storage.assertBot("getMyShortDescription");
2338
1600
  return await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getMyInfo).call(this, params?.languageCode).then((v) => v.about);
2339
1601
  }
2340
1602
  /**
2341
1603
  * Delete multiple messages.
2342
1604
  *
2343
1605
  * @method
2344
- * @param chatId The chat that contains the messages.
1606
+ * @param chatId The identifier of the chat that contains the messages.
2345
1607
  * @param messageIds The identifier of the messages to delete.
2346
1608
  */
2347
1609
  async deleteMessages(chatId, messageIds, params) {
2348
- const peer = await this.getInputPeer(chatId);
2349
- if (peer instanceof _2_tl_js_1.types.InputPeerChannel) {
2350
- await this.api.channels.deleteMessages({ channel: new _2_tl_js_1.types.InputChannel(peer), id: messageIds });
2351
- }
2352
- else {
2353
- await this.api.messages.deleteMessages({ id: messageIds, revoke: params?.onlyForMe ? undefined : true });
2354
- }
1610
+ return await __classPrivateFieldGet(this, _Client_messageManager, "f").deleteMessages(chatId, messageIds, params);
2355
1611
  }
2356
1612
  /**
2357
1613
  * Delete a single message.
2358
1614
  *
2359
1615
  * @method
2360
- * @param chatId The chat that contains the message.
1616
+ * @param chatId The identifier of the chat that contains the message.
2361
1617
  * @param messageId The identifier of the message to delete.
2362
1618
  */
2363
1619
  async deleteMessage(chatId, messageId, params) {
2364
- await this.deleteMessages(chatId, [messageId], params);
1620
+ return await __classPrivateFieldGet(this, _Client_messageManager, "f").deleteMessages(chatId, [messageId], params);
2365
1621
  }
2366
1622
  /**
2367
1623
  * Send a photo.
@@ -2371,29 +1627,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
2371
1627
  * @param photo The photo to send.
2372
1628
  */
2373
1629
  async sendPhoto(chatId, photo, params) {
2374
- let media = null;
2375
- const spoiler = params?.hasSpoiler ? true : undefined;
2376
- if (typeof photo === "string") {
2377
- const fileId = __classPrivateFieldGet(this, _Client_instances, "m", _Client_resolveFileId).call(this, photo, _3_types_js_1.FileType.Photo);
2378
- if (fileId != null) {
2379
- media = new _2_tl_js_1.types.InputMediaPhoto({
2380
- id: new _2_tl_js_1.types.InputPhoto(fileId),
2381
- spoiler,
2382
- });
2383
- }
2384
- }
2385
- if (media == null) {
2386
- if (typeof photo === "string" && (0, _0_utilities_js_1.isHttpUrl)(photo)) {
2387
- media = new _2_tl_js_1.types.InputMediaPhotoExternal({ url: photo, spoiler });
2388
- }
2389
- else {
2390
- const [contents, fileName] = await (0, _0_utilities_js_1.getFileContents)(photo);
2391
- const file = await this.upload(contents, { fileName, chunkSize: params?.chunkSize, signal: params?.signal });
2392
- media = new _2_tl_js_1.types.InputMediaUploadedPhoto({ file, spoiler });
2393
- }
2394
- }
2395
- const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendMedia).call(this, chatId, media, params);
2396
- return (0, _3_types_js_1.assertMessageType)(message, "photo");
1630
+ return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendPhoto(chatId, photo, params);
2397
1631
  }
2398
1632
  /**
2399
1633
  * Send a document.
@@ -2403,8 +1637,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
2403
1637
  * @param document The document to send.
2404
1638
  */
2405
1639
  async sendDocument(chatId, document, params) {
2406
- const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendDocumentInner).call(this, chatId, document, params, _3_types_js_1.FileType.Document, []);
2407
- return (0, _3_types_js_1.assertMessageType)(message, "document");
1640
+ return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendDocument(chatId, document, params);
2408
1641
  }
2409
1642
  /**
2410
1643
  * Send a video.
@@ -2414,15 +1647,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
2414
1647
  * @param video The video to send.
2415
1648
  */
2416
1649
  async sendVideo(chatId, video, params) {
2417
- const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendDocumentInner).call(this, chatId, video, params, _3_types_js_1.FileType.Video, [
2418
- new _2_tl_js_1.types.DocumentAttributeVideo({
2419
- supports_streaming: params?.supportsStreaming ? true : undefined,
2420
- w: params?.width ?? 0,
2421
- h: params?.height ?? 0,
2422
- duration: params?.duration ?? 0,
2423
- }),
2424
- ]);
2425
- return (0, _3_types_js_1.assertMessageType)(message, "video");
1650
+ return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendVideo(chatId, video, params);
2426
1651
  }
2427
1652
  /**
2428
1653
  * Send an animation.
@@ -2432,16 +1657,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
2432
1657
  * @param animation The animation to send.
2433
1658
  */
2434
1659
  async sendAnimation(chatId, animation, params) {
2435
- const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendDocumentInner).call(this, chatId, animation, params, _3_types_js_1.FileType.Animation, [
2436
- new _2_tl_js_1.types.DocumentAttributeAnimated(),
2437
- new _2_tl_js_1.types.DocumentAttributeVideo({
2438
- supports_streaming: true,
2439
- w: params?.width ?? 0,
2440
- h: params?.height ?? 0,
2441
- duration: params?.duration ?? 0,
2442
- }),
2443
- ]);
2444
- return (0, _3_types_js_1.assertMessageType)(message, "animation");
1660
+ return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendAnimation(chatId, animation, params);
2445
1661
  }
2446
1662
  /**
2447
1663
  * Send a voice message.
@@ -2451,13 +1667,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
2451
1667
  * @param voice The voice to send.
2452
1668
  */
2453
1669
  async sendVoice(chatId, voice, params) {
2454
- const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendDocumentInner).call(this, chatId, voice, params, _3_types_js_1.FileType.Voice, [
2455
- new _2_tl_js_1.types.DocumentAttributeAudio({
2456
- voice: true,
2457
- duration: params?.duration ?? 0,
2458
- }),
2459
- ]);
2460
- return (0, _3_types_js_1.assertMessageType)(message, "voice");
1670
+ return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendVoice(chatId, voice, params);
2461
1671
  }
2462
1672
  /**
2463
1673
  * Send an audio file.
@@ -2467,14 +1677,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
2467
1677
  * @param audio The audio to send.
2468
1678
  */
2469
1679
  async sendAudio(chatId, audio, params) {
2470
- const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendDocumentInner).call(this, chatId, audio, params, _3_types_js_1.FileType.Audio, [
2471
- new _2_tl_js_1.types.DocumentAttributeAudio({
2472
- duration: params?.duration ?? 0,
2473
- performer: params?.performer,
2474
- title: params?.title,
2475
- }),
2476
- ]);
2477
- return (0, _3_types_js_1.assertMessageType)(message, "audio");
1680
+ return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendAudio(chatId, audio, params);
2478
1681
  }
2479
1682
  /**
2480
1683
  * Send a video note.
@@ -2483,16 +1686,8 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
2483
1686
  * @param chatId The chat to send the video note to.
2484
1687
  * @param videoNote The video note to send.
2485
1688
  */
2486
- async sendVideoNote(chatId, audio, params) {
2487
- const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendDocumentInner).call(this, chatId, audio, params, _3_types_js_1.FileType.VideoNote, [
2488
- new _2_tl_js_1.types.DocumentAttributeVideo({
2489
- round_message: true,
2490
- w: params?.length ?? 0,
2491
- h: params?.length ?? 0,
2492
- duration: params?.duration ?? 0,
2493
- }),
2494
- ], false);
2495
- 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);
2496
1691
  }
2497
1692
  /**
2498
1693
  * Send a location.
@@ -2503,42 +1698,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
2503
1698
  * @param longitude The location's longitude.
2504
1699
  */
2505
1700
  async sendLocation(chatId, latitude, longitude, params) {
2506
- const peer = await this.getInputPeer(chatId);
2507
- const randomId = (0, _1_utilities_js_1.getRandomId)();
2508
- const silent = params?.disableNotification ? true : undefined;
2509
- const noforwards = params?.protectContent ? true : undefined;
2510
- const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined; // TODO: check default sendAs
2511
- const replyMarkup = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params);
2512
- const result = await this.api.messages.sendMedia({
2513
- peer,
2514
- random_id: randomId,
2515
- silent,
2516
- noforwards,
2517
- reply_to: __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyTo).call(this, params),
2518
- send_as: sendAs,
2519
- reply_markup: replyMarkup,
2520
- media: params?.livePeriod !== undefined
2521
- ? new _2_tl_js_1.types.InputMediaGeoLive({
2522
- geo_point: new _2_tl_js_1.types.InputGeoPoint({
2523
- lat: latitude,
2524
- long: longitude,
2525
- accuracy_radius: params?.horizontalAccuracy,
2526
- }),
2527
- heading: params?.heading,
2528
- period: params.livePeriod,
2529
- proximity_notification_radius: params?.proximityAlertRadius,
2530
- })
2531
- : new _2_tl_js_1.types.InputMediaGeoPoint({
2532
- geo_point: new _2_tl_js_1.types.InputGeoPoint({
2533
- lat: latitude,
2534
- long: longitude,
2535
- accuracy_radius: params?.horizontalAccuracy,
2536
- }),
2537
- }),
2538
- message: "",
2539
- });
2540
- const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
2541
- return (0, _3_types_js_1.assertMessageType)(message, "location");
1701
+ return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendLocation(chatId, latitude, longitude, params);
2542
1702
  }
2543
1703
  /**
2544
1704
  * Send a contact.
@@ -2549,30 +1709,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
2549
1709
  * @param number The contact's phone number.
2550
1710
  */
2551
1711
  async sendContact(chatId, firstName, number, params) {
2552
- const peer = await this.getInputPeer(chatId);
2553
- const randomId = (0, _1_utilities_js_1.getRandomId)();
2554
- const silent = params?.disableNotification ? true : undefined;
2555
- const noforwards = params?.protectContent ? true : undefined;
2556
- const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined; // TODO: check default sendAs
2557
- const replyMarkup = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params);
2558
- const result = await this.api.messages.sendMedia({
2559
- peer,
2560
- random_id: randomId,
2561
- silent,
2562
- noforwards,
2563
- reply_to: __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyTo).call(this, params),
2564
- send_as: sendAs,
2565
- reply_markup: replyMarkup,
2566
- media: new _2_tl_js_1.types.InputMediaContact({
2567
- phone_number: number,
2568
- first_name: firstName,
2569
- last_name: params?.lastName ?? "",
2570
- vcard: params?.vcard ?? "",
2571
- }),
2572
- message: "",
2573
- });
2574
- const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
2575
- return (0, _3_types_js_1.assertMessageType)(message, "contact");
1712
+ return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendContact(chatId, firstName, number, params);
2576
1713
  }
2577
1714
  /**
2578
1715
  * Send a dice.
@@ -2581,27 +1718,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
2581
1718
  * @param chatId The chat to send the dice to.
2582
1719
  */
2583
1720
  async sendDice(chatId, params) {
2584
- const peer = await this.getInputPeer(chatId);
2585
- const randomId = (0, _1_utilities_js_1.getRandomId)();
2586
- const silent = params?.disableNotification ? true : undefined;
2587
- const noforwards = params?.protectContent ? true : undefined;
2588
- const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined; // TODO: check default sendAs
2589
- const replyMarkup = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params);
2590
- const result = await this.api.messages.sendMedia({
2591
- peer,
2592
- random_id: randomId,
2593
- silent,
2594
- noforwards,
2595
- reply_to: __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyTo).call(this, params),
2596
- send_as: sendAs,
2597
- reply_markup: replyMarkup,
2598
- media: new _2_tl_js_1.types.InputMediaDice({
2599
- emoticon: params?.emoji ?? "🎲",
2600
- }),
2601
- message: "",
2602
- });
2603
- const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
2604
- return (0, _3_types_js_1.assertMessageType)(message, "dice");
1721
+ return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendDice(chatId, params);
2605
1722
  }
2606
1723
  /**
2607
1724
  * Send a venue.
@@ -2614,35 +1731,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
2614
1731
  * @param address The written address of the venue.
2615
1732
  */
2616
1733
  async sendVenue(chatId, latitude, longitude, title, address, params) {
2617
- const peer = await this.getInputPeer(chatId);
2618
- const randomId = (0, _1_utilities_js_1.getRandomId)();
2619
- const silent = params?.disableNotification ? true : undefined;
2620
- const noforwards = params?.protectContent ? true : undefined;
2621
- const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined; // TODO: check default sendAs
2622
- const replyMarkup = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params);
2623
- const result = await this.api.messages.sendMedia({
2624
- peer,
2625
- random_id: randomId,
2626
- silent,
2627
- noforwards,
2628
- reply_to: __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyTo).call(this, params),
2629
- send_as: sendAs,
2630
- reply_markup: replyMarkup,
2631
- media: new _2_tl_js_1.types.InputMediaVenue({
2632
- geo_point: new _2_tl_js_1.types.InputGeoPoint({
2633
- lat: latitude,
2634
- long: longitude,
2635
- }),
2636
- title,
2637
- address,
2638
- venue_id: params?.foursquareId ?? "",
2639
- venue_type: params?.foursquareType ?? "",
2640
- provider: "foursquare",
2641
- }),
2642
- message: "",
2643
- });
2644
- const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
2645
- return (0, _3_types_js_1.assertMessageType)(message, "venue");
1734
+ return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendVenue(chatId, latitude, longitude, title, address, params);
2646
1735
  }
2647
1736
  /**
2648
1737
  * Get network statistics. This might not always be available.
@@ -2672,32 +1761,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
2672
1761
  * @method
2673
1762
  */
2674
1763
  async getChats(params) {
2675
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertUser).call(this, "getChats");
2676
- if (!__classPrivateFieldGet(this, _Client_chatsLoadedFromStorage, "f")) {
2677
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_loadChatsFromStorage).call(this);
2678
- }
2679
- if (params?.after?.id && !__classPrivateFieldGet(this, _Client_chats, "f").has(params.after.id)) {
2680
- throw new Error("Invalid after");
2681
- }
2682
- let limit = params?.limit ?? 100;
2683
- if (limit <= 0 || limit > 100) {
2684
- limit = 100;
2685
- }
2686
- const listId = (0, _0_utilities_js_1.getChatListId)(params?.from ?? "main");
2687
- let chats = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLoadedChats).call(this, listId);
2688
- if (params?.after) {
2689
- chats = chats
2690
- .filter((v) => v.order < params.after.order);
2691
- }
2692
- if (chats.length < limit) {
2693
- d("have only %d chats but %d more is needed", chats.length, limit - chats.length);
2694
- if (!await this.storage.hasAllChats(listId)) {
2695
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchChats).call(this, listId, limit, params?.after);
2696
- return await this.getChats(params);
2697
- }
2698
- }
2699
- chats = chats.slice(0, limit);
2700
- return chats;
1764
+ return await __classPrivateFieldGet(this, _Client_chatListManager, "f").getChats(params?.from, params?.after, params?.limit);
2701
1765
  }
2702
1766
  /**
2703
1767
  * Get a chat.
@@ -2711,13 +1775,13 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
2711
1775
  maybeChatId = chatId;
2712
1776
  }
2713
1777
  else if (typeof chatId === "string") {
2714
- 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));
2715
1779
  }
2716
1780
  else {
2717
1781
  (0, _1_utilities_js_1.UNREACHABLE)();
2718
1782
  }
2719
1783
  if (maybeChatId != null) {
2720
- const [chat] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, maybeChatId);
1784
+ const [chat] = __classPrivateFieldGet(this, _Client_chatListManager, "f").getChatAnywhere(maybeChatId);
2721
1785
  if (chat !== undefined) {
2722
1786
  return chat;
2723
1787
  }
@@ -2772,160 +1836,282 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
2772
1836
  /**
2773
1837
  * Get chat history. User-only.
2774
1838
  *
2775
- * @param chatId The identifier of the chat to get its history.
2776
1839
  * @method
1840
+ * @param chatId The identifier of the chat to get its history.
2777
1841
  */
2778
1842
  async getHistory(chatId, params) {
2779
- let limit = params?.limit ?? 100;
2780
- if (limit <= 0) {
2781
- limit = 1;
2782
- }
2783
- else if (limit > 100) {
2784
- limit = 100;
2785
- }
2786
- let offsetId = params?.after?.id ?? 0;
2787
- if (offsetId < 0) {
2788
- offsetId = 0;
2789
- }
2790
- const peer = await this.getInputPeer(chatId);
2791
- const messages = new Array();
2792
- for (const message_ of await this.storage.getHistory((0, _2_tl_js_1.peerToChatId)(peer), offsetId, limit)) {
2793
- const message = await (0, _3_types_js_1.constructMessage)(message_, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this), false);
2794
- messages.push(message);
2795
- }
2796
- if (messages.length < limit) {
2797
- d("have only %d messages but need %d more", messages.length, limit - messages.length);
2798
- if (messages.length > 0) {
2799
- offsetId = messages[messages.length - 1].id; // TODO: track id of oldest message and don't send requests for it
2800
- }
2801
- const result = await this.api.messages.getHistory({
2802
- peer: peer,
2803
- offset_id: offsetId,
2804
- offset_date: 0,
2805
- add_offset: 0,
2806
- limit,
2807
- max_id: 0,
2808
- min_id: 0,
2809
- hash: 0n,
2810
- });
2811
- if (!("messages" in result)) {
2812
- (0, _1_utilities_js_1.UNREACHABLE)();
2813
- }
2814
- for (const message_ of result.messages) {
2815
- const message = await (0, _3_types_js_1.constructMessage)(message_, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this), false);
2816
- messages.push(message);
2817
- }
2818
- }
2819
- return messages;
1843
+ return await __classPrivateFieldGet(this, _Client_messageManager, "f").getHistory(chatId, params);
2820
1844
  }
2821
1845
  /**
2822
1846
  * Get custom emoji documents for download.
2823
1847
  *
2824
- * @param id Identifier of one or more of custom emojis.
2825
1848
  * @method
1849
+ * @param id Identifier of one or more of custom emojis.
2826
1850
  */
2827
1851
  async getCustomEmojiDocuments(id) {
2828
- id = Array.isArray(id) ? id : [id];
2829
- if (!id.length) {
2830
- throw new Error("No custom emoji ID provided");
2831
- }
2832
- const documents = new Array();
2833
- let shouldFetch = false;
2834
- for (const [i, id_] of id.entries()) {
2835
- const maybeDocument = await this.storage.getCustomEmojiDocument(BigInt(id_));
2836
- if (maybeDocument != null && Date.now() - maybeDocument[1].getTime() <= 30 * 60 * 1000) {
2837
- const document_ = maybeDocument[0];
2838
- const fileUniqueId = new _3_types_js_1.FileUniqueID(_3_types_js_1.FileUniqueType.Document, { mediaId: document_.id }).encode();
2839
- const fileId = new _3_types_js_1.FileID(null, null, _3_types_js_1.FileType.Document, document_.dc_id, {
2840
- mediaId: document_.id,
2841
- accessHash: document_.access_hash,
2842
- fileReference: document_.file_reference,
2843
- }).encode();
2844
- 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);
2845
- documents.push(document);
2846
- }
2847
- else {
2848
- shouldFetch = true;
2849
- break;
2850
- }
2851
- }
2852
- if (!shouldFetch) {
2853
- return documents;
2854
- }
2855
- 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)));
2856
- for (const [i, document_] of documents_.entries()) {
2857
- const fileUniqueId = new _3_types_js_1.FileUniqueID(_3_types_js_1.FileUniqueType.Document, { mediaId: document_.id }).encode();
2858
- const fileId = new _3_types_js_1.FileID(null, null, _3_types_js_1.FileType.Document, document_.dc_id, {
2859
- mediaId: document_.id,
2860
- accessHash: document_.access_hash,
2861
- fileReference: document_.file_reference,
2862
- }).encode();
2863
- 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);
2864
- documents.push(document);
2865
- }
2866
- return documents;
1852
+ return await __classPrivateFieldGet(this, _Client_fileManager, "f").getCustomEmojiDocuments(id);
2867
1853
  }
2868
1854
  /**
2869
1855
  * Set a chat's available reactions.
2870
1856
  *
1857
+ * @method
2871
1858
  * @param chatId The identifier of the chat.
2872
1859
  * @param availableReactions The new available reactions.
2873
- * @method
2874
1860
  */
2875
1861
  async setAvailableReactions(chatId, availableReactions) {
2876
- // TODO: sync with storage
2877
- await this.api.messages.setChatAvailableReactions({
2878
- peer: await this.getInputPeer(chatId),
2879
- 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)(),
2880
- });
1862
+ await __classPrivateFieldGet(this, _Client_reactionManager, "f").setAvailableReactions(chatId, availableReactions);
2881
1863
  }
2882
1864
  /**
2883
1865
  * Change reactions made to a message.
2884
1866
  *
1867
+ * @method
2885
1868
  * @param chatId The identifier of the chat which the message belongs to.
2886
1869
  * @param messageId The identifier of the message to add the reaction to.
2887
1870
  * @param reactions The new reactions.
2888
1871
  */
2889
1872
  async setReactions(chatId, messageId, reactions, params) {
2890
- 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);
2891
1874
  }
2892
1875
  /**
2893
1876
  * Make a reaction to a message.
2894
1877
  *
1878
+ * @method
2895
1879
  * @param chatId The identifier of the chat which the message belongs to.
2896
1880
  * @param messageId The identifier of the message to add the reaction to.
2897
1881
  * @param reaction The reaction to add.
2898
1882
  */
2899
1883
  async addReaction(chatId, messageId, reaction, params) {
2900
- const chosenReactions = await this.getMessage(chatId, messageId).then((v) => v?.reactions ?? []).then((v) => v.filter((v) => v.chosen));
2901
- for (const r of chosenReactions) {
2902
- if ((0, _3_types_js_1.reactionEqual)(r.reaction, reaction)) {
2903
- return;
2904
- }
2905
- }
2906
- const reactions = [reaction, ...chosenReactions.map((v) => v.reaction)];
2907
- await this.setReactions(chatId, messageId, reactions, params);
1884
+ await __classPrivateFieldGet(this, _Client_reactionManager, "f").addReaction(chatId, messageId, reaction, params);
2908
1885
  }
2909
1886
  /**
2910
1887
  * Undo a reaction made to a message.
2911
1888
  *
1889
+ * @method
2912
1890
  * @param chatId The identifier of the chat which the message belongs to.
2913
1891
  * @param messageId The identifier of the message which the reaction was made to.
2914
1892
  * @param reaction The reaction to remove.
2915
1893
  */
2916
1894
  async removeReaction(chatId, messageId, reaction) {
2917
- const chosenReactions = await this.getMessage(chatId, messageId).then((v) => v?.reactions ?? []).then((v) => v.filter((v) => v.chosen));
2918
- for (const r of chosenReactions) {
2919
- if ((0, _3_types_js_1.reactionEqual)(r.reaction, reaction)) {
2920
- const reactions = chosenReactions.filter((v) => v != r).map((v) => v.reaction);
2921
- await this.setReactions(chatId, messageId, reactions);
2922
- 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");
2923
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
+ });
2924
2023
  }
2925
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
+ }
2926
2093
  }
2927
2094
  exports.Client = Client;
2928
- _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() {
2929
2115
  if (__classPrivateFieldGet(this, _Client_lastGetMe, "f") != null) {
2930
2116
  return __classPrivateFieldGet(this, _Client_lastGetMe, "f");
2931
2117
  }
@@ -2934,38 +2120,12 @@ _a = Client, _Client_getMe = async function _Client_getMe() {
2934
2120
  __classPrivateFieldSet(this, _Client_lastGetMe, user, "f");
2935
2121
  return user;
2936
2122
  }
2937
- }, _Client_handleStoredUpdates = async function _Client_handleStoredUpdates(boxId) {
2938
- if (__classPrivateFieldGet(this, _Client_handleUpdatesSet, "f").has(boxId)) {
2939
- return;
2940
- }
2941
- __classPrivateFieldGet(this, _Client_handleUpdatesSet, "f").add(boxId);
2942
- do {
2943
- const maybeUpdate = await this.storage.getFirstUpdate(boxId);
2944
- if (maybeUpdate == null) {
2945
- break;
2946
- }
2947
- const [key, update] = maybeUpdate;
2948
- for (let i = 0; i < 100; ++i) {
2949
- try {
2950
- const handle = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleUpdate).call(this, update);
2951
- handle: for (let i = 0; i < 2; ++i) {
2952
- try {
2953
- await handle();
2954
- break handle;
2955
- }
2956
- catch {
2957
- continue handle;
2958
- }
2959
- }
2960
- break;
2961
- }
2962
- catch (err) {
2963
- d("#handleUpdate error: %o", err);
2964
- }
2965
- }
2966
- await this.storage.set(key, null);
2967
- } while (true);
2968
- __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
+ });
2969
2129
  }, _Client_handleUpdate = async function _Client_handleUpdate(update) {
2970
2130
  const promises = new Array();
2971
2131
  if (update instanceof _2_tl_js_1.types.UpdateUserName) {
@@ -2983,7 +2143,7 @@ _a = Client, _Client_getMe = async function _Client_getMe() {
2983
2143
  if (update.message instanceof _2_tl_js_1.types.Message || update.message instanceof _2_tl_js_1.types.MessageService) {
2984
2144
  const chatId = (0, _2_tl_js_1.peerToChatId)(update.message.peer_id);
2985
2145
  await this.storage.setMessage(chatId, update.message.id, update.message);
2986
- promises.push((await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId))());
2146
+ promises.push(__classPrivateFieldGet(this, _Client_chatListManager, "f").reassignChatLastMessage(chatId));
2987
2147
  }
2988
2148
  }
2989
2149
  if (update instanceof _2_tl_js_1.types.UpdateMessageReactions) {
@@ -2996,7 +2156,7 @@ _a = Client, _Client_getMe = async function _Client_getMe() {
2996
2156
  const forwards = message.forwards ?? 0;
2997
2157
  const recentReactions = update.reactions.recent_reactions ?? [];
2998
2158
  const reactions = update.reactions.results.map((v) => (0, _3_types_js_1.constructMessageReaction)(v, recentReactions));
2999
- 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 } }));
3000
2160
  }
3001
2161
  }
3002
2162
  else if (update instanceof _2_tl_js_1.types.UpdateChannelMessageViews || update instanceof _2_tl_js_1.types.UpdateChannelMessageForwards) {
@@ -3013,7 +2173,7 @@ _a = Client, _Client_getMe = async function _Client_getMe() {
3013
2173
  const forwards = message.forwards ?? 0;
3014
2174
  const recentReactions = message.reactions?.recent_reactions ?? [];
3015
2175
  const reactions = message.reactions?.results.map((v) => (0, _3_types_js_1.constructMessageReaction)(v, recentReactions)) ?? [];
3016
- 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 } }));
3017
2177
  }
3018
2178
  }
3019
2179
  if (update instanceof _2_tl_js_1.types.UpdateNewMessage ||
@@ -3027,16 +2187,14 @@ _a = Client, _Client_getMe = async function _Client_getMe() {
3027
2187
  shouldIgnore = __classPrivateFieldGet(this, _Client_ignoreOutgoing, "f");
3028
2188
  }
3029
2189
  if (!shouldIgnore) {
3030
- 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);
3031
2191
  promises.push((async () => {
3032
- let context;
3033
2192
  if (update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateNewChannelMessage) {
3034
- context = await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { message });
2193
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { message });
3035
2194
  }
3036
2195
  else {
3037
- context = await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { editedMessage: message });
2196
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { editedMessage: message });
3038
2197
  }
3039
- await __classPrivateFieldGet(this, _Client_handle, "f").call(this, context, _0_utilities_js_1.resolve);
3040
2198
  })());
3041
2199
  }
3042
2200
  }
@@ -3052,12 +2210,12 @@ _a = Client, _Client_getMe = async function _Client_getMe() {
3052
2210
  if (deletedMessages.length > 0) {
3053
2211
  promises.push((async () => {
3054
2212
  try {
3055
- 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 });
3056
2214
  }
3057
2215
  finally {
3058
2216
  for (const { chatId, messageId } of deletedMessages) {
3059
2217
  await this.storage.setMessage(chatId, messageId, null);
3060
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId);
2218
+ await __classPrivateFieldGet(this, _Client_chatListManager, "f").reassignChatLastMessage(chatId);
3061
2219
  }
3062
2220
  }
3063
2221
  })());
@@ -3075,424 +2233,58 @@ _a = Client, _Client_getMe = async function _Client_getMe() {
3075
2233
  if (deletedMessages.length > 0) {
3076
2234
  promises.push((async () => {
3077
2235
  try {
3078
- 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 });
3079
2237
  }
3080
2238
  finally {
3081
2239
  for (const { chatId, messageId } of deletedMessages) {
3082
2240
  await this.storage.setMessage(chatId, messageId, null);
3083
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId);
2241
+ await __classPrivateFieldGet(this, _Client_chatListManager, "f").reassignChatLastMessage(chatId);
3084
2242
  }
3085
2243
  }
3086
2244
  })());
3087
2245
  }
3088
2246
  }
3089
2247
  if (update instanceof _2_tl_js_1.types.UpdateBotCallbackQuery || update instanceof _2_tl_js_1.types.UpdateInlineBotCallbackQuery) {
3090
- 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)) }));
3091
2249
  }
3092
2250
  else if (update instanceof _2_tl_js_1.types.UpdateBotInlineQuery) {
3093
- 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)) }));
3094
2252
  }
3095
2253
  else if (update instanceof _2_tl_js_1.types.UpdateBotInlineSend) {
3096
- 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)) }));
3097
2255
  }
3098
2256
  else if (update instanceof _2_tl_js_1.types.UpdateBotMessageReactions) {
3099
- const date = new Date(update.date * 1000);
3100
- const reactions = update.reactions.map((v) => (0, _3_types_js_1.constructReactionCount)(v));
3101
- const entity = await this[getEntity](update.peer);
3102
- if (entity) {
3103
- const chat = (0, _3_types_js_1.constructChatP)(entity);
3104
- const messageId = update.msg_id;
3105
- const messageReactionCount = { chat, messageId, date, reactions };
3106
- 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 }));
3107
2266
  }
3108
2267
  }
3109
2268
  if (update instanceof _2_tl_js_1.types.UpdatePinnedDialogs) {
3110
- 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);
3111
2273
  }
3112
2274
  if (update instanceof _2_tl_js_1.types.UpdateChannel) {
3113
- const peer = new _2_tl_js_1.types.PeerChannel(update);
3114
- const channel = await this[getEntity](peer);
3115
- if (channel != null && "left" in channel && channel.left) {
3116
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_removeChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
3117
- }
3118
- else if (channel instanceof _2_tl_js_1.types.ChannelForbidden) {
3119
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_removeChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
3120
- }
3121
- else if (channel instanceof _2_tl_js_1.types.Channel) {
3122
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updateOrAddChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
3123
- }
2275
+ await __classPrivateFieldGet(this, _Client_chatListManager, "f").handleUpdateChannel(update);
3124
2276
  }
3125
- else if (update instanceof _2_tl_js_1.types.UpdateChat) { // TODO: handle deactivated (migration)
3126
- const peer = new _2_tl_js_1.types.PeerChat(update);
3127
- const chat = await this[getEntity](peer);
3128
- if (chat != null && "left" in chat && chat.left) {
3129
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_removeChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
3130
- }
3131
- else if (chat instanceof _2_tl_js_1.types.ChatForbidden) {
3132
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_removeChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
3133
- }
3134
- else if (chat instanceof _2_tl_js_1.types.Chat) {
3135
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updateOrAddChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
3136
- }
2277
+ else if (update instanceof _2_tl_js_1.types.UpdateChat) {
2278
+ await __classPrivateFieldGet(this, _Client_chatListManager, "f").handleUpdateChat(update);
3137
2279
  }
3138
2280
  else if (update instanceof _2_tl_js_1.types.UpdateUser || update instanceof _2_tl_js_1.types.UpdateUserName) {
3139
- const peer = new _2_tl_js_1.types.PeerUser(update);
3140
- const chat = await this[getEntity](peer);
3141
- if (chat != null) {
3142
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updateOrAddChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
3143
- }
2281
+ await __classPrivateFieldGet(this, _Client_chatListManager, "f").handleUpdateUser(update);
3144
2282
  }
3145
2283
  return () => Promise.all(promises);
3146
- }, _Client_constructReplyMarkup = async function _Client_constructReplyMarkup(params) {
3147
- if (params?.replyMarkup) {
3148
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "replyMarkup");
3149
- return (0, _3_types_js_1.replyMarkupToTlObject)(params.replyMarkup, __classPrivateFieldGet(this, _Client_usernameResolver, "f").bind(this));
3150
- }
3151
2284
  }, _Client_setMyInfo =
3152
2285
  //#endregion
3153
2286
  async function _Client_setMyInfo(info) {
3154
2287
  await this.api.bots.setBotInfo({ bot: new _2_tl_js_1.types.InputUserSelf(), ...info });
3155
2288
  }, _Client_getMyInfo = function _Client_getMyInfo(languageCode) {
3156
2289
  return this.api.bots.getBotInfo({ bot: new _2_tl_js_1.types.InputUserSelf(), lang_code: languageCode ?? "" });
3157
- }, _Client_resolveFileId = function _Client_resolveFileId(maybeFileId, expectedFileType) {
3158
- let fileId = null;
3159
- try {
3160
- fileId = _3_types_js_1.FileID.decode(maybeFileId);
3161
- }
3162
- catch (err) {
3163
- d("fileId: %o", err);
3164
- }
3165
- if (fileId != null) {
3166
- if (fileId.fileType != expectedFileType) {
3167
- (0, _1_utilities_js_1.UNREACHABLE)();
3168
- }
3169
- if (fileId.params.mediaId == undefined || fileId.params.accessHash == undefined || fileId.params.fileReference == undefined) {
3170
- (0, _1_utilities_js_1.UNREACHABLE)();
3171
- }
3172
- return {
3173
- id: fileId.params.mediaId,
3174
- access_hash: fileId.params.accessHash,
3175
- file_reference: fileId.params.fileReference,
3176
- };
3177
- }
3178
- return null;
3179
- }, _Client_sendMedia = async function _Client_sendMedia(chatId, media, params) {
3180
- const peer = await this.getInputPeer(chatId);
3181
- const randomId = (0, _1_utilities_js_1.getRandomId)();
3182
- const silent = params?.disableNotification ? true : undefined;
3183
- const noforwards = params?.protectContent ? true : undefined;
3184
- const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined; // TODO: check default sendAs
3185
- const replyMarkup = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params);
3186
- const caption_ = params?.caption;
3187
- const parseResult = caption_ !== undefined ? __classPrivateFieldGet(this, _Client_instances, "m", _Client_parseText).call(this, caption_, { parseMode: params?.parseMode, entities: params?.captionEntities }) : undefined;
3188
- const caption = parseResult === undefined ? undefined : parseResult[0];
3189
- const captionEntities = parseResult === undefined ? undefined : parseResult[1];
3190
- const result = await this.api.messages.sendMedia({
3191
- peer,
3192
- random_id: randomId,
3193
- silent,
3194
- noforwards,
3195
- reply_markup: replyMarkup,
3196
- reply_to: __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyTo).call(this, params),
3197
- send_as: sendAs,
3198
- media,
3199
- message: caption ?? "",
3200
- entities: captionEntities,
3201
- });
3202
- return await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
3203
- }, _Client_sendDocumentInner = async function _Client_sendDocumentInner(chatId, document, params, fileType, otherAttribs, urlSupported = false) {
3204
- let media = null;
3205
- const spoiler = params?.hasSpoiler ? true : undefined;
3206
- if (typeof document === "string") {
3207
- const fileId = __classPrivateFieldGet(this, _Client_instances, "m", _Client_resolveFileId).call(this, document, fileType);
3208
- if (fileId != null) {
3209
- media = new _2_tl_js_1.types.InputMediaDocument({
3210
- id: new _2_tl_js_1.types.InputDocument(fileId),
3211
- spoiler,
3212
- });
3213
- }
3214
- }
3215
- if (media == null) {
3216
- if (typeof document === "string" && (0, _0_utilities_js_1.isHttpUrl)(document)) {
3217
- if (!urlSupported) {
3218
- throw new Error("URL not supported");
3219
- }
3220
- media = new _2_tl_js_1.types.InputMediaDocumentExternal({ url: document, spoiler });
3221
- }
3222
- else {
3223
- const [contents, fileName_] = await (0, _0_utilities_js_1.getFileContents)(document);
3224
- const fileName = params?.fileName ?? fileName_;
3225
- const mimeType = params?.mimeType ?? (0, _0_deps_js_1.contentType)(fileName.split(".").slice(-1)[0]) ?? "application/octet-stream";
3226
- const file = await this.upload(contents, { fileName, chunkSize: params?.chunkSize, signal: params?.signal });
3227
- let thumb = undefined;
3228
- if (params?.thumbnail) {
3229
- const [thumbContents, fileName__] = await (0, _0_utilities_js_1.getFileContents)(params.thumbnail);
3230
- thumb = await this.upload(thumbContents, { fileName: fileName__, chunkSize: params?.chunkSize, signal: params?.signal });
3231
- }
3232
- media = new _2_tl_js_1.types.InputMediaUploadedDocument({
3233
- file,
3234
- thumb,
3235
- spoiler,
3236
- attributes: [new _2_tl_js_1.types.DocumentAttributeFilename({ file_name: fileName }), ...otherAttribs],
3237
- mime_type: mimeType,
3238
- });
3239
- }
3240
- }
3241
- const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendMedia).call(this, chatId, media, params);
3242
- return message;
3243
- }, _Client_sendChatUpdate = async function _Client_sendChatUpdate(chatId, added) {
3244
- try {
3245
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertUser).call(this, "");
3246
- }
3247
- catch {
3248
- return;
3249
- }
3250
- const [chat] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
3251
- const update = chat === undefined ? { deletedChat: { chatId } } : added ? { newChat: chat } : { editedChat: chat };
3252
- __classPrivateFieldGet(this, _Client_instances, "m", _Client_getHandleUpdateQueue).call(this, __classPrivateFieldGet(this, _Client_mainBoxId, "f")).add(async () => {
3253
- await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, update), _0_utilities_js_1.resolve);
3254
- });
3255
- }, _Client_reassignChatLastMessage = async function _Client_reassignChatLastMessage(chatId, add = false, sendUpdate = true) {
3256
- try {
3257
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertUser).call(this, "");
3258
- }
3259
- catch {
3260
- return () => Promise.resolve();
3261
- }
3262
- const [chat, listId] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
3263
- if (!chat && !add) {
3264
- return () => Promise.resolve();
3265
- }
3266
- const message_ = await this.storage.getLastMessage(chatId);
3267
- if (message_ != null) {
3268
- const message = await (0, _3_types_js_1.constructMessage)(message_, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this));
3269
- if (chat) {
3270
- chat.order = (0, _3_types_js_1.getChatOrder)(message, chat.pinned);
3271
- chat.lastMessage = message;
3272
- await this.storage.setChat(listId, chatId, chat.pinned, message.id, message.date);
3273
- }
3274
- else {
3275
- const pinnedChats = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getPinnedChats).call(this, listId);
3276
- const chat = await (0, _3_types_js_1.constructChat3)(chatId, pinnedChats.indexOf(chatId), message, this[getEntity].bind(this));
3277
- if (chat == null) {
3278
- (0, _1_utilities_js_1.UNREACHABLE)();
3279
- }
3280
- __classPrivateFieldGet(this, _Client_chats, "f").set(chatId, chat);
3281
- await this.storage.setChat(listId, chatId, chat.pinned, chat.lastMessage?.id ?? 0, chat.lastMessage?.date ?? new Date(0));
3282
- }
3283
- if (sendUpdate) {
3284
- return () => __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
3285
- }
3286
- return () => Promise.resolve();
3287
- }
3288
- const message = await this.getHistory(chatId, { limit: 1 }).then((v) => v[0]);
3289
- if (message !== undefined) {
3290
- if (chat) {
3291
- chat.order = (0, _3_types_js_1.getChatOrder)(message, chat.pinned);
3292
- chat.lastMessage = message;
3293
- await this.storage.setChat(listId, chatId, chat.pinned, message.id, message.date);
3294
- }
3295
- else {
3296
- const pinnedChats = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getPinnedChats).call(this, listId);
3297
- const chat = await (0, _3_types_js_1.constructChat3)(chatId, pinnedChats.indexOf(chatId), message, this[getEntity].bind(this));
3298
- if (chat == null) {
3299
- (0, _1_utilities_js_1.UNREACHABLE)();
3300
- }
3301
- __classPrivateFieldGet(this, _Client_chats, "f").set(chatId, chat);
3302
- }
3303
- if (sendUpdate) {
3304
- return () => __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
3305
- }
3306
- return () => Promise.resolve();
3307
- }
3308
- if (chat) {
3309
- chat.order = (0, _3_types_js_1.getChatOrder)(undefined, chat.pinned);
3310
- chat.lastMessage = undefined;
3311
- if (sendUpdate) {
3312
- return () => __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
3313
- }
3314
- }
3315
- return () => Promise.resolve();
3316
- }, _Client_tryGetChatId = function _Client_tryGetChatId(username) {
3317
- username = username.toLowerCase();
3318
- for (const chat of __classPrivateFieldGet(this, _Client_chats, "f").values()) {
3319
- if ("username" in chat) {
3320
- if (chat.username === username || chat.also?.some((v) => v.toLowerCase() === username)) {
3321
- return chat.id;
3322
- }
3323
- }
3324
- }
3325
- for (const chat of __classPrivateFieldGet(this, _Client_archivedChats, "f").values()) {
3326
- if ("username" in chat) {
3327
- if (chat.username === username || chat.also?.some((v) => v.toLowerCase() === username)) {
3328
- return chat.id;
3329
- }
3330
- }
3331
- }
3332
- return null;
3333
- }, _Client_getChatAnywhere = function _Client_getChatAnywhere(chatId) {
3334
- let chat = __classPrivateFieldGet(this, _Client_chats, "f").get(chatId);
3335
- if (chat) {
3336
- return [chat, 0];
3337
- }
3338
- chat = __classPrivateFieldGet(this, _Client_archivedChats, "f").get(chatId);
3339
- if (chat) {
3340
- return [chat, 1];
3341
- }
3342
- return [undefined, -1];
3343
- }, _Client_getChatList = function _Client_getChatList(listId) {
3344
- switch (listId) {
3345
- case 0:
3346
- return __classPrivateFieldGet(this, _Client_chats, "f");
3347
- case 1:
3348
- return __classPrivateFieldGet(this, _Client_archivedChats, "f");
3349
- default:
3350
- throw new Error("Invalid chat list: " + listId);
3351
- }
3352
- }, _Client_loadChatsFromStorage = async function _Client_loadChatsFromStorage() {
3353
- const chats = await this.storage.getChats(0);
3354
- const archivedChats = await this.storage.getChats(1);
3355
- for (const { chatId, pinned, topMessageId } of chats) {
3356
- const chat = await (0, _3_types_js_1.constructChat4)(chatId, pinned, topMessageId, this[getEntity].bind(this), this.getMessage.bind(this));
3357
- if (chat == null) {
3358
- continue;
3359
- }
3360
- __classPrivateFieldGet(this, _Client_chats, "f").set(chat.id, chat);
3361
- }
3362
- for (const { chatId, pinned, topMessageId } of archivedChats) {
3363
- const chat = await (0, _3_types_js_1.constructChat4)(chatId, pinned, topMessageId, this[getEntity].bind(this), this.getMessage.bind(this));
3364
- if (chat == null) {
3365
- continue;
3366
- }
3367
- __classPrivateFieldGet(this, _Client_archivedChats, "f").set(chat.id, chat);
3368
- }
3369
- __classPrivateFieldSet(this, _Client_chatsLoadedFromStorage, true, "f");
3370
- }, _Client_getLoadedChats = function _Client_getLoadedChats(listId) {
3371
- const chats_ = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, listId);
3372
- const chats = new Array();
3373
- for (const chat of chats_.values()) {
3374
- chats.push(chat);
3375
- }
3376
- return chats
3377
- .sort((a, b) => b.id - a.id)
3378
- .sort((a, b) => b.order.localeCompare(a.order));
3379
- }, _Client_loadPinnedChats = async function _Client_loadPinnedChats() {
3380
- const [pinnedChats, pinnedArchiveChats] = await Promise.all([this.storage.getPinnedChats(0), this.storage.getPinnedChats(1)]);
3381
- if (pinnedChats != null && pinnedArchiveChats != null) {
3382
- __classPrivateFieldSet(this, _Client_pinnedChats, pinnedChats, "f");
3383
- __classPrivateFieldSet(this, _Client_pinnedArchiveChats, pinnedArchiveChats, "f");
3384
- __classPrivateFieldSet(this, _Client_storageHadPinnedChats, true, "f");
3385
- }
3386
- __classPrivateFieldSet(this, _Client_pinnedChatsLoaded, true, "f");
3387
- }, _Client_fetchPinnedChats = async function _Client_fetchPinnedChats(listId = null) {
3388
- if (listId == null || listId == 0) {
3389
- const dialogs = await this.api.messages.getPinnedDialogs({ folder_id: 0 });
3390
- const pinnedChats = new Array();
3391
- for (const dialog of dialogs.dialogs) {
3392
- pinnedChats.push((0, _2_tl_js_1.peerToChatId)(dialog.peer));
3393
- }
3394
- __classPrivateFieldSet(this, _Client_pinnedChats, pinnedChats, "f");
3395
- await this.storage.setPinnedChats(0, __classPrivateFieldGet(this, _Client_pinnedChats, "f"));
3396
- }
3397
- if (listId == null || listId == 1) {
3398
- const dialogs = await this.api.messages.getPinnedDialogs({ folder_id: 1 });
3399
- const pinnedArchiveChats = new Array();
3400
- for (const dialog of dialogs.dialogs) {
3401
- pinnedArchiveChats.push((0, _2_tl_js_1.peerToChatId)(dialog.peer));
3402
- }
3403
- __classPrivateFieldSet(this, _Client_pinnedArchiveChats, pinnedArchiveChats, "f");
3404
- await this.storage.setPinnedChats(1, __classPrivateFieldGet(this, _Client_pinnedArchiveChats, "f"));
3405
- }
3406
- if (listId != null && listId != 0 && listId != 1) {
3407
- (0, _1_utilities_js_1.UNREACHABLE)();
3408
- }
3409
- }, _Client_getPinnedChats = async function _Client_getPinnedChats(listId) {
3410
- if (!__classPrivateFieldGet(this, _Client_pinnedChatsLoaded, "f")) {
3411
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_loadPinnedChats).call(this);
3412
- }
3413
- if (!__classPrivateFieldGet(this, _Client_storageHadPinnedChats, "f")) {
3414
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchPinnedChats).call(this);
3415
- }
3416
- switch (listId) {
3417
- case 0:
3418
- return __classPrivateFieldGet(this, _Client_pinnedChats, "f");
3419
- case 1:
3420
- return __classPrivateFieldGet(this, _Client_pinnedArchiveChats, "f");
3421
- default:
3422
- (0, _1_utilities_js_1.UNREACHABLE)();
3423
- }
3424
- }, _Client_updateOrAddChat = async function _Client_updateOrAddChat(chatId) {
3425
- const [chat, listId] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
3426
- if (chat !== undefined) {
3427
- const newChat = await (0, _3_types_js_1.constructChat3)(chatId, chat.pinned, chat.lastMessage, this[getEntity].bind(this));
3428
- if (newChat != null) {
3429
- __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, listId).set(chatId, newChat);
3430
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
3431
- }
3432
- }
3433
- else {
3434
- const chat = await (0, _3_types_js_1.constructChat4)(chatId, -1, -1, this[getEntity].bind(this), this.getMessage.bind(this));
3435
- if (chat != null) {
3436
- __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, 0).set(chatId, chat);
3437
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId, false, false);
3438
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, true);
3439
- }
3440
- }
3441
- }, _Client_removeChat = async function _Client_removeChat(chatId) {
3442
- const [chat, listId] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
3443
- if (chat !== undefined) {
3444
- __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, listId).delete(chatId);
3445
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
3446
- }
3447
- }, _Client_updatePinnedChats = async function _Client_updatePinnedChats(update) {
3448
- const listId = update.folder_id ?? 0;
3449
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchPinnedChats).call(this, update.folder_id);
3450
- const chats = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, listId);
3451
- const pinnedChats = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getPinnedChats).call(this, listId);
3452
- for (const [i, chatId] of pinnedChats.entries()) {
3453
- const chat = chats.get(chatId);
3454
- if (chat !== undefined) {
3455
- chat.order = (0, _3_types_js_1.getChatOrder)(chat.lastMessage, i);
3456
- chat.pinned = i;
3457
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
3458
- }
3459
- }
3460
- for (const chat of chats.values()) {
3461
- if (chat.pinned != -1 && pinnedChats.indexOf(chat.id) == -1) {
3462
- chat.order = (0, _3_types_js_1.getChatOrder)(chat.lastMessage, -1);
3463
- chat.pinned = -1;
3464
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chat.id, false);
3465
- }
3466
- }
3467
- await this.storage.setPinnedChats(listId, await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getPinnedChats).call(this, listId));
3468
- }, _Client_fetchChats = async function _Client_fetchChats(listId, limit, after) {
3469
- const dialogs = await this.api.messages.getDialogs({
3470
- limit,
3471
- offset_id: after?.lastMessage?.id ?? 0,
3472
- offset_date: after?.lastMessage?.date ? Math.ceil(after.lastMessage.date.getTime() / 1000) : 0,
3473
- offset_peer: after ? await this.getInputPeer(after.id) : new _2_tl_js_1.types.InputPeerEmpty(),
3474
- hash: 0n,
3475
- folder_id: listId,
3476
- });
3477
- const pinnedChats = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getPinnedChats).call(this, listId);
3478
- if (!(dialogs instanceof _2_tl_js_1.types.messages.Dialogs) && !(dialogs instanceof _2_tl_js_1.types.messages.DialogsSlice)) {
3479
- (0, _1_utilities_js_1.UNREACHABLE)();
3480
- }
3481
- if (dialogs.dialogs.length < limit) {
3482
- await this.storage.setHasAllChats(listId, true);
3483
- }
3484
- const chats = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, listId);
3485
- for (const dialog of dialogs.dialogs) {
3486
- const chat = await (0, _3_types_js_1.constructChat)(dialog, dialogs, pinnedChats, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this));
3487
- chats.set(chat.id, chat);
3488
- await this.storage.setChat(listId, chat.id, chat.pinned, chat.lastMessage?.id ?? 0, chat.lastMessage?.date ?? new Date(0));
3489
- }
3490
- }, _Client_sendReaction = async function _Client_sendReaction(chatId, messageId, reactions, params) {
3491
- await this.api.messages.sendReaction({
3492
- peer: await this.getInputPeer(chatId),
3493
- msg_id: messageId,
3494
- reaction: reactions.map((v) => (0, _3_types_js_1.reactionToTlObject)(v)),
3495
- big: params?.big ? true : undefined,
3496
- add_to_recent: params?.addToRecents ? true : undefined,
3497
- });
3498
2290
  };