@mtkruto/node 0.1.139 → 0.1.141

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (287) hide show
  1. package/esm/3_types.d.ts +10 -36
  2. package/esm/3_types.js +10 -36
  3. package/esm/4_constants.d.ts +1 -1
  4. package/esm/4_constants.js +1 -1
  5. package/esm/5_client.d.ts +1 -1
  6. package/esm/5_client.js +1 -1
  7. package/esm/_dnt.polyfills.d.ts +6 -0
  8. package/esm/client/0_filters.d.ts +60 -0
  9. package/esm/client/0_filters.js +27 -0
  10. package/esm/client/0_message.js +2 -2
  11. package/esm/client/{3_params.d.ts → 0_params.d.ts} +30 -33
  12. package/esm/client/0_types.d.ts +39 -0
  13. package/esm/client/0_types.js +2 -0
  14. package/esm/client/0_utilities.d.ts +1 -47
  15. package/esm/client/0_utilities.js +0 -27
  16. package/esm/client/1_composer.d.ts +1 -1
  17. package/esm/client/1_composer.js +1 -1
  18. package/esm/client/1_file_manager.d.ts +10 -0
  19. package/esm/client/1_file_manager.js +241 -0
  20. package/esm/client/1_update_manager.d.ts +18 -0
  21. package/esm/client/1_update_manager.js +553 -0
  22. package/esm/client/2_message_manager.d.ts +40 -0
  23. package/esm/client/2_message_manager.js +621 -0
  24. package/esm/client/3_chat_list_manager.d.ts +21 -0
  25. package/esm/client/3_chat_list_manager.js +353 -0
  26. package/esm/client/3_reaction_manager.d.ts +16 -0
  27. package/esm/client/3_reaction_manager.js +61 -0
  28. package/esm/client/4_client.d.ts +187 -60
  29. package/esm/client/4_client.js +492 -1698
  30. package/esm/connection/1_connection_web_socket.js +6 -6
  31. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/main/deps.d.ts +1 -1
  32. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/main/deps.js +1 -1
  33. package/esm/deps/raw.githubusercontent.com/MTKruto/object-inspect/main/index.d.ts +1 -0
  34. package/esm/deps/raw.githubusercontent.com/MTKruto/object-inspect/main/index.js +524 -0
  35. package/esm/mod.d.ts +1 -0
  36. package/esm/mod.js +1 -0
  37. package/esm/storage/0_storage.d.ts +5 -3
  38. package/esm/storage/0_storage.js +14 -4
  39. package/esm/tl/1_tl_object.d.ts +1 -0
  40. package/esm/tl/1_tl_object.js +24 -0
  41. package/esm/types/0_bot_command.d.ts +1 -0
  42. package/esm/types/0_chat_member_rights.d.ts +37 -0
  43. package/esm/types/0_chat_photo.d.ts +4 -4
  44. package/esm/types/0_file_source.d.ts +5 -0
  45. package/esm/types/0_giveaway_parameters.js +2 -1
  46. package/esm/types/0_id.d.ts +4 -0
  47. package/esm/types/0_message_entity.d.ts +20 -20
  48. package/esm/types/1__getters.d.ts +2 -2
  49. package/esm/types/1_animation.d.ts +1 -1
  50. package/esm/types/1_bot_command_scope.d.ts +5 -4
  51. package/esm/types/1_chat_p.d.ts +5 -6
  52. package/esm/types/1_document.d.ts +1 -0
  53. package/esm/types/1_input_message_content.d.ts +88 -0
  54. package/esm/types/1_photo.d.ts +1 -1
  55. package/esm/types/1_sticker.d.ts +1 -1
  56. package/esm/types/1_user.d.ts +1 -1
  57. package/esm/types/1_video.d.ts +1 -1
  58. package/esm/types/1_video_note.d.ts +1 -1
  59. package/esm/types/2_inline_keyboard_button.d.ts +10 -10
  60. package/esm/types/2_message_reaction_count.d.ts +3 -0
  61. package/esm/types/2_message_reaction_count.js +17 -1
  62. package/esm/types/2_message_reactions.d.ts +15 -0
  63. package/esm/types/2_message_reactions.js +37 -0
  64. package/esm/types/3_reply_markup.d.ts +42 -0
  65. package/esm/types/3_reply_markup.js +117 -0
  66. package/esm/types/4_inline_query_result.d.ts +193 -0
  67. package/esm/types/{5_inline_query_result.js → 4_inline_query_result.js} +2 -2
  68. package/esm/types/4_message.d.ts +36 -39
  69. package/esm/types/4_message.js +7 -24
  70. package/esm/types/5_callback_query.d.ts +2 -1
  71. package/esm/types/5_chat.d.ts +8 -5
  72. package/esm/types/6_update.d.ts +12 -2
  73. package/esm/utilities/0_buffer.js +9 -6
  74. package/esm/utilities/0_object.d.ts +1 -1
  75. package/esm/utilities/0_object.js +1 -6
  76. package/esm/utilities/1_misc.d.ts +2 -0
  77. package/esm/utilities/1_misc.js +6 -0
  78. package/package.json +1 -2
  79. package/script/3_types.d.ts +10 -36
  80. package/script/3_types.js +10 -36
  81. package/script/4_constants.d.ts +1 -1
  82. package/script/4_constants.js +1 -1
  83. package/script/5_client.d.ts +1 -1
  84. package/script/5_client.js +1 -1
  85. package/script/_dnt.polyfills.d.ts +6 -0
  86. package/script/client/0_filters.d.ts +60 -0
  87. package/script/client/0_filters.js +31 -0
  88. package/script/client/0_message.js +1 -1
  89. package/script/client/{3_params.d.ts → 0_params.d.ts} +30 -33
  90. package/script/client/0_types.d.ts +39 -0
  91. package/script/client/0_types.js +6 -0
  92. package/script/client/0_utilities.d.ts +1 -47
  93. package/script/client/0_utilities.js +1 -29
  94. package/script/client/1_composer.d.ts +1 -1
  95. package/script/client/1_composer.js +2 -2
  96. package/script/client/1_file_manager.d.ts +10 -0
  97. package/script/client/1_file_manager.js +245 -0
  98. package/script/client/1_update_manager.d.ts +18 -0
  99. package/script/client/1_update_manager.js +557 -0
  100. package/script/client/2_message_manager.d.ts +40 -0
  101. package/script/client/2_message_manager.js +625 -0
  102. package/script/client/3_chat_list_manager.d.ts +21 -0
  103. package/script/client/3_chat_list_manager.js +357 -0
  104. package/script/client/3_reaction_manager.d.ts +16 -0
  105. package/script/client/3_reaction_manager.js +65 -0
  106. package/script/client/4_client.d.ts +187 -60
  107. package/script/client/4_client.js +491 -1698
  108. package/script/connection/1_connection_web_socket.js +5 -5
  109. package/script/deps/raw.githubusercontent.com/MTKruto/debug/main/deps.d.ts +1 -1
  110. package/script/deps/raw.githubusercontent.com/MTKruto/debug/main/deps.js +2 -2
  111. package/script/deps/raw.githubusercontent.com/MTKruto/object-inspect/main/index.d.ts +1 -0
  112. package/script/deps/raw.githubusercontent.com/MTKruto/object-inspect/main/index.js +550 -0
  113. package/script/mod.d.ts +1 -0
  114. package/script/mod.js +1 -0
  115. package/script/storage/0_storage.d.ts +5 -3
  116. package/script/storage/0_storage.js +14 -4
  117. package/script/tl/1_tl_object.d.ts +1 -0
  118. package/script/tl/1_tl_object.js +24 -0
  119. package/script/types/0_bot_command.d.ts +1 -0
  120. package/script/types/0_chat_member_rights.d.ts +37 -0
  121. package/script/types/0_chat_photo.d.ts +4 -4
  122. package/script/types/0_file_source.d.ts +5 -0
  123. package/script/types/0_giveaway_parameters.js +2 -1
  124. package/script/types/0_id.d.ts +4 -0
  125. package/script/types/0_message_entity.d.ts +20 -20
  126. package/script/types/1__getters.d.ts +2 -2
  127. package/script/types/1_animation.d.ts +1 -1
  128. package/script/types/1_bot_command_scope.d.ts +5 -4
  129. package/script/types/1_chat_p.d.ts +5 -6
  130. package/script/types/1_document.d.ts +1 -0
  131. package/script/types/1_input_message_content.d.ts +88 -0
  132. package/script/types/1_photo.d.ts +1 -1
  133. package/script/types/1_sticker.d.ts +1 -1
  134. package/script/types/1_user.d.ts +1 -1
  135. package/script/types/1_video.d.ts +1 -1
  136. package/script/types/1_video_note.d.ts +1 -1
  137. package/script/types/2_inline_keyboard_button.d.ts +10 -10
  138. package/script/types/2_message_reaction_count.d.ts +3 -0
  139. package/script/types/2_message_reaction_count.js +19 -0
  140. package/script/types/2_message_reactions.d.ts +15 -0
  141. package/script/types/2_message_reactions.js +41 -0
  142. package/script/types/3_reply_markup.d.ts +42 -0
  143. package/script/types/3_reply_markup.js +122 -0
  144. package/script/types/4_inline_query_result.d.ts +193 -0
  145. package/script/types/{5_inline_query_result.js → 4_inline_query_result.js} +3 -3
  146. package/script/types/4_message.d.ts +36 -39
  147. package/script/types/4_message.js +6 -23
  148. package/script/types/5_callback_query.d.ts +2 -1
  149. package/script/types/5_chat.d.ts +8 -5
  150. package/script/types/6_update.d.ts +12 -2
  151. package/script/utilities/0_buffer.js +9 -6
  152. package/script/utilities/0_object.d.ts +1 -1
  153. package/script/utilities/0_object.js +1 -6
  154. package/script/utilities/1_misc.d.ts +2 -0
  155. package/script/utilities/1_misc.js +9 -1
  156. package/esm/types/0_chat_id.d.ts +0 -4
  157. package/esm/types/0_force_reply.d.ts +0 -12
  158. package/esm/types/0_force_reply.js +0 -17
  159. package/esm/types/0_input_contact_message_content.d.ts +0 -11
  160. package/esm/types/0_input_location_message_content.d.ts +0 -15
  161. package/esm/types/0_input_venue_message_content.d.ts +0 -19
  162. package/esm/types/0_reply_keyboard_remove.d.ts +0 -10
  163. package/esm/types/0_reply_keyboard_remove.js +0 -8
  164. package/esm/types/1_input_invoice_message_content.d.ts +0 -23
  165. package/esm/types/1_input_text_message_content.d.ts +0 -8
  166. package/esm/types/1_input_text_message_content.js +0 -1
  167. package/esm/types/2_input_message_content.d.ts +0 -6
  168. package/esm/types/2_input_message_content.js +0 -1
  169. package/esm/types/2_reply_keyboard_markup.d.ts +0 -12
  170. package/esm/types/2_reply_keyboard_markup.js +0 -37
  171. package/esm/types/3_inline_keyboard_markup.d.ts +0 -8
  172. package/esm/types/3_inline_keyboard_markup.js +0 -24
  173. package/esm/types/4_inline_query_result_article.d.ts +0 -15
  174. package/esm/types/4_inline_query_result_article.js +0 -1
  175. package/esm/types/4_inline_query_result_audio.d.ts +0 -17
  176. package/esm/types/4_inline_query_result_audio.js +0 -1
  177. package/esm/types/4_inline_query_result_cached_audio.d.ts +0 -14
  178. package/esm/types/4_inline_query_result_cached_audio.js +0 -1
  179. package/esm/types/4_inline_query_result_cached_document.d.ts +0 -15
  180. package/esm/types/4_inline_query_result_cached_document.js +0 -1
  181. package/esm/types/4_inline_query_result_cached_gif.d.ts +0 -15
  182. package/esm/types/4_inline_query_result_cached_gif.js +0 -1
  183. package/esm/types/4_inline_query_result_cached_mpeg4_gif.d.ts +0 -15
  184. package/esm/types/4_inline_query_result_cached_mpeg4_gif.js +0 -1
  185. package/esm/types/4_inline_query_result_cached_photo.d.ts +0 -16
  186. package/esm/types/4_inline_query_result_cached_photo.js +0 -1
  187. package/esm/types/4_inline_query_result_cached_sticker.d.ts +0 -9
  188. package/esm/types/4_inline_query_result_cached_sticker.js +0 -1
  189. package/esm/types/4_inline_query_result_cached_video.d.ts +0 -16
  190. package/esm/types/4_inline_query_result_cached_video.js +0 -1
  191. package/esm/types/4_inline_query_result_cached_voice.d.ts +0 -15
  192. package/esm/types/4_inline_query_result_cached_voice.js +0 -1
  193. package/esm/types/4_inline_query_result_contact.d.ts +0 -15
  194. package/esm/types/4_inline_query_result_contact.js +0 -1
  195. package/esm/types/4_inline_query_result_document.d.ts +0 -18
  196. package/esm/types/4_inline_query_result_document.js +0 -1
  197. package/esm/types/4_inline_query_result_game.d.ts +0 -7
  198. package/esm/types/4_inline_query_result_game.js +0 -1
  199. package/esm/types/4_inline_query_result_gif.d.ts +0 -20
  200. package/esm/types/4_inline_query_result_gif.js +0 -1
  201. package/esm/types/4_inline_query_result_location.d.ts +0 -18
  202. package/esm/types/4_inline_query_result_location.js +0 -1
  203. package/esm/types/4_inline_query_result_mpeg4_gif.d.ts +0 -20
  204. package/esm/types/4_inline_query_result_mpeg4_gif.js +0 -1
  205. package/esm/types/4_inline_query_result_photo.d.ts +0 -19
  206. package/esm/types/4_inline_query_result_photo.js +0 -1
  207. package/esm/types/4_inline_query_result_venue.d.ts +0 -19
  208. package/esm/types/4_inline_query_result_venue.js +0 -1
  209. package/esm/types/4_inline_query_result_video.d.ts +0 -21
  210. package/esm/types/4_inline_query_result_video.js +0 -1
  211. package/esm/types/4_inline_query_result_voice.d.ts +0 -16
  212. package/esm/types/4_inline_query_result_voice.js +0 -1
  213. package/esm/types/4_reply_markup.d.ts +0 -7
  214. package/esm/types/4_reply_markup.js +0 -22
  215. package/esm/types/5_inline_query_result.d.ts +0 -28
  216. package/script/types/0_chat_id.d.ts +0 -4
  217. package/script/types/0_force_reply.d.ts +0 -12
  218. package/script/types/0_force_reply.js +0 -22
  219. package/script/types/0_input_contact_message_content.d.ts +0 -11
  220. package/script/types/0_input_location_message_content.d.ts +0 -15
  221. package/script/types/0_input_venue_message_content.d.ts +0 -19
  222. package/script/types/0_reply_keyboard_remove.d.ts +0 -10
  223. package/script/types/0_reply_keyboard_remove.js +0 -13
  224. package/script/types/1_input_invoice_message_content.d.ts +0 -23
  225. package/script/types/1_input_text_message_content.d.ts +0 -8
  226. package/script/types/1_input_text_message_content.js +0 -2
  227. package/script/types/2_input_message_content.d.ts +0 -6
  228. package/script/types/2_input_message_content.js +0 -2
  229. package/script/types/2_reply_keyboard_markup.d.ts +0 -12
  230. package/script/types/2_reply_keyboard_markup.js +0 -42
  231. package/script/types/3_inline_keyboard_markup.d.ts +0 -8
  232. package/script/types/3_inline_keyboard_markup.js +0 -29
  233. package/script/types/4_inline_query_result_article.d.ts +0 -15
  234. package/script/types/4_inline_query_result_article.js +0 -2
  235. package/script/types/4_inline_query_result_audio.d.ts +0 -17
  236. package/script/types/4_inline_query_result_audio.js +0 -2
  237. package/script/types/4_inline_query_result_cached_audio.d.ts +0 -14
  238. package/script/types/4_inline_query_result_cached_audio.js +0 -2
  239. package/script/types/4_inline_query_result_cached_document.d.ts +0 -15
  240. package/script/types/4_inline_query_result_cached_document.js +0 -2
  241. package/script/types/4_inline_query_result_cached_gif.d.ts +0 -15
  242. package/script/types/4_inline_query_result_cached_gif.js +0 -2
  243. package/script/types/4_inline_query_result_cached_mpeg4_gif.d.ts +0 -15
  244. package/script/types/4_inline_query_result_cached_mpeg4_gif.js +0 -2
  245. package/script/types/4_inline_query_result_cached_photo.d.ts +0 -16
  246. package/script/types/4_inline_query_result_cached_photo.js +0 -2
  247. package/script/types/4_inline_query_result_cached_sticker.d.ts +0 -9
  248. package/script/types/4_inline_query_result_cached_sticker.js +0 -2
  249. package/script/types/4_inline_query_result_cached_video.d.ts +0 -16
  250. package/script/types/4_inline_query_result_cached_video.js +0 -2
  251. package/script/types/4_inline_query_result_cached_voice.d.ts +0 -15
  252. package/script/types/4_inline_query_result_cached_voice.js +0 -2
  253. package/script/types/4_inline_query_result_contact.d.ts +0 -15
  254. package/script/types/4_inline_query_result_contact.js +0 -2
  255. package/script/types/4_inline_query_result_document.d.ts +0 -18
  256. package/script/types/4_inline_query_result_document.js +0 -2
  257. package/script/types/4_inline_query_result_game.d.ts +0 -7
  258. package/script/types/4_inline_query_result_game.js +0 -2
  259. package/script/types/4_inline_query_result_gif.d.ts +0 -20
  260. package/script/types/4_inline_query_result_gif.js +0 -2
  261. package/script/types/4_inline_query_result_location.d.ts +0 -18
  262. package/script/types/4_inline_query_result_location.js +0 -2
  263. package/script/types/4_inline_query_result_mpeg4_gif.d.ts +0 -20
  264. package/script/types/4_inline_query_result_mpeg4_gif.js +0 -2
  265. package/script/types/4_inline_query_result_photo.d.ts +0 -19
  266. package/script/types/4_inline_query_result_photo.js +0 -2
  267. package/script/types/4_inline_query_result_venue.d.ts +0 -19
  268. package/script/types/4_inline_query_result_venue.js +0 -2
  269. package/script/types/4_inline_query_result_video.d.ts +0 -21
  270. package/script/types/4_inline_query_result_video.js +0 -2
  271. package/script/types/4_inline_query_result_voice.d.ts +0 -16
  272. package/script/types/4_inline_query_result_voice.js +0 -2
  273. package/script/types/4_reply_markup.d.ts +0 -7
  274. package/script/types/4_reply_markup.js +0 -26
  275. package/script/types/5_inline_query_result.d.ts +0 -28
  276. /package/esm/{client/3_params.js → _dnt.polyfills.js} +0 -0
  277. /package/esm/{types/0_chat_id.js → client/0_params.js} +0 -0
  278. /package/esm/types/{0_input_contact_message_content.js → 0_chat_member_rights.js} +0 -0
  279. /package/esm/types/{0_input_location_message_content.js → 0_file_source.js} +0 -0
  280. /package/esm/types/{0_input_venue_message_content.js → 0_id.js} +0 -0
  281. /package/esm/types/{1_input_invoice_message_content.js → 1_input_message_content.js} +0 -0
  282. /package/script/{client/3_params.js → _dnt.polyfills.js} +0 -0
  283. /package/script/{types/0_chat_id.js → client/0_params.js} +0 -0
  284. /package/script/types/{0_input_contact_message_content.js → 0_chat_member_rights.js} +0 -0
  285. /package/script/types/{0_input_location_message_content.js → 0_file_source.js} +0 -0
  286. /package/script/types/{0_input_venue_message_content.js → 0_id.js} +0 -0
  287. /package/script/types/{1_input_invoice_message_content.js → 1_input_message_content.js} +0 -0
@@ -0,0 +1,553 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _UpdateManager_instances, _a, _UpdateManager_c, _UpdateManager_updateState, _UpdateManager_updateHandler, _UpdateManager_handleUpdateQueues, _UpdateManager_checkGap, _UpdateManager_checkChannelGap, _UpdateManager_channelUpdateQueues, _UpdateManager_processChannelPtsUpdateInner, _UpdateManager_queueUpdate, _UpdateManager_processChannelPtsUpdate, _UpdateManager_processPtsUpdateInner, _UpdateManager_ptsUpdateQueue, _UpdateManager_processPtsUpdate, _UpdateManager_processUpdatesQueue, _UpdateManager_processUpdates, _UpdateManager_setUpdateStateDate, _UpdateManager_setUpdatePts, _UpdateManager_getLocalState, _UpdateManager_recoverChannelUpdateGap, _UpdateManager_handleUpdatesSet, _UpdateManager_handleStoredUpdates, _UpdateManager_handleUpdate;
13
+ import { debug } from "../0_deps.js";
14
+ import { Queue, UNREACHABLE, ZERO_CHANNEL_ID } from "../1_utilities.js";
15
+ import { as, functions, inputPeerToPeer, peerToChatId, types } from "../2_tl.js";
16
+ import { CHANNEL_DIFFERENCE_LIMIT_BOT, CHANNEL_DIFFERENCE_LIMIT_USER } from "../4_constants.js";
17
+ import { isChannelPtsUpdate, isPtsUpdate } from "./0_utilities.js";
18
+ const d = debug("UpdateManager");
19
+ const dGap = debug("UpdateManager/recoverUpdateGap");
20
+ const dGapC = debug("UpdateManager/recoverChannelUpdateGap");
21
+ export class UpdateManager {
22
+ constructor(c) {
23
+ _UpdateManager_instances.add(this);
24
+ _UpdateManager_c.set(this, void 0);
25
+ _UpdateManager_updateState.set(this, void 0);
26
+ _UpdateManager_updateHandler.set(this, void 0);
27
+ _UpdateManager_handleUpdateQueues.set(this, new Map());
28
+ _UpdateManager_channelUpdateQueues.set(this, new Map());
29
+ _UpdateManager_ptsUpdateQueue.set(this, new Queue("ptsUpdate"));
30
+ _UpdateManager_processUpdatesQueue.set(this, new Queue("UpdateManager/processUpdates"));
31
+ _UpdateManager_handleUpdatesSet.set(this, new Set());
32
+ __classPrivateFieldSet(this, _UpdateManager_c, c, "f");
33
+ }
34
+ async fetchState(source) {
35
+ const state = await __classPrivateFieldGet(this, _UpdateManager_c, "f").api.updates.getState();
36
+ __classPrivateFieldSet(this, _UpdateManager_updateState, state, "f");
37
+ d("state fetched [%s]", source);
38
+ }
39
+ async processChats(chats) {
40
+ for (const chat of chats) {
41
+ if (chat instanceof types.Channel && chat.access_hash) {
42
+ await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.setEntity(chat);
43
+ await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.setChannelAccessHash(chat.id, chat.access_hash);
44
+ if (chat.username) {
45
+ await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.updateUsernames("channel", chat.id, [chat.username]);
46
+ }
47
+ if (chat.usernames) {
48
+ await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.updateUsernames("channel", chat.id, chat.usernames.map((v) => v.username));
49
+ }
50
+ }
51
+ else if (chat instanceof types.Chat) {
52
+ await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.setEntity(chat);
53
+ }
54
+ else if (chat instanceof types.ChannelForbidden || chat instanceof types.ChatForbidden) {
55
+ await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.removeEntity(chat);
56
+ }
57
+ }
58
+ }
59
+ async processResult(result) {
60
+ if (result instanceof types.messages.Dialogs ||
61
+ result instanceof types.messages.DialogsSlice ||
62
+ result instanceof types.messages.Messages ||
63
+ result instanceof types.messages.MessagesSlice ||
64
+ result instanceof types.messages.ChannelMessages ||
65
+ result instanceof types.messages.ChatFull ||
66
+ result instanceof types.contacts.Found ||
67
+ result instanceof types.account.PrivacyRules ||
68
+ result instanceof types.contacts.ResolvedPeer ||
69
+ result instanceof types.channels.ChannelParticipants ||
70
+ result instanceof types.channels.ChannelParticipant ||
71
+ result instanceof types.messages.PeerDialogs ||
72
+ result instanceof types.contacts.TopPeers ||
73
+ result instanceof types.channels.AdminLogResults ||
74
+ result instanceof types.help.RecentMeUrls ||
75
+ result instanceof types.messages.InactiveChats ||
76
+ result instanceof types.help.PromoData ||
77
+ result instanceof types.messages.MessageViews ||
78
+ result instanceof types.messages.DiscussionMessage ||
79
+ result instanceof types.phone.GroupCall ||
80
+ result instanceof types.phone.GroupParticipants ||
81
+ result instanceof types.phone.JoinAsPeers ||
82
+ result instanceof types.messages.SponsoredMessages ||
83
+ result instanceof types.messages.SearchResultsCalendar ||
84
+ result instanceof types.channels.SendAsPeers ||
85
+ result instanceof types.users.UserFull ||
86
+ result instanceof types.messages.PeerSettings ||
87
+ result instanceof types.messages.MessageReactionsList ||
88
+ result instanceof types.messages.ForumTopics ||
89
+ result instanceof types.account.AutoSaveSettings ||
90
+ result instanceof types.chatlists.ExportedInvites ||
91
+ result instanceof types.chatlists.ChatlistInviteAlready ||
92
+ result instanceof types.chatlists.ChatlistInvite ||
93
+ result instanceof types.chatlists.ChatlistUpdates ||
94
+ result instanceof types.messages.Chats ||
95
+ result instanceof types.messages.ChatsSlice) {
96
+ await this.processChats(result.chats);
97
+ if ("users" in result) {
98
+ await this.processUsers(result.users);
99
+ }
100
+ if ("messages" in result) {
101
+ for (const message of result.messages) {
102
+ if (message instanceof types.Message || message instanceof types.MessageService) {
103
+ await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.setMessage(peerToChatId(message.peer_id), message.id, message);
104
+ }
105
+ }
106
+ }
107
+ }
108
+ if (result instanceof types.messages.Messages) {
109
+ for (const message of result.messages) {
110
+ if (message instanceof types.Message || message instanceof types.MessageService) {
111
+ await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.setMessage(peerToChatId(message.peer_id), message.id, message);
112
+ }
113
+ }
114
+ }
115
+ }
116
+ async processUsers(users) {
117
+ for (const user of users) {
118
+ if (user instanceof types.User && user.access_hash) {
119
+ await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.setEntity(user);
120
+ await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.setUserAccessHash(user.id, user.access_hash);
121
+ if (user.username) {
122
+ await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.updateUsernames("user", user.id, [user.username]);
123
+ }
124
+ if (user.usernames) {
125
+ await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.updateUsernames("user", user.id, user.usernames.map((v) => v.username));
126
+ }
127
+ }
128
+ }
129
+ }
130
+ getHandleUpdateQueue(boxId) {
131
+ let queue = __classPrivateFieldGet(this, _UpdateManager_handleUpdateQueues, "f").get(boxId);
132
+ if (queue !== undefined) {
133
+ return queue;
134
+ }
135
+ else {
136
+ queue = new Queue(`handleUpdate-${boxId}`);
137
+ return queue;
138
+ }
139
+ }
140
+ processUpdates(updates, checkGap, call = null, callback) {
141
+ __classPrivateFieldGet(this, _UpdateManager_processUpdatesQueue, "f").add(() => __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_processUpdates).call(this, updates, checkGap, call).then(callback));
142
+ }
143
+ async recoverUpdateGap(source) {
144
+ dGap("recovering from update gap [%s]", source);
145
+ __classPrivateFieldGet(this, _UpdateManager_c, "f").setConnectionState("updating");
146
+ try {
147
+ let state = await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_getLocalState).call(this);
148
+ while (true) {
149
+ const difference = await __classPrivateFieldGet(this, _UpdateManager_c, "f").api.updates.getDifference({ pts: state.pts, date: state.date, qts: state.qts ?? 0 });
150
+ if (difference instanceof types.updates.Difference || difference instanceof types.updates.DifferenceSlice) {
151
+ await this.processChats(difference.chats);
152
+ await this.processUsers(difference.users);
153
+ for (const message of difference.new_messages) {
154
+ await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_processUpdates).call(this, new types.UpdateNewMessage({ message, pts: 0, pts_count: 0 }), false);
155
+ }
156
+ for (const update of difference.other_updates) {
157
+ await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_processUpdates).call(this, update, false);
158
+ }
159
+ if (difference instanceof types.updates.Difference) {
160
+ await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.setState(difference.state);
161
+ dGap("recovered from update gap");
162
+ break;
163
+ }
164
+ else if (difference instanceof types.updates.DifferenceSlice) {
165
+ state = difference.intermediate_state;
166
+ }
167
+ else {
168
+ UNREACHABLE();
169
+ }
170
+ }
171
+ else if (difference instanceof types.updates.DifferenceTooLong) {
172
+ await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.deleteMessages();
173
+ await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.removeChats(0);
174
+ await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.removeChats(1);
175
+ state.pts = difference.pts;
176
+ dGap("received differenceTooLong");
177
+ }
178
+ else if (difference instanceof types.updates.DifferenceEmpty) {
179
+ await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_setUpdateStateDate).call(this, difference.date);
180
+ dGap("there was no update gap");
181
+ break;
182
+ }
183
+ else {
184
+ UNREACHABLE();
185
+ }
186
+ }
187
+ }
188
+ finally {
189
+ __classPrivateFieldGet(this, _UpdateManager_c, "f").resetConnectionState();
190
+ }
191
+ }
192
+ setUpdateHandler(handler) {
193
+ __classPrivateFieldSet(this, _UpdateManager_updateHandler, handler, "f");
194
+ }
195
+ }
196
+ _a = UpdateManager, _UpdateManager_c = new WeakMap(), _UpdateManager_updateState = new WeakMap(), _UpdateManager_updateHandler = new WeakMap(), _UpdateManager_handleUpdateQueues = new WeakMap(), _UpdateManager_channelUpdateQueues = new WeakMap(), _UpdateManager_ptsUpdateQueue = new WeakMap(), _UpdateManager_processUpdatesQueue = new WeakMap(), _UpdateManager_handleUpdatesSet = new WeakMap(), _UpdateManager_instances = new WeakSet(), _UpdateManager_checkGap = async function _UpdateManager_checkGap(pts, ptsCount) {
197
+ const localState = await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_getLocalState).call(this);
198
+ if (localState.pts + ptsCount < pts) {
199
+ await this.recoverUpdateGap("processUpdates");
200
+ }
201
+ }, _UpdateManager_checkChannelGap = async function _UpdateManager_checkChannelGap(channelId, pts, ptsCount) {
202
+ let localPts = await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.getChannelPts(channelId);
203
+ if (!localPts) {
204
+ localPts = pts - ptsCount;
205
+ }
206
+ if (localPts + ptsCount < pts) {
207
+ await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_recoverChannelUpdateGap).call(this, channelId, "processUpdates");
208
+ }
209
+ }, _UpdateManager_processChannelPtsUpdateInner = async function _UpdateManager_processChannelPtsUpdateInner(update, checkGap) {
210
+ const channelId = update instanceof types.UpdateNewChannelMessage || update instanceof types.UpdateEditChannelMessage ? update.message.peer_id[as](types.PeerChannel).channel_id : update.channel_id;
211
+ if (update instanceof types.UpdateChannelTooLong) {
212
+ if (update.pts != undefined) {
213
+ await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.setChannelPts(channelId, update.pts);
214
+ }
215
+ await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_recoverChannelUpdateGap).call(this, channelId, "updateChannelTooLong");
216
+ return;
217
+ }
218
+ if (update.pts != 0) {
219
+ const ptsCount = update.pts_count;
220
+ if (checkGap) {
221
+ await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_checkChannelGap).call(this, channelId, update.pts, ptsCount);
222
+ }
223
+ let currentPts = await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.getChannelPts(channelId);
224
+ currentPts ??= update.pts - ptsCount;
225
+ if (currentPts + ptsCount > update.pts) {
226
+ return;
227
+ }
228
+ }
229
+ if (__classPrivateFieldGet(this, _UpdateManager_c, "f").guaranteeUpdateDelivery) {
230
+ await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.setUpdate(channelId, update);
231
+ }
232
+ if (update.pts != 0) {
233
+ await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.setChannelPts(channelId, update.pts);
234
+ }
235
+ __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_queueUpdate).call(this, update, channelId, true);
236
+ }, _UpdateManager_queueUpdate = function _UpdateManager_queueUpdate(update, boxId, pts) {
237
+ this.getHandleUpdateQueue(boxId).add(async () => {
238
+ if (__classPrivateFieldGet(this, _UpdateManager_c, "f").guaranteeUpdateDelivery && pts) {
239
+ await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_handleStoredUpdates).call(this, boxId);
240
+ }
241
+ else {
242
+ await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_handleUpdate).call(this, update);
243
+ }
244
+ });
245
+ }, _UpdateManager_processChannelPtsUpdate = function _UpdateManager_processChannelPtsUpdate(update, checkGap) {
246
+ const channelId = update instanceof types.UpdateNewChannelMessage || update instanceof types.UpdateEditChannelMessage ? update.message.peer_id[as](types.PeerChannel).channel_id : update.channel_id;
247
+ let queue = __classPrivateFieldGet(this, _UpdateManager_channelUpdateQueues, "f").get(channelId);
248
+ if (queue == undefined) {
249
+ queue = new Queue(`channelUpdates-${channelId}`);
250
+ __classPrivateFieldGet(this, _UpdateManager_channelUpdateQueues, "f").set(channelId, queue);
251
+ }
252
+ queue.add(async () => {
253
+ await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_processChannelPtsUpdateInner).call(this, update, checkGap);
254
+ });
255
+ }, _UpdateManager_processPtsUpdateInner = async function _UpdateManager_processPtsUpdateInner(update, checkGap) {
256
+ const localState = await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_getLocalState).call(this);
257
+ if (update.pts != 0) {
258
+ if (checkGap) {
259
+ await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_checkGap).call(this, update.pts, update.pts_count);
260
+ }
261
+ if (localState.pts + update.pts_count > update.pts) {
262
+ return;
263
+ }
264
+ }
265
+ if (__classPrivateFieldGet(this, _UpdateManager_c, "f").guaranteeUpdateDelivery) {
266
+ await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.setUpdate(_a.MAIN_BOX_ID, update);
267
+ }
268
+ if (update.pts != 0) {
269
+ await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_setUpdatePts).call(this, update.pts);
270
+ }
271
+ __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_queueUpdate).call(this, update, 0n, true);
272
+ }, _UpdateManager_processPtsUpdate = function _UpdateManager_processPtsUpdate(update, checkGap) {
273
+ __classPrivateFieldGet(this, _UpdateManager_ptsUpdateQueue, "f").add(async () => {
274
+ await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_processPtsUpdateInner).call(this, update, checkGap);
275
+ });
276
+ }, _UpdateManager_processUpdates = async function _UpdateManager_processUpdates(updates_, checkGap, call = null) {
277
+ /// First, individual updates (Update[1]) are extracted from Updates.[2]
278
+ ///
279
+ /// If an updatesTooLong[3] was received, an update gap recovery is initiated and no further action will be taken.
280
+ ///
281
+ /// [1]: https://core.telegram.org/type/Update
282
+ /// [2]: https://core.telegram.org/type/Updates
283
+ /// [3]: https://core.telegram.org/constructor/updatesTooLong
284
+ let updates;
285
+ if (updates_ instanceof types.UpdatesCombined || updates_ instanceof types.Updates) {
286
+ updates = updates_.updates;
287
+ const seq = updates_.seq;
288
+ const seqStart = "seq_start" in updates_ ? updates_.seq_start : updates_.seq;
289
+ if (checkGap) {
290
+ if (seqStart == 0) {
291
+ checkGap = false;
292
+ d("seqStart=0");
293
+ }
294
+ else {
295
+ const localState = await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_getLocalState).call(this);
296
+ const localSeq = localState.seq;
297
+ if (localSeq + 1 == seqStart) {
298
+ // The update sequence can be applied.
299
+ localState.seq = seq;
300
+ localState.date = updates_.date;
301
+ await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_setUpdateStateDate).call(this, updates_.date);
302
+ await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.setState(localState);
303
+ }
304
+ else if (localSeq + 1 > seqStart) {
305
+ // The update sequence was already applied, and must be ignored.
306
+ d("localSeq + 1 > seqStart");
307
+ return;
308
+ }
309
+ else if (localSeq + 1 < seqStart) {
310
+ // There's an updates gap that must be filled.
311
+ await this.recoverUpdateGap("localSeq + 1 < seqStart");
312
+ }
313
+ }
314
+ }
315
+ }
316
+ else if (updates_ instanceof types.UpdateShort) {
317
+ updates = [updates_.update];
318
+ }
319
+ else if (updates_ instanceof types.UpdateShortMessage) {
320
+ updates = [
321
+ new types.UpdateNewMessage({
322
+ message: new types.Message({
323
+ out: updates_.out,
324
+ mentioned: updates_.mentioned,
325
+ media_unread: updates_.media_unread,
326
+ silent: updates_.silent,
327
+ id: updates_.id,
328
+ from_id: updates_.out ? new types.PeerUser({ user_id: await __classPrivateFieldGet(this, _UpdateManager_c, "f").getSelfId().then(BigInt) }) : new types.PeerUser({ user_id: updates_.user_id }),
329
+ peer_id: new types.PeerUser({ user_id: updates_.user_id }),
330
+ message: updates_.message,
331
+ date: updates_.date,
332
+ fwd_from: updates_.fwd_from,
333
+ via_bot_id: updates_.via_bot_id,
334
+ reply_to: updates_.reply_to,
335
+ entities: updates_.entities,
336
+ ttl_period: updates_.ttl_period,
337
+ }),
338
+ pts: updates_.pts,
339
+ pts_count: updates_.pts_count,
340
+ }),
341
+ ];
342
+ }
343
+ else if (updates_ instanceof types.UpdateShortChatMessage) {
344
+ updates = [
345
+ new types.UpdateNewMessage({
346
+ message: new types.Message({
347
+ out: updates_.out,
348
+ mentioned: updates_.mentioned,
349
+ media_unread: updates_.media_unread,
350
+ silent: updates_.silent,
351
+ id: updates_.id,
352
+ from_id: new types.PeerUser({ user_id: updates_.from_id }),
353
+ peer_id: new types.PeerChat({ chat_id: updates_.chat_id }),
354
+ fwd_from: updates_.fwd_from,
355
+ via_bot_id: updates_.via_bot_id,
356
+ reply_to: updates_.reply_to,
357
+ date: updates_.date,
358
+ message: updates_.message,
359
+ entities: updates_.entities,
360
+ ttl_period: updates_.ttl_period,
361
+ }),
362
+ pts: updates_.pts,
363
+ pts_count: updates_.pts_count,
364
+ }),
365
+ ];
366
+ }
367
+ else if (updates_ instanceof types.UpdateShortSentMessage) {
368
+ if (!(call instanceof functions.messages.sendMessage)) {
369
+ UNREACHABLE();
370
+ }
371
+ updates = [
372
+ new types.UpdateNewMessage({
373
+ message: new types.Message({
374
+ out: updates_.out,
375
+ silent: call.silent,
376
+ id: updates_.id,
377
+ from_id: new types.PeerUser({ user_id: await __classPrivateFieldGet(this, _UpdateManager_c, "f").getSelfId().then(BigInt) }),
378
+ peer_id: inputPeerToPeer(call.peer),
379
+ message: call.message,
380
+ media: updates_.media,
381
+ date: updates_.date,
382
+ // reply_to: call.reply_to, // TODO?
383
+ entities: updates_.entities,
384
+ ttl_period: updates_.ttl_period,
385
+ }),
386
+ pts: updates_.pts,
387
+ pts_count: updates_.pts_count,
388
+ }),
389
+ ];
390
+ }
391
+ else if (updates_ instanceof types.UpdatesTooLong) {
392
+ await this.recoverUpdateGap("updatesTooLong");
393
+ return;
394
+ }
395
+ else if (updates_ instanceof types._Update) {
396
+ updates = [updates_];
397
+ }
398
+ else {
399
+ UNREACHABLE();
400
+ }
401
+ /// We process the updates when we are sure there is no gap.
402
+ if (updates_ instanceof types.Updates || updates_ instanceof types.UpdatesCombined) {
403
+ await this.processChats(updates_.chats);
404
+ await this.processUsers(updates_.users);
405
+ await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_setUpdateStateDate).call(this, updates_.date);
406
+ }
407
+ else if (updates_ instanceof types.UpdateShort ||
408
+ updates_ instanceof types.UpdateShortMessage ||
409
+ updates_ instanceof types.UpdateShortChatMessage ||
410
+ updates_ instanceof types.UpdateShortSentMessage) {
411
+ await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_setUpdateStateDate).call(this, updates_.date);
412
+ }
413
+ for (const update of updates) {
414
+ if (update instanceof types.UpdatePtsChanged) {
415
+ await this.fetchState("updatePtsChanged");
416
+ if (__classPrivateFieldGet(this, _UpdateManager_updateState, "f")) {
417
+ await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.setState(__classPrivateFieldGet(this, _UpdateManager_updateState, "f"));
418
+ }
419
+ else {
420
+ UNREACHABLE();
421
+ }
422
+ }
423
+ else if (isPtsUpdate(update)) {
424
+ __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_processPtsUpdate).call(this, update, checkGap);
425
+ }
426
+ else if (isChannelPtsUpdate(update)) {
427
+ __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_processChannelPtsUpdate).call(this, update, checkGap);
428
+ }
429
+ else {
430
+ __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_queueUpdate).call(this, update, 0n, false);
431
+ }
432
+ }
433
+ }, _UpdateManager_setUpdateStateDate = async function _UpdateManager_setUpdateStateDate(date) {
434
+ const localState = await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_getLocalState).call(this);
435
+ localState.date = date;
436
+ await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.setState(localState);
437
+ }, _UpdateManager_setUpdatePts = async function _UpdateManager_setUpdatePts(pts) {
438
+ const localState = await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_getLocalState).call(this);
439
+ localState.pts = pts;
440
+ await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.setState(localState);
441
+ }, _UpdateManager_getLocalState = async function _UpdateManager_getLocalState() {
442
+ let localState = await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.getState();
443
+ if (!localState) {
444
+ if (__classPrivateFieldGet(this, _UpdateManager_updateState, "f")) {
445
+ localState = __classPrivateFieldGet(this, _UpdateManager_updateState, "f");
446
+ await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.setState(localState);
447
+ }
448
+ else {
449
+ await this.fetchState("getLocalState");
450
+ if (__classPrivateFieldGet(this, _UpdateManager_updateState, "f")) {
451
+ localState = __classPrivateFieldGet(this, _UpdateManager_updateState, "f");
452
+ await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.setState(localState);
453
+ }
454
+ else {
455
+ UNREACHABLE();
456
+ }
457
+ }
458
+ }
459
+ return localState;
460
+ }, _UpdateManager_recoverChannelUpdateGap = async function _UpdateManager_recoverChannelUpdateGap(channelId, source) {
461
+ dGapC("recovering channel update gap [%o, %s]", channelId, source);
462
+ const pts_ = await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.getChannelPts(channelId);
463
+ let pts = pts_ == null ? 1 : pts_;
464
+ while (true) {
465
+ const { access_hash } = await __classPrivateFieldGet(this, _UpdateManager_c, "f").getInputPeer(ZERO_CHANNEL_ID + -Number(channelId)).then((v) => v[as](types.InputPeerChannel));
466
+ const difference = await __classPrivateFieldGet(this, _UpdateManager_c, "f").api.updates.getChannelDifference({
467
+ pts,
468
+ channel: new types.InputChannel({ channel_id: channelId, access_hash }),
469
+ filter: new types.ChannelMessagesFilterEmpty(),
470
+ limit: await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.getAccountType() == "user" ? CHANNEL_DIFFERENCE_LIMIT_USER : CHANNEL_DIFFERENCE_LIMIT_BOT,
471
+ });
472
+ if (difference instanceof types.updates.ChannelDifference) {
473
+ await this.processChats(difference.chats);
474
+ await this.processUsers(difference.users);
475
+ for (const message of difference.new_messages) {
476
+ await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_processUpdates).call(this, new types.UpdateNewChannelMessage({ message, pts: 0, pts_count: 0 }), false);
477
+ }
478
+ for (const update of difference.other_updates) {
479
+ await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_processUpdates).call(this, update, false);
480
+ }
481
+ await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.setChannelPts(channelId, difference.pts);
482
+ dGapC("recovered from update gap [%o, %s]", channelId, source);
483
+ break;
484
+ }
485
+ else if (difference instanceof types.updates.ChannelDifferenceTooLong) {
486
+ // TODO: invalidate messages
487
+ dGapC("received channelDifferenceTooLong");
488
+ await this.processChats(difference.chats);
489
+ await this.processUsers(difference.users);
490
+ for (const message of difference.messages) {
491
+ await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_processUpdates).call(this, new types.UpdateNewChannelMessage({ message, pts: 0, pts_count: 0 }), false);
492
+ }
493
+ const pts_ = difference.dialog[as](types.Dialog).pts;
494
+ if (pts_ != undefined) {
495
+ pts = pts_;
496
+ }
497
+ else {
498
+ UNREACHABLE();
499
+ }
500
+ dGapC("processed channelDifferenceTooLong");
501
+ }
502
+ else if (difference instanceof types.updates.ChannelDifferenceEmpty) {
503
+ dGapC("there was no update gap");
504
+ break;
505
+ }
506
+ }
507
+ }, _UpdateManager_handleStoredUpdates = async function _UpdateManager_handleStoredUpdates(boxId) {
508
+ if (__classPrivateFieldGet(this, _UpdateManager_handleUpdatesSet, "f").has(boxId)) {
509
+ return;
510
+ }
511
+ __classPrivateFieldGet(this, _UpdateManager_handleUpdatesSet, "f").add(boxId);
512
+ do {
513
+ const maybeUpdate = await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.getFirstUpdate(boxId);
514
+ if (maybeUpdate == null) {
515
+ break;
516
+ }
517
+ const [key, update] = maybeUpdate;
518
+ for (let i = 0; i < 100; ++i) {
519
+ try {
520
+ const handle = await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_handleUpdate).call(this, update);
521
+ handle: for (let i = 0; i < 2; ++i) {
522
+ try {
523
+ await handle();
524
+ break handle;
525
+ }
526
+ catch {
527
+ continue handle;
528
+ }
529
+ }
530
+ break;
531
+ }
532
+ catch (err) {
533
+ d("#handleUpdate error: %o", err);
534
+ }
535
+ }
536
+ await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.set(key, null);
537
+ } while (true);
538
+ __classPrivateFieldGet(this, _UpdateManager_handleUpdatesSet, "f").delete(boxId);
539
+ }, _UpdateManager_handleUpdate = async function _UpdateManager_handleUpdate(update) {
540
+ const handler = __classPrivateFieldGet(this, _UpdateManager_updateHandler, "f");
541
+ if (handler) {
542
+ return await handler(update);
543
+ }
544
+ else {
545
+ return () => Promise.resolve();
546
+ }
547
+ };
548
+ Object.defineProperty(UpdateManager, "MAIN_BOX_ID", {
549
+ enumerable: true,
550
+ configurable: true,
551
+ writable: true,
552
+ value: 0n
553
+ });
@@ -0,0 +1,40 @@
1
+ import { enums, types } from "../2_tl.js";
2
+ import { FileSource, ID, Message } from "../3_types.js";
3
+ import { DeleteMessagesParams, EditMessageParams, EditMessageReplyMarkupParams, ForwardMessagesParams, GetHistoryParams, PinMessageParams, SendAnimationParams, SendAudioParams, SendContactParams, SendDiceParams, SendDocumentParams, SendLocationParams, SendMessageParams, SendPhotoParams, SendPollParams, SendVenueParams, SendVideoNoteParams, SendVideoParams, SendVoiceParams } from "./0_params.js";
4
+ import { C as C_ } from "./0_types.js";
5
+ import { FileManager } from "./1_file_manager.js";
6
+ interface C extends C_ {
7
+ fileManager: FileManager;
8
+ }
9
+ export declare class MessageManager {
10
+ #private;
11
+ constructor(c: C);
12
+ getMessages(chatId: ID, messageIds: number[]): Promise<Message[]>;
13
+ getMessageWithReply(chatId: ID, messageId: number): Promise<Message>;
14
+ getMessage(chatId: ID, messageId: number): Promise<Message>;
15
+ getStickerSetName(inputStickerSet: types.InputStickerSetID, hash?: number): Promise<string>;
16
+ constructMessage(message_: enums.Message, r?: boolean): Promise<Message>;
17
+ forwardMessages(from: ID, to: ID, messageIds: number[], params?: ForwardMessagesParams): Promise<Message[]>;
18
+ getHistory(chatId: ID, params?: GetHistoryParams): Promise<Message[]>;
19
+ sendMessage(chatId: ID, text: string, params?: SendMessageParams): Promise<import("../3_types.js").MessageText>;
20
+ sendVenue(chatId: ID, latitude: number, longitude: number, title: string, address: string, params?: SendVenueParams): Promise<import("../3_types.js").MessageVenue>;
21
+ sendContact(chatId: ID, firstName: string, number: string, params?: SendContactParams): Promise<import("../3_types.js").MessageContact>;
22
+ sendDice(chatId: ID, params?: SendDiceParams): Promise<import("../3_types.js").MessageDice>;
23
+ sendLocation(chatId: ID, latitude: number, longitude: number, params?: SendLocationParams): Promise<import("../3_types.js").MessageLocation>;
24
+ sendVideoNote(chatId: ID, audio: FileSource, params?: SendVideoNoteParams): Promise<import("../3_types.js").MessageVideoNote>;
25
+ sendAudio(chatId: ID, audio: FileSource, params?: SendAudioParams): Promise<import("../3_types.js").MessageAudio>;
26
+ sendVoice(chatId: ID, voice: FileSource, params?: SendVoiceParams): Promise<import("../3_types.js").MessageVoice>;
27
+ sendAnimation(chatId: ID, animation: FileSource, params?: SendAnimationParams): Promise<import("../3_types.js").MessageAnimation>;
28
+ sendVideo(chatId: ID, video: FileSource, params?: SendVideoParams): Promise<import("../3_types.js").MessageVideo>;
29
+ sendDocument(chatId: ID, document: FileSource, params?: SendDocumentParams): Promise<import("../3_types.js").MessageDocument>;
30
+ sendPhoto(chatId: ID, photo: FileSource, params?: SendPhotoParams): Promise<import("../3_types.js").MessagePhoto>;
31
+ sendPoll(chatId: ID, question: string, options: [string, string, ...string[]], params?: SendPollParams): Promise<import("../3_types.js").MessagePoll>;
32
+ editMessageReplyMarkup(chatId: ID, messageId: number, params?: EditMessageReplyMarkupParams): Promise<import("../3_types.js").MessageText | import("../3_types.js").MessagePhoto | import("../3_types.js").MessageDocument | import("../3_types.js").MessageVideo | import("../3_types.js").MessageSticker | import("../3_types.js").MessageAnimation | import("../3_types.js").MessageVoice | import("../3_types.js").MessageAudio | import("../3_types.js").MessageDice | import("../3_types.js").MessageVideoNote | import("../3_types.js").MessageContact | import("../3_types.js").MessageGame | import("../3_types.js").MessagePoll | import("../3_types.js").MessageVenue | import("../3_types.js").MessageLocation | import("../3_types.js").MessageNewChatMembers | import("../3_types.js").MessageLeftChatMember | import("../3_types.js").MessageNewChatTitle | import("../3_types.js").MessageNewChatPhoto | import("../3_types.js").MessageDeletedChatPhoto | import("../3_types.js").MessageGroupCreated | import("../3_types.js").MessageSupergroupCreated | import("../3_types.js").MessageChannelCreated | import("../3_types.js").MessageAutoDeleteTimerChanged | import("../3_types.js").MessageChatMigratedTo | import("../3_types.js").MessageChatMigratedFrom | import("../3_types.js").MessagePinnedMessage | import("../3_types.js").MessageUserShared | import("../3_types.js").MessageWriteAccessAllowed | import("../3_types.js").MessageForumTopicCreated | import("../3_types.js").MessageForumTopicEdited | import("../3_types.js").MessageForumTopicClosed | import("../3_types.js").MessageForumTopicReopened | import("../3_types.js").MessageVideoChatScheduled | import("../3_types.js").MessageVideoChatStarted | import("../3_types.js").MessageVideoChatEnded | import("../3_types.js").MessageGiveaway | import("../3_types.js").MessageUnsupported>;
33
+ editMessageText(chatId: ID, messageId: number, text: string, params?: EditMessageParams): Promise<import("../3_types.js").MessageText>;
34
+ deleteMessages(chatId: ID, messageIds: number[], params?: DeleteMessagesParams): Promise<void>;
35
+ deleteChatMemberMessages(chatId: ID, memberId: ID): Promise<void>;
36
+ pinMessage(chatId: ID, messageId: number, params?: PinMessageParams): Promise<void>;
37
+ unpinMessage(chatId: ID, messageId: number): Promise<void>;
38
+ unpinMessages(chatId: ID): Promise<void>;
39
+ }
40
+ export {};