@mtkruto/node 0.69.0 → 0.70.1

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 (565) hide show
  1. package/esm/0_deps.d.ts +3 -1
  2. package/esm/0_deps.d.ts.map +1 -1
  3. package/esm/0_deps.js +3 -1
  4. package/esm/3_types.d.ts +35 -35
  5. package/esm/3_types.d.ts.map +1 -1
  6. package/esm/3_types.js +35 -35
  7. package/esm/_dnt.polyfills.d.ts +20 -13
  8. package/esm/_dnt.polyfills.d.ts.map +1 -1
  9. package/esm/_dnt.polyfills.js +120 -11
  10. package/esm/client/0_abortable_loop.d.ts +27 -0
  11. package/esm/client/0_abortable_loop.d.ts.map +1 -0
  12. package/esm/client/0_abortable_loop.js +49 -0
  13. package/esm/client/0_client_abstract.d.ts +1 -0
  14. package/esm/client/0_client_abstract.d.ts.map +1 -1
  15. package/esm/client/0_client_abstract.js +3 -0
  16. package/esm/client/0_filters.d.ts +9 -3
  17. package/esm/client/0_filters.d.ts.map +1 -1
  18. package/esm/client/0_filters.js +4 -1
  19. package/esm/client/0_params.d.ts +1 -1
  20. package/esm/client/0_password.d.ts +2 -2
  21. package/esm/client/0_password.d.ts.map +1 -1
  22. package/esm/client/0_storage_operations.d.ts +53 -71
  23. package/esm/client/0_storage_operations.d.ts.map +1 -1
  24. package/esm/client/0_storage_operations.js +241 -238
  25. package/esm/client/0_update_processor.d.ts +2 -2
  26. package/esm/client/0_update_processor.d.ts.map +1 -1
  27. package/esm/client/0_utilities.d.ts +2 -2
  28. package/esm/client/0_utilities.d.ts.map +1 -1
  29. package/esm/client/1_types.d.ts +2 -2
  30. package/esm/client/1_types.d.ts.map +1 -1
  31. package/esm/client/2_account_manager.js +5 -5
  32. package/esm/client/2_business_connection_manager.d.ts +1 -1
  33. package/esm/client/2_business_connection_manager.d.ts.map +1 -1
  34. package/esm/client/2_business_connection_manager.js +3 -3
  35. package/esm/client/2_client_encrypted.d.ts +1 -1
  36. package/esm/client/2_client_encrypted.d.ts.map +1 -1
  37. package/esm/client/2_client_encrypted.js +26 -23
  38. package/esm/client/2_file_manager.js +2 -2
  39. package/esm/client/2_network_statistics_manager.d.ts +2 -2
  40. package/esm/client/2_network_statistics_manager.d.ts.map +1 -1
  41. package/esm/client/2_network_statistics_manager.js +30 -4
  42. package/esm/client/2_payment_manager.d.ts +1 -1
  43. package/esm/client/2_payment_manager.d.ts.map +1 -1
  44. package/esm/client/2_payment_manager.js +2 -2
  45. package/esm/client/2_reaction_manager.d.ts +1 -1
  46. package/esm/client/2_reaction_manager.d.ts.map +1 -1
  47. package/esm/client/2_reaction_manager.js +2 -2
  48. package/esm/client/2_translations_manager.d.ts +1 -1
  49. package/esm/client/2_translations_manager.d.ts.map +1 -1
  50. package/esm/client/2_translations_manager.js +15 -11
  51. package/esm/client/2_update_manager.d.ts +4 -2
  52. package/esm/client/2_update_manager.d.ts.map +1 -1
  53. package/esm/client/2_update_manager.js +62 -80
  54. package/esm/client/3_message_manager.d.ts +2 -2
  55. package/esm/client/3_message_manager.d.ts.map +1 -1
  56. package/esm/client/3_message_manager.js +5 -5
  57. package/esm/client/3_video_chat_manager.d.ts +1 -1
  58. package/esm/client/3_video_chat_manager.d.ts.map +1 -1
  59. package/esm/client/4_callback_query_manager.d.ts +1 -1
  60. package/esm/client/4_callback_query_manager.d.ts.map +1 -1
  61. package/esm/client/4_callback_query_manager.js +1 -1
  62. package/esm/client/4_chat_list_manager.d.ts +2 -3
  63. package/esm/client/4_chat_list_manager.d.ts.map +1 -1
  64. package/esm/client/4_chat_list_manager.js +10 -265
  65. package/esm/client/4_chat_manager.d.ts +2 -2
  66. package/esm/client/4_chat_manager.d.ts.map +1 -1
  67. package/esm/client/4_chat_manager.js +7 -7
  68. package/esm/client/4_gift_manager.js +3 -3
  69. package/esm/client/4_inline_query_manager.d.ts +1 -1
  70. package/esm/client/4_inline_query_manager.d.ts.map +1 -1
  71. package/esm/client/4_inline_query_manager.js +3 -3
  72. package/esm/client/4_link_preview_manager.d.ts +1 -1
  73. package/esm/client/4_link_preview_manager.d.ts.map +1 -1
  74. package/esm/client/4_link_preview_manager.js +3 -3
  75. package/esm/client/4_poll_manager.d.ts +1 -1
  76. package/esm/client/4_poll_manager.d.ts.map +1 -1
  77. package/esm/client/4_poll_manager.js +1 -1
  78. package/esm/client/4_story_manager.d.ts +1 -1
  79. package/esm/client/4_story_manager.d.ts.map +1 -1
  80. package/esm/client/4_story_manager.js +7 -7
  81. package/esm/client/5_client.d.ts +15 -9
  82. package/esm/client/5_client.d.ts.map +1 -1
  83. package/esm/client/5_client.js +420 -382
  84. package/esm/deps/jsr.io/@std/cache/0.2.0/_serialize_arg_list.d.ts +12 -0
  85. package/esm/deps/jsr.io/@std/cache/0.2.0/_serialize_arg_list.d.ts.map +1 -0
  86. package/esm/deps/jsr.io/@std/cache/0.2.0/_serialize_arg_list.js +69 -0
  87. package/esm/deps/jsr.io/@std/cache/0.2.0/lru_cache.d.ts +112 -0
  88. package/esm/deps/jsr.io/@std/cache/0.2.0/lru_cache.d.ts.map +1 -0
  89. package/esm/deps/jsr.io/@std/cache/0.2.0/lru_cache.js +140 -0
  90. package/esm/deps/jsr.io/@std/cache/0.2.0/memoize.d.ts +111 -0
  91. package/esm/deps/jsr.io/@std/cache/0.2.0/memoize.d.ts.map +1 -0
  92. package/esm/deps/jsr.io/@std/cache/0.2.0/memoize.js +82 -0
  93. package/esm/deps/jsr.io/@std/encoding/1.0.7/hex.d.ts +39 -0
  94. package/esm/deps/jsr.io/@std/encoding/1.0.7/hex.d.ts.map +1 -0
  95. package/esm/deps/jsr.io/@std/encoding/1.0.7/hex.js +109 -0
  96. package/esm/session/1_session.d.ts +1 -0
  97. package/esm/session/1_session.d.ts.map +1 -1
  98. package/esm/session/1_session.js +3 -0
  99. package/esm/session/2_session_encrypted.d.ts +2 -2
  100. package/esm/session/2_session_encrypted.d.ts.map +1 -1
  101. package/esm/session/2_session_encrypted.js +198 -135
  102. package/esm/storage/0_storage.d.ts +1 -0
  103. package/esm/storage/0_storage.d.ts.map +1 -1
  104. package/esm/storage/2_storage_indexed_db.d.ts +1 -0
  105. package/esm/storage/2_storage_indexed_db.d.ts.map +1 -1
  106. package/esm/storage/2_storage_indexed_db.js +3 -0
  107. package/esm/storage/2_storage_local_storage.node.d.ts +1 -0
  108. package/esm/storage/2_storage_local_storage.node.d.ts.map +1 -1
  109. package/esm/storage/2_storage_local_storage.node.js +3 -0
  110. package/esm/storage/2_storage_memory.d.ts +1 -0
  111. package/esm/storage/2_storage_memory.d.ts.map +1 -1
  112. package/esm/storage/2_storage_memory.js +3 -0
  113. package/esm/storage/2_storage_session_storage.d.ts +1 -0
  114. package/esm/storage/2_storage_session_storage.d.ts.map +1 -1
  115. package/esm/storage/2_storage_session_storage.js +3 -0
  116. package/esm/tl/0_utilities.d.ts +1 -0
  117. package/esm/tl/0_utilities.d.ts.map +1 -1
  118. package/esm/tl/0_utilities.js +20 -1
  119. package/esm/tl/1_telegram_api.d.ts +810 -254
  120. package/esm/tl/1_telegram_api.d.ts.map +1 -1
  121. package/esm/tl/1_telegram_api.js +912 -213
  122. package/esm/tl/1_tl_reader.d.ts +2 -2
  123. package/esm/tl/1_tl_reader.d.ts.map +1 -1
  124. package/esm/tl/1_tl_writer.d.ts +2 -2
  125. package/esm/tl/1_tl_writer.d.ts.map +1 -1
  126. package/esm/tl/2_mtproto.d.ts +1 -1
  127. package/esm/tl/2_mtproto.d.ts.map +1 -1
  128. package/esm/tl/2_telegram.d.ts +1 -1
  129. package/esm/tl/2_telegram.d.ts.map +1 -1
  130. package/esm/types/0_file_source.d.ts +1 -1
  131. package/esm/types/0_file_source.d.ts.map +1 -1
  132. package/esm/types/1_chat_p.d.ts +10 -0
  133. package/esm/types/1_chat_p.d.ts.map +1 -1
  134. package/esm/types/1_chat_p.js +4 -0
  135. package/esm/types/2_chat.d.ts +2 -5
  136. package/esm/types/2_chat.d.ts.map +1 -1
  137. package/esm/types/2_chat.js +10 -15
  138. package/esm/types/{0_message_entity.d.ts → 2_message_entity.d.ts} +3 -3
  139. package/esm/types/{0_message_entity.d.ts.map → 2_message_entity.d.ts.map} +1 -1
  140. package/esm/types/{0_message_entity.js → 2_message_entity.js} +7 -7
  141. package/esm/types/2_message_reaction_count.d.ts +2 -3
  142. package/esm/types/2_message_reaction_count.d.ts.map +1 -1
  143. package/esm/types/2_message_reaction_count.js +4 -6
  144. package/esm/types/2_poll_answer.d.ts +2 -3
  145. package/esm/types/2_poll_answer.d.ts.map +1 -1
  146. package/esm/types/2_poll_answer.js +4 -5
  147. package/esm/types/2_story_interactive_area.d.ts +2 -2
  148. package/esm/types/2_story_interactive_area.d.ts.map +1 -1
  149. package/esm/types/2_story_interactive_area.js +2 -2
  150. package/esm/types/{1_story_privacy.d.ts → 2_story_privacy.d.ts} +3 -3
  151. package/esm/types/{1_story_privacy.d.ts.map → 2_story_privacy.d.ts.map} +1 -1
  152. package/esm/types/{1_story_privacy.js → 2_story_privacy.js} +10 -10
  153. package/{script/types/1_user.d.ts → esm/types/2_user.d.ts} +5 -1
  154. package/esm/types/2_user.d.ts.map +1 -0
  155. package/esm/types/{1_user.js → 2_user.js} +24 -0
  156. package/esm/types/{2_business_connection.d.ts → 3_business_connection.d.ts} +4 -4
  157. package/esm/types/3_business_connection.d.ts.map +1 -0
  158. package/esm/types/{2_business_connection.js → 3_business_connection.js} +10 -3
  159. package/{script/types/2_chat_member.d.ts → esm/types/3_chat_member.d.ts} +6 -4
  160. package/esm/types/{2_chat_member.d.ts.map → 3_chat_member.d.ts.map} +1 -1
  161. package/esm/types/{2_chat_member.js → 3_chat_member.js} +5 -5
  162. package/esm/types/{2_chat_settings.d.ts → 3_chat_settings.d.ts} +2 -2
  163. package/{script/types/2_chat_settings.d.ts.map → esm/types/3_chat_settings.d.ts.map} +1 -1
  164. package/esm/types/{2_chat_settings.js → 3_chat_settings.js} +1 -1
  165. package/esm/types/{2_chosen_inline_result.d.ts → 3_chosen_inline_result.d.ts} +4 -4
  166. package/esm/types/3_chosen_inline_result.d.ts.map +1 -0
  167. package/esm/types/{2_chosen_inline_result.js → 3_chosen_inline_result.js} +3 -3
  168. package/esm/types/{2_forward_header.d.ts → 3_forward_header.d.ts} +4 -5
  169. package/esm/types/3_forward_header.d.ts.map +1 -0
  170. package/esm/types/{2_forward_header.js → 3_forward_header.js} +11 -12
  171. package/{script/types/2_game.d.ts → esm/types/3_game.d.ts} +2 -2
  172. package/esm/types/3_game.d.ts.map +1 -0
  173. package/esm/types/{2_gift_upgraded_component.d.ts → 3_gift_upgraded_component.d.ts} +2 -2
  174. package/esm/types/{2_gift_upgraded_component.d.ts.map → 3_gift_upgraded_component.d.ts.map} +1 -1
  175. package/esm/types/{2_gift_upgraded_component.js → 3_gift_upgraded_component.js} +1 -1
  176. package/esm/types/{2_inline_query.d.ts → 3_inline_query.d.ts} +4 -4
  177. package/esm/types/3_inline_query.d.ts.map +1 -0
  178. package/esm/types/{2_inline_query.js → 3_inline_query.js} +5 -5
  179. package/{script/types/1_input_media.d.ts → esm/types/3_input_media.d.ts} +2 -2
  180. package/esm/types/{1_input_media.d.ts.map → 3_input_media.d.ts.map} +1 -1
  181. package/{script/types/2_invite_link.d.ts → esm/types/3_invite_link.d.ts} +4 -4
  182. package/{script/types/2_invite_link.d.ts.map → esm/types/3_invite_link.d.ts.map} +1 -1
  183. package/esm/types/{2_invite_link.js → 3_invite_link.js} +5 -5
  184. package/{script/types/2_message_reactions.d.ts → esm/types/3_message_reactions.d.ts} +5 -6
  185. package/esm/types/3_message_reactions.d.ts.map +1 -0
  186. package/esm/types/{2_message_reactions.js → 3_message_reactions.js} +10 -12
  187. package/esm/types/{1_poll_option.d.ts → 3_poll_option.d.ts} +2 -2
  188. package/esm/types/{1_poll_option.d.ts.map → 3_poll_option.d.ts.map} +1 -1
  189. package/esm/types/{1_poll_option.js → 3_poll_option.js} +1 -1
  190. package/esm/types/{2_pre_checkout_query.d.ts → 3_pre_checkout_query.d.ts} +4 -4
  191. package/esm/types/3_pre_checkout_query.d.ts.map +1 -0
  192. package/esm/types/{2_pre_checkout_query.js → 3_pre_checkout_query.js} +5 -5
  193. package/{script/types/1_reply_quote.d.ts → esm/types/3_reply_quote.d.ts} +2 -2
  194. package/esm/types/{1_reply_quote.d.ts.map → 3_reply_quote.d.ts.map} +1 -1
  195. package/esm/types/{1_reply_quote.js → 3_reply_quote.js} +1 -1
  196. package/esm/types/3_story.d.ts +4 -5
  197. package/esm/types/3_story.d.ts.map +1 -1
  198. package/esm/types/3_story.js +6 -7
  199. package/esm/types/{3_chat_member_updated.d.ts → 4_chat_member_updated.d.ts} +6 -7
  200. package/esm/types/4_chat_member_updated.d.ts.map +1 -0
  201. package/esm/types/{3_chat_member_updated.js → 4_chat_member_updated.js} +13 -14
  202. package/esm/types/{3_gift.d.ts → 4_gift.d.ts} +6 -6
  203. package/esm/types/{3_gift.d.ts.map → 4_gift.d.ts.map} +1 -1
  204. package/esm/types/{3_gift.js → 4_gift.js} +7 -7
  205. package/esm/types/{3_join_request.d.ts → 4_join_request.d.ts} +6 -7
  206. package/esm/types/4_join_request.d.ts.map +1 -0
  207. package/esm/types/{3_join_request.js → 4_join_request.js} +17 -18
  208. package/esm/types/{2_poll.d.ts → 4_poll.d.ts} +3 -3
  209. package/esm/types/{2_poll.d.ts.map → 4_poll.d.ts.map} +1 -1
  210. package/esm/types/{2_poll.js → 4_poll.js} +2 -2
  211. package/{script/types/2_reply_to.d.ts → esm/types/4_reply_to.d.ts} +2 -2
  212. package/esm/types/{2_reply_to.d.ts.map → 4_reply_to.d.ts.map} +1 -1
  213. package/esm/types/{4_claimed_gift.d.ts → 5_claimed_gift.d.ts} +5 -6
  214. package/esm/types/5_claimed_gift.d.ts.map +1 -0
  215. package/esm/types/{4_claimed_gift.js → 5_claimed_gift.js} +4 -4
  216. package/esm/types/{4_link_preview.d.ts → 5_link_preview.d.ts} +4 -4
  217. package/{script/types/4_link_preview.d.ts.map → esm/types/5_link_preview.d.ts.map} +1 -1
  218. package/esm/types/{4_link_preview.js → 5_link_preview.js} +3 -3
  219. package/esm/types/{5_claimed_gifts.d.ts → 6_claimed_gifts.d.ts} +4 -4
  220. package/esm/types/6_claimed_gifts.d.ts.map +1 -0
  221. package/esm/types/{5_claimed_gifts.js → 6_claimed_gifts.js} +4 -4
  222. package/esm/types/{5_message.d.ts → 6_message.d.ts} +10 -11
  223. package/esm/types/6_message.d.ts.map +1 -0
  224. package/esm/types/{5_message.js → 6_message.js} +41 -66
  225. package/{script/types/5_message_content.d.ts → esm/types/6_message_content.d.ts} +3 -3
  226. package/esm/types/{5_message_content.d.ts.map → 6_message_content.d.ts.map} +1 -1
  227. package/{script/types/6_callback_query.d.ts → esm/types/7_callback_query.d.ts} +5 -5
  228. package/esm/types/{6_callback_query.d.ts.map → 7_callback_query.d.ts.map} +1 -1
  229. package/esm/types/{6_callback_query.js → 7_callback_query.js} +5 -5
  230. package/{script/types/6_chat_list_item.d.ts → esm/types/7_chat_list_item.d.ts} +6 -7
  231. package/esm/types/7_chat_list_item.d.ts.map +1 -0
  232. package/esm/types/{6_chat_list_item.js → 7_chat_list_item.js} +11 -11
  233. package/{script/types/6_inline_query_result.d.ts → esm/types/7_inline_query_result.d.ts} +3 -3
  234. package/esm/types/{6_inline_query_result.d.ts.map → 7_inline_query_result.d.ts.map} +1 -1
  235. package/esm/types/{6_inline_query_result.js → 7_inline_query_result.js} +1 -1
  236. package/esm/types/{6_saved_chat.d.ts → 7_saved_chat.d.ts} +4 -5
  237. package/esm/types/7_saved_chat.d.ts.map +1 -0
  238. package/esm/types/{6_saved_chat.js → 7_saved_chat.js} +4 -4
  239. package/esm/types/{6_topic.d.ts → 7_topic.d.ts} +2 -2
  240. package/esm/types/{6_topic.d.ts.map → 7_topic.d.ts.map} +1 -1
  241. package/esm/types/{7_inline_query_answer.d.ts → 8_inline_query_answer.d.ts} +2 -2
  242. package/esm/types/{7_inline_query_answer.d.ts.map → 8_inline_query_answer.d.ts.map} +1 -1
  243. package/esm/types/{7_inline_query_answer.js → 8_inline_query_answer.js} +1 -1
  244. package/{script/types/7_saved_chats.d.ts → esm/types/8_saved_chats.d.ts} +5 -5
  245. package/esm/types/8_saved_chats.d.ts.map +1 -0
  246. package/esm/types/{7_saved_chats.js → 8_saved_chats.js} +3 -3
  247. package/esm/types/{7_update.d.ts → 8_update.d.ts} +35 -16
  248. package/esm/types/8_update.d.ts.map +1 -0
  249. package/esm/types/_file_id.d.ts +1 -1
  250. package/esm/types/_file_id.d.ts.map +1 -1
  251. package/esm/types/_getters.d.ts +0 -7
  252. package/esm/types/_getters.d.ts.map +1 -1
  253. package/esm/utilities/0_hash.d.ts +2 -2
  254. package/esm/utilities/0_hash.d.ts.map +1 -1
  255. package/esm/utilities/0_misc.d.ts +1 -0
  256. package/esm/utilities/0_misc.d.ts.map +1 -1
  257. package/esm/utilities/0_misc.js +14 -1
  258. package/esm/utilities/0_part_stream.d.ts +1 -1
  259. package/esm/utilities/0_part_stream.d.ts.map +1 -1
  260. package/package.json +1 -1
  261. package/script/0_deps.d.ts +3 -1
  262. package/script/0_deps.d.ts.map +1 -1
  263. package/script/0_deps.js +6 -1
  264. package/script/3_types.d.ts +35 -35
  265. package/script/3_types.d.ts.map +1 -1
  266. package/script/3_types.js +35 -35
  267. package/script/_dnt.polyfills.d.ts +20 -13
  268. package/script/_dnt.polyfills.d.ts.map +1 -1
  269. package/script/_dnt.polyfills.js +120 -11
  270. package/script/client/0_abortable_loop.d.ts +27 -0
  271. package/script/client/0_abortable_loop.d.ts.map +1 -0
  272. package/script/client/0_abortable_loop.js +53 -0
  273. package/script/client/0_client_abstract.d.ts +1 -0
  274. package/script/client/0_client_abstract.d.ts.map +1 -1
  275. package/script/client/0_client_abstract.js +3 -0
  276. package/script/client/0_filters.d.ts +9 -3
  277. package/script/client/0_filters.d.ts.map +1 -1
  278. package/script/client/0_filters.js +4 -1
  279. package/script/client/0_params.d.ts +1 -1
  280. package/script/client/0_password.d.ts +2 -2
  281. package/script/client/0_password.d.ts.map +1 -1
  282. package/script/client/0_storage_operations.d.ts +53 -71
  283. package/script/client/0_storage_operations.d.ts.map +1 -1
  284. package/script/client/0_storage_operations.js +239 -236
  285. package/script/client/0_update_processor.d.ts +2 -2
  286. package/script/client/0_update_processor.d.ts.map +1 -1
  287. package/script/client/0_utilities.d.ts +2 -2
  288. package/script/client/0_utilities.d.ts.map +1 -1
  289. package/script/client/1_types.d.ts +2 -2
  290. package/script/client/1_types.d.ts.map +1 -1
  291. package/script/client/2_account_manager.js +5 -5
  292. package/script/client/2_business_connection_manager.d.ts +1 -1
  293. package/script/client/2_business_connection_manager.d.ts.map +1 -1
  294. package/script/client/2_business_connection_manager.js +3 -3
  295. package/script/client/2_client_encrypted.d.ts +1 -1
  296. package/script/client/2_client_encrypted.d.ts.map +1 -1
  297. package/script/client/2_client_encrypted.js +26 -23
  298. package/script/client/2_file_manager.js +2 -2
  299. package/script/client/2_network_statistics_manager.d.ts +2 -2
  300. package/script/client/2_network_statistics_manager.d.ts.map +1 -1
  301. package/script/client/2_network_statistics_manager.js +30 -4
  302. package/script/client/2_payment_manager.d.ts +1 -1
  303. package/script/client/2_payment_manager.d.ts.map +1 -1
  304. package/script/client/2_payment_manager.js +2 -2
  305. package/script/client/2_reaction_manager.d.ts +1 -1
  306. package/script/client/2_reaction_manager.d.ts.map +1 -1
  307. package/script/client/2_reaction_manager.js +2 -2
  308. package/script/client/2_translations_manager.d.ts +1 -1
  309. package/script/client/2_translations_manager.d.ts.map +1 -1
  310. package/script/client/2_translations_manager.js +15 -11
  311. package/script/client/2_update_manager.d.ts +4 -2
  312. package/script/client/2_update_manager.d.ts.map +1 -1
  313. package/script/client/2_update_manager.js +62 -80
  314. package/script/client/3_message_manager.d.ts +2 -2
  315. package/script/client/3_message_manager.d.ts.map +1 -1
  316. package/script/client/3_message_manager.js +5 -5
  317. package/script/client/3_video_chat_manager.d.ts +1 -1
  318. package/script/client/3_video_chat_manager.d.ts.map +1 -1
  319. package/script/client/4_callback_query_manager.d.ts +1 -1
  320. package/script/client/4_callback_query_manager.d.ts.map +1 -1
  321. package/script/client/4_callback_query_manager.js +1 -1
  322. package/script/client/4_chat_list_manager.d.ts +2 -3
  323. package/script/client/4_chat_list_manager.d.ts.map +1 -1
  324. package/script/client/4_chat_list_manager.js +9 -264
  325. package/script/client/4_chat_manager.d.ts +2 -2
  326. package/script/client/4_chat_manager.d.ts.map +1 -1
  327. package/script/client/4_chat_manager.js +7 -7
  328. package/script/client/4_gift_manager.js +3 -3
  329. package/script/client/4_inline_query_manager.d.ts +1 -1
  330. package/script/client/4_inline_query_manager.d.ts.map +1 -1
  331. package/script/client/4_inline_query_manager.js +3 -3
  332. package/script/client/4_link_preview_manager.d.ts +1 -1
  333. package/script/client/4_link_preview_manager.d.ts.map +1 -1
  334. package/script/client/4_link_preview_manager.js +3 -3
  335. package/script/client/4_poll_manager.d.ts +1 -1
  336. package/script/client/4_poll_manager.d.ts.map +1 -1
  337. package/script/client/4_poll_manager.js +1 -1
  338. package/script/client/4_story_manager.d.ts +1 -1
  339. package/script/client/4_story_manager.d.ts.map +1 -1
  340. package/script/client/4_story_manager.js +7 -7
  341. package/script/client/5_client.d.ts +15 -9
  342. package/script/client/5_client.d.ts.map +1 -1
  343. package/script/client/5_client.js +418 -380
  344. package/script/deps/jsr.io/@std/cache/0.2.0/_serialize_arg_list.d.ts +12 -0
  345. package/script/deps/jsr.io/@std/cache/0.2.0/_serialize_arg_list.d.ts.map +1 -0
  346. package/script/deps/jsr.io/@std/cache/0.2.0/_serialize_arg_list.js +72 -0
  347. package/script/deps/jsr.io/@std/cache/0.2.0/lru_cache.d.ts +112 -0
  348. package/script/deps/jsr.io/@std/cache/0.2.0/lru_cache.d.ts.map +1 -0
  349. package/script/deps/jsr.io/@std/cache/0.2.0/lru_cache.js +144 -0
  350. package/script/deps/jsr.io/@std/cache/0.2.0/memoize.d.ts +111 -0
  351. package/script/deps/jsr.io/@std/cache/0.2.0/memoize.d.ts.map +1 -0
  352. package/script/deps/jsr.io/@std/cache/0.2.0/memoize.js +85 -0
  353. package/script/deps/jsr.io/@std/encoding/1.0.7/hex.d.ts +39 -0
  354. package/script/deps/jsr.io/@std/encoding/1.0.7/hex.d.ts.map +1 -0
  355. package/script/deps/jsr.io/@std/encoding/1.0.7/hex.js +113 -0
  356. package/script/session/1_session.d.ts +1 -0
  357. package/script/session/1_session.d.ts.map +1 -1
  358. package/script/session/1_session.js +3 -0
  359. package/script/session/2_session_encrypted.d.ts +2 -2
  360. package/script/session/2_session_encrypted.d.ts.map +1 -1
  361. package/script/session/2_session_encrypted.js +197 -134
  362. package/script/storage/0_storage.d.ts +1 -0
  363. package/script/storage/0_storage.d.ts.map +1 -1
  364. package/script/storage/2_storage_indexed_db.d.ts +1 -0
  365. package/script/storage/2_storage_indexed_db.d.ts.map +1 -1
  366. package/script/storage/2_storage_indexed_db.js +3 -0
  367. package/script/storage/2_storage_local_storage.node.d.ts +1 -0
  368. package/script/storage/2_storage_local_storage.node.d.ts.map +1 -1
  369. package/script/storage/2_storage_local_storage.node.js +3 -0
  370. package/script/storage/2_storage_memory.d.ts +1 -0
  371. package/script/storage/2_storage_memory.d.ts.map +1 -1
  372. package/script/storage/2_storage_memory.js +3 -0
  373. package/script/storage/2_storage_session_storage.d.ts +1 -0
  374. package/script/storage/2_storage_session_storage.d.ts.map +1 -1
  375. package/script/storage/2_storage_session_storage.js +3 -0
  376. package/script/tl/0_utilities.d.ts +1 -0
  377. package/script/tl/0_utilities.d.ts.map +1 -1
  378. package/script/tl/0_utilities.js +20 -0
  379. package/script/tl/1_telegram_api.d.ts +810 -254
  380. package/script/tl/1_telegram_api.d.ts.map +1 -1
  381. package/script/tl/1_telegram_api.js +912 -213
  382. package/script/tl/1_tl_reader.d.ts +2 -2
  383. package/script/tl/1_tl_reader.d.ts.map +1 -1
  384. package/script/tl/1_tl_writer.d.ts +2 -2
  385. package/script/tl/1_tl_writer.d.ts.map +1 -1
  386. package/script/tl/2_mtproto.d.ts +1 -1
  387. package/script/tl/2_mtproto.d.ts.map +1 -1
  388. package/script/tl/2_telegram.d.ts +1 -1
  389. package/script/tl/2_telegram.d.ts.map +1 -1
  390. package/script/types/0_file_source.d.ts +1 -1
  391. package/script/types/0_file_source.d.ts.map +1 -1
  392. package/script/types/1_chat_p.d.ts +10 -0
  393. package/script/types/1_chat_p.d.ts.map +1 -1
  394. package/script/types/1_chat_p.js +5 -0
  395. package/script/types/2_chat.d.ts +2 -5
  396. package/script/types/2_chat.d.ts.map +1 -1
  397. package/script/types/2_chat.js +10 -15
  398. package/script/types/{0_message_entity.d.ts → 2_message_entity.d.ts} +3 -3
  399. package/script/types/{0_message_entity.d.ts.map → 2_message_entity.d.ts.map} +1 -1
  400. package/script/types/{0_message_entity.js → 2_message_entity.js} +7 -7
  401. package/script/types/2_message_reaction_count.d.ts +2 -3
  402. package/script/types/2_message_reaction_count.d.ts.map +1 -1
  403. package/script/types/2_message_reaction_count.js +4 -6
  404. package/script/types/2_poll_answer.d.ts +2 -3
  405. package/script/types/2_poll_answer.d.ts.map +1 -1
  406. package/script/types/2_poll_answer.js +4 -5
  407. package/script/types/2_story_interactive_area.d.ts +2 -2
  408. package/script/types/2_story_interactive_area.d.ts.map +1 -1
  409. package/script/types/2_story_interactive_area.js +2 -2
  410. package/script/types/{1_story_privacy.d.ts → 2_story_privacy.d.ts} +3 -3
  411. package/script/types/{1_story_privacy.d.ts.map → 2_story_privacy.d.ts.map} +1 -1
  412. package/script/types/{1_story_privacy.js → 2_story_privacy.js} +10 -10
  413. package/{esm/types/1_user.d.ts → script/types/2_user.d.ts} +5 -1
  414. package/script/types/2_user.d.ts.map +1 -0
  415. package/script/types/{1_user.js → 2_user.js} +25 -0
  416. package/script/types/{2_business_connection.d.ts → 3_business_connection.d.ts} +4 -4
  417. package/script/types/3_business_connection.d.ts.map +1 -0
  418. package/script/types/{2_business_connection.js → 3_business_connection.js} +10 -3
  419. package/{esm/types/2_chat_member.d.ts → script/types/3_chat_member.d.ts} +6 -4
  420. package/script/types/{2_chat_member.d.ts.map → 3_chat_member.d.ts.map} +1 -1
  421. package/script/types/{2_chat_member.js → 3_chat_member.js} +5 -5
  422. package/script/types/{2_chat_settings.d.ts → 3_chat_settings.d.ts} +2 -2
  423. package/{esm/types/2_chat_settings.d.ts.map → script/types/3_chat_settings.d.ts.map} +1 -1
  424. package/script/types/{2_chat_settings.js → 3_chat_settings.js} +2 -2
  425. package/script/types/{2_chosen_inline_result.d.ts → 3_chosen_inline_result.d.ts} +4 -4
  426. package/script/types/3_chosen_inline_result.d.ts.map +1 -0
  427. package/script/types/{2_chosen_inline_result.js → 3_chosen_inline_result.js} +4 -4
  428. package/script/types/{2_forward_header.d.ts → 3_forward_header.d.ts} +4 -5
  429. package/script/types/3_forward_header.d.ts.map +1 -0
  430. package/script/types/{2_forward_header.js → 3_forward_header.js} +11 -12
  431. package/{esm/types/2_game.d.ts → script/types/3_game.d.ts} +2 -2
  432. package/script/types/3_game.d.ts.map +1 -0
  433. package/script/types/{2_gift_upgraded_component.d.ts → 3_gift_upgraded_component.d.ts} +2 -2
  434. package/script/types/{2_gift_upgraded_component.d.ts.map → 3_gift_upgraded_component.d.ts.map} +1 -1
  435. package/script/types/{2_gift_upgraded_component.js → 3_gift_upgraded_component.js} +2 -2
  436. package/script/types/{2_inline_query.d.ts → 3_inline_query.d.ts} +4 -4
  437. package/script/types/3_inline_query.d.ts.map +1 -0
  438. package/script/types/{2_inline_query.js → 3_inline_query.js} +5 -5
  439. package/{esm/types/1_input_media.d.ts → script/types/3_input_media.d.ts} +2 -2
  440. package/script/types/{1_input_media.d.ts.map → 3_input_media.d.ts.map} +1 -1
  441. package/{esm/types/2_invite_link.d.ts → script/types/3_invite_link.d.ts} +4 -4
  442. package/{esm/types/2_invite_link.d.ts.map → script/types/3_invite_link.d.ts.map} +1 -1
  443. package/script/types/{2_invite_link.js → 3_invite_link.js} +5 -5
  444. package/{esm/types/2_message_reactions.d.ts → script/types/3_message_reactions.d.ts} +5 -6
  445. package/script/types/3_message_reactions.d.ts.map +1 -0
  446. package/script/types/{2_message_reactions.js → 3_message_reactions.js} +10 -12
  447. package/script/types/{1_poll_option.d.ts → 3_poll_option.d.ts} +2 -2
  448. package/script/types/{1_poll_option.d.ts.map → 3_poll_option.d.ts.map} +1 -1
  449. package/script/types/{1_poll_option.js → 3_poll_option.js} +2 -2
  450. package/script/types/{2_pre_checkout_query.d.ts → 3_pre_checkout_query.d.ts} +4 -4
  451. package/script/types/3_pre_checkout_query.d.ts.map +1 -0
  452. package/script/types/{2_pre_checkout_query.js → 3_pre_checkout_query.js} +5 -5
  453. package/{esm/types/1_reply_quote.d.ts → script/types/3_reply_quote.d.ts} +2 -2
  454. package/script/types/{1_reply_quote.d.ts.map → 3_reply_quote.d.ts.map} +1 -1
  455. package/script/types/{1_reply_quote.js → 3_reply_quote.js} +2 -2
  456. package/script/types/3_story.d.ts +4 -5
  457. package/script/types/3_story.d.ts.map +1 -1
  458. package/script/types/3_story.js +8 -9
  459. package/script/types/{3_chat_member_updated.d.ts → 4_chat_member_updated.d.ts} +6 -7
  460. package/script/types/4_chat_member_updated.d.ts.map +1 -0
  461. package/script/types/{3_chat_member_updated.js → 4_chat_member_updated.js} +13 -14
  462. package/script/types/{3_gift.d.ts → 4_gift.d.ts} +6 -6
  463. package/script/types/{3_gift.d.ts.map → 4_gift.d.ts.map} +1 -1
  464. package/script/types/{3_gift.js → 4_gift.js} +9 -9
  465. package/script/types/{3_join_request.d.ts → 4_join_request.d.ts} +6 -7
  466. package/script/types/4_join_request.d.ts.map +1 -0
  467. package/script/types/{3_join_request.js → 4_join_request.js} +17 -18
  468. package/script/types/{2_poll.d.ts → 4_poll.d.ts} +3 -3
  469. package/script/types/{2_poll.d.ts.map → 4_poll.d.ts.map} +1 -1
  470. package/script/types/{2_poll.js → 4_poll.js} +5 -5
  471. package/{esm/types/2_reply_to.d.ts → script/types/4_reply_to.d.ts} +2 -2
  472. package/script/types/{2_reply_to.d.ts.map → 4_reply_to.d.ts.map} +1 -1
  473. package/script/types/{4_claimed_gift.d.ts → 5_claimed_gift.d.ts} +5 -6
  474. package/script/types/5_claimed_gift.d.ts.map +1 -0
  475. package/script/types/{4_claimed_gift.js → 5_claimed_gift.js} +5 -5
  476. package/script/types/{4_link_preview.d.ts → 5_link_preview.d.ts} +4 -4
  477. package/{esm/types/4_link_preview.d.ts.map → script/types/5_link_preview.d.ts.map} +1 -1
  478. package/script/types/{4_link_preview.js → 5_link_preview.js} +3 -3
  479. package/script/types/{5_claimed_gifts.d.ts → 6_claimed_gifts.d.ts} +4 -4
  480. package/script/types/6_claimed_gifts.d.ts.map +1 -0
  481. package/script/types/{5_claimed_gifts.js → 6_claimed_gifts.js} +4 -4
  482. package/script/types/{5_message.d.ts → 6_message.d.ts} +10 -11
  483. package/script/types/6_message.d.ts.map +1 -0
  484. package/script/types/{5_message.js → 6_message.js} +45 -70
  485. package/{esm/types/5_message_content.d.ts → script/types/6_message_content.d.ts} +3 -3
  486. package/script/types/{5_message_content.d.ts.map → 6_message_content.d.ts.map} +1 -1
  487. package/{esm/types/6_callback_query.d.ts → script/types/7_callback_query.d.ts} +5 -5
  488. package/script/types/{6_callback_query.d.ts.map → 7_callback_query.d.ts.map} +1 -1
  489. package/script/types/{6_callback_query.js → 7_callback_query.js} +5 -5
  490. package/{esm/types/6_chat_list_item.d.ts → script/types/7_chat_list_item.d.ts} +6 -7
  491. package/script/types/7_chat_list_item.d.ts.map +1 -0
  492. package/script/types/{6_chat_list_item.js → 7_chat_list_item.js} +11 -11
  493. package/{esm/types/6_inline_query_result.d.ts → script/types/7_inline_query_result.d.ts} +3 -3
  494. package/script/types/{6_inline_query_result.d.ts.map → 7_inline_query_result.d.ts.map} +1 -1
  495. package/script/types/{6_inline_query_result.js → 7_inline_query_result.js} +3 -3
  496. package/script/types/{6_saved_chat.d.ts → 7_saved_chat.d.ts} +4 -5
  497. package/script/types/7_saved_chat.d.ts.map +1 -0
  498. package/script/types/{6_saved_chat.js → 7_saved_chat.js} +4 -4
  499. package/script/types/{6_topic.d.ts → 7_topic.d.ts} +2 -2
  500. package/script/types/{6_topic.d.ts.map → 7_topic.d.ts.map} +1 -1
  501. package/script/types/{7_inline_query_answer.d.ts → 8_inline_query_answer.d.ts} +2 -2
  502. package/script/types/{7_inline_query_answer.d.ts.map → 8_inline_query_answer.d.ts.map} +1 -1
  503. package/script/types/{7_inline_query_answer.js → 8_inline_query_answer.js} +2 -2
  504. package/{esm/types/7_saved_chats.d.ts → script/types/8_saved_chats.d.ts} +5 -5
  505. package/script/types/8_saved_chats.d.ts.map +1 -0
  506. package/script/types/{7_saved_chats.js → 8_saved_chats.js} +3 -3
  507. package/script/types/{7_update.d.ts → 8_update.d.ts} +35 -16
  508. package/script/types/8_update.d.ts.map +1 -0
  509. package/script/types/_file_id.d.ts +1 -1
  510. package/script/types/_file_id.d.ts.map +1 -1
  511. package/script/types/_getters.d.ts +0 -7
  512. package/script/types/_getters.d.ts.map +1 -1
  513. package/script/utilities/0_hash.d.ts +2 -2
  514. package/script/utilities/0_hash.d.ts.map +1 -1
  515. package/script/utilities/0_misc.d.ts +1 -0
  516. package/script/utilities/0_misc.d.ts.map +1 -1
  517. package/script/utilities/0_misc.js +14 -0
  518. package/script/utilities/0_part_stream.d.ts +1 -1
  519. package/script/utilities/0_part_stream.d.ts.map +1 -1
  520. package/esm/types/1_user.d.ts.map +0 -1
  521. package/esm/types/2_business_connection.d.ts.map +0 -1
  522. package/esm/types/2_chosen_inline_result.d.ts.map +0 -1
  523. package/esm/types/2_forward_header.d.ts.map +0 -1
  524. package/esm/types/2_game.d.ts.map +0 -1
  525. package/esm/types/2_inline_query.d.ts.map +0 -1
  526. package/esm/types/2_message_reactions.d.ts.map +0 -1
  527. package/esm/types/2_pre_checkout_query.d.ts.map +0 -1
  528. package/esm/types/3_chat_member_updated.d.ts.map +0 -1
  529. package/esm/types/3_join_request.d.ts.map +0 -1
  530. package/esm/types/4_claimed_gift.d.ts.map +0 -1
  531. package/esm/types/5_claimed_gifts.d.ts.map +0 -1
  532. package/esm/types/5_message.d.ts.map +0 -1
  533. package/esm/types/6_chat_list_item.d.ts.map +0 -1
  534. package/esm/types/6_saved_chat.d.ts.map +0 -1
  535. package/esm/types/7_saved_chats.d.ts.map +0 -1
  536. package/esm/types/7_update.d.ts.map +0 -1
  537. package/script/types/1_user.d.ts.map +0 -1
  538. package/script/types/2_business_connection.d.ts.map +0 -1
  539. package/script/types/2_chosen_inline_result.d.ts.map +0 -1
  540. package/script/types/2_forward_header.d.ts.map +0 -1
  541. package/script/types/2_game.d.ts.map +0 -1
  542. package/script/types/2_inline_query.d.ts.map +0 -1
  543. package/script/types/2_message_reactions.d.ts.map +0 -1
  544. package/script/types/2_pre_checkout_query.d.ts.map +0 -1
  545. package/script/types/3_chat_member_updated.d.ts.map +0 -1
  546. package/script/types/3_join_request.d.ts.map +0 -1
  547. package/script/types/4_claimed_gift.d.ts.map +0 -1
  548. package/script/types/5_claimed_gifts.d.ts.map +0 -1
  549. package/script/types/5_message.d.ts.map +0 -1
  550. package/script/types/6_chat_list_item.d.ts.map +0 -1
  551. package/script/types/6_saved_chat.d.ts.map +0 -1
  552. package/script/types/7_saved_chats.d.ts.map +0 -1
  553. package/script/types/7_update.d.ts.map +0 -1
  554. /package/esm/types/{2_game.js → 3_game.js} +0 -0
  555. /package/esm/types/{1_input_media.js → 3_input_media.js} +0 -0
  556. /package/esm/types/{2_reply_to.js → 4_reply_to.js} +0 -0
  557. /package/esm/types/{5_message_content.js → 6_message_content.js} +0 -0
  558. /package/esm/types/{6_topic.js → 7_topic.js} +0 -0
  559. /package/esm/types/{7_update.js → 8_update.js} +0 -0
  560. /package/script/types/{2_game.js → 3_game.js} +0 -0
  561. /package/script/types/{1_input_media.js → 3_input_media.js} +0 -0
  562. /package/script/types/{2_reply_to.js → 4_reply_to.js} +0 -0
  563. /package/script/types/{5_message_content.js → 6_message_content.js} +0 -0
  564. /package/script/types/{6_topic.js → 7_topic.js} +0 -0
  565. /package/script/types/{7_update.js → 8_update.js} +0 -0
@@ -21,12 +21,14 @@ import { delay, MINUTE, SECOND, unreachable } from "../0_deps.js";
21
21
  import { AccessError, ConnectionError, InputError } from "../0_errors.js";
22
22
  import { cleanObject, drop, getLogger, mustPrompt, mustPromptOneOf, Mutex, ZERO_CHANNEL_ID } from "../1_utilities.js";
23
23
  import { StorageMemory } from "../2_storage.js";
24
- import { Api, Mtproto } from "../2_tl.js";
24
+ import { Api, Mtproto, toJSON } from "../2_tl.js";
25
25
  import { getDcId } from "../3_transport.js";
26
- import { constructUser } from "../3_types.js";
26
+ import { constructChatP, constructUser2 } from "../3_types.js";
27
27
  import { APP_VERSION, DEVICE_MODEL, INITIAL_DC, LANG_CODE, LANG_PACK, MAX_CHANNEL_ID, MAX_CHAT_ID, SYSTEM_LANG_CODE, SYSTEM_VERSION, USERNAME_TTL } from "../4_constants.js";
28
28
  import { AuthKeyUnregistered, FloodWait, Migrate, PasswordHashInvalid, PhoneNumberInvalid, SessionPasswordNeeded, SessionRevoked } from "../4_errors.js";
29
29
  import { PhoneCodeInvalid } from "../4_errors.js";
30
+ import { peerToChatId } from "../tl/2_telegram.js";
31
+ import { AbortableLoop } from "./0_abortable_loop.js";
30
32
  import { checkPassword } from "./0_password.js";
31
33
  import { StorageOperations } from "./0_storage_operations.js";
32
34
  import { canBeInputChannel, canBeInputUser, DOWNLOAD_POOL_SIZE, getUsername, resolve, toInputChannel, toInputUser } from "./0_utilities.js";
@@ -62,7 +64,8 @@ export const restartAuth = Symbol("restartAuth");
62
64
  export const handleMigrationError = Symbol("handleMigrationError");
63
65
  // global Client ID counter for logs
64
66
  let id = 0;
65
- const getEntity = Symbol();
67
+ const getPeer = Symbol();
68
+ const mustGetPeer = Symbol();
66
69
  /**
67
70
  * An MTKruto client.
68
71
  */
@@ -147,6 +150,7 @@ export class Client extends Composer {
147
150
  #L;
148
151
  #LsignIn;
149
152
  #LupdateGapRecoveryLoop;
153
+ #LstorageWriteLoop;
150
154
  #LhandleMigrationError;
151
155
  #Lmin;
152
156
  /**
@@ -186,6 +190,7 @@ export class Client extends Composer {
186
190
  const L = this.#L = getLogger("Client").client(id++);
187
191
  this.#LsignIn = L.branch("signIn");
188
192
  this.#LupdateGapRecoveryLoop = L.branch("updateGapRecoveryLoop");
193
+ this.#LstorageWriteLoop = L.branch("storageWriteLoop");
189
194
  this.#LhandleMigrationError = L.branch("[handleMigrationError]");
190
195
  this.#Lmin = L.branch("min");
191
196
  const c = {
@@ -213,7 +218,7 @@ export class Client extends Composer {
213
218
  getInputChannel: this.getInputChannel.bind(this),
214
219
  getInputUser: this.getInputUser.bind(this),
215
220
  getInputPeerChatId: this.#getInputPeerChatId.bind(this),
216
- getEntity: this[getEntity].bind(this),
221
+ getPeer: this[mustGetPeer].bind(this),
217
222
  handleUpdate: this.#queueHandleCtxUpdate.bind(this),
218
223
  parseMode: this.#parseMode,
219
224
  outgoingMessages: this.#outgoingMessages,
@@ -312,22 +317,21 @@ export class Client extends Composer {
312
317
  return this.#client?.disconnected ?? true;
313
318
  }
314
319
  #constructContext = async (update) => {
315
- const msg = "message" in update ? update.message : "editedMessage" in update ? update.editedMessage : "scheduledMessage" in update ? update.scheduledMessage : "callbackQuery" in update ? update.callbackQuery.message : undefined;
316
- const reactions = "messageInteractions" in update ? update.messageInteractions : undefined;
317
- const mustGetMsg = () => {
318
- if (msg !== undefined) {
319
- return { chatId: msg.chat.id, messageId: msg.id, businessConnectionId: msg.businessConnectionId, senderId: msg.from?.id, userId: msg.from?.id };
320
+ const mustGetMsg = (ctx) => {
321
+ if (ctx.msg !== undefined) {
322
+ return { chatId: ctx.msg.chat.id, messageId: ctx.msg.id, businessConnectionId: ctx.msg.businessConnectionId, senderId: ctx.msg.from?.id, userId: ctx.msg.from?.id };
320
323
  }
321
- else if (reactions !== undefined) {
324
+ const reactions = "messageInteractions" in update ? update.messageInteractions : undefined;
325
+ if (reactions !== undefined) {
322
326
  return { chatId: reactions.chatId, messageId: reactions.messageId };
323
327
  }
324
328
  else {
325
329
  unreachable();
326
330
  }
327
331
  };
328
- const mustGetUserId = () => {
329
- if (msg?.from) {
330
- return msg.from.id;
332
+ const mustGetUserId = (ctx) => {
333
+ if (ctx.msg?.from) {
334
+ return ctx.msg.from.id;
331
335
  }
332
336
  else if ("callbackQuery" in update) {
333
337
  return update.callbackQuery.from.id;
@@ -352,9 +356,6 @@ export class Client extends Composer {
352
356
  }
353
357
  unreachable();
354
358
  };
355
- const chat_ = "messageReactions" in update ? update.messageReactions.chat : "messageReactionCount" in update ? update.messageReactionCount.chat : "chatMember" in update ? update.chatMember.chat : "myChatMember" in update ? update.myChatMember.chat : "joinRequest" in update ? update.joinRequest.chat : "story" in update ? update.story.chat : undefined;
356
- const chat = chat_ ?? msg?.chat;
357
- const from = "callbackQuery" in update ? update.callbackQuery.from : "inlineQuery" in update ? update.inlineQuery.from : "chatMember" in update ? update.chatMember.from : "myChatMember" in update ? update.myChatMember.from : "messageReactions" in update ? update.messageReactions.user : "preCheckoutQuery" in update ? update.preCheckoutQuery.from : "joinRequest" in update ? update.joinRequest.from : "businessConnection" in update ? update.businessConnection.user : "pollAnswer" in update ? update.pollAnswer.from : msg?.from ? msg.from : undefined;
358
359
  const getReplyTo = (quote, chatId, messageId) => {
359
360
  if ("story" in update) {
360
361
  return { chatId: update.story.chat.id, storyId: update.story.id };
@@ -363,352 +364,368 @@ export class Client extends Composer {
363
364
  const shouldQuote = quote === undefined ? !isPrivate : quote;
364
365
  return shouldQuote ? { messageId } : undefined;
365
366
  };
366
- const me = "connectionState" in update ? this.#lastGetMe : ("authorizationState" in update && !update.authorizationState.authorized) ? this.#lastGetMe : await this.#getMe();
367
+ if (this.#lastGetMe === null && !("connectionState" in update) && (!("authorizationState" in update) || ("authorizationState" in update && update.authorizationState.authorized))) {
368
+ await this.#getMe();
369
+ }
367
370
  const context = {
368
371
  ...update,
369
372
  client: this,
370
- me: (me === null ? undefined : me),
371
- msg: msg,
372
- chat: chat,
373
- from: from,
374
- get toJSON() {
375
- return () => update;
376
- },
377
- reply: (text, params) => {
378
- const { chatId, messageId, businessConnectionId } = mustGetMsg();
373
+ get me() {
374
+ return this.client.#lastGetMe === null ? undefined : this.client.#lastGetMe;
375
+ },
376
+ get msg() {
377
+ return "message" in update ? update.message : "editedMessage" in update ? update.editedMessage : "scheduledMessage" in update ? update.scheduledMessage : "callbackQuery" in update ? update.callbackQuery.message : undefined;
378
+ },
379
+ get chat() {
380
+ return this.msg?.chat ?? ("messageReactions" in update ? update.messageReactions.chat : "messageReactionCount" in update ? update.messageReactionCount.chat : "chatMember" in update ? update.chatMember.chat : "myChatMember" in update ? update.myChatMember.chat : "joinRequest" in update ? update.joinRequest.chat : "story" in update ? update.story.chat : undefined);
381
+ },
382
+ get from() {
383
+ const from = "callbackQuery" in update ? update.callbackQuery.from : "inlineQuery" in update ? update.inlineQuery.from : "chatMember" in update ? update.chatMember.from : "myChatMember" in update ? update.myChatMember.from : "messageReactions" in update ? update.messageReactions.user : "preCheckoutQuery" in update ? update.preCheckoutQuery.from : "joinRequest" in update ? update.joinRequest.from : "businessConnection" in update ? update.businessConnection.user : "pollAnswer" in update ? update.pollAnswer.from : this.msg?.from;
384
+ return from;
385
+ },
386
+ toJSON() {
387
+ if ("update" in update) {
388
+ return { update: toJSON(update.update) };
389
+ }
390
+ else {
391
+ return update;
392
+ }
393
+ },
394
+ reply(text, params) {
395
+ const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
379
396
  const replyTo = getReplyTo(params?.quote, chatId, messageId);
380
- return this.sendMessage(chatId, text, { ...params, replyTo, businessConnectionId });
397
+ return this.client.sendMessage(chatId, text, { ...params, replyTo, businessConnectionId });
381
398
  },
382
- replyPoll: (question, options, params) => {
383
- const { chatId, messageId, businessConnectionId } = mustGetMsg();
399
+ replyPoll(question, options, params) {
400
+ const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
384
401
  const replyTo = getReplyTo(params?.quote, chatId, messageId);
385
- return this.sendPoll(chatId, question, options, { ...params, replyTo, businessConnectionId });
402
+ return this.client.sendPoll(chatId, question, options, { ...params, replyTo, businessConnectionId });
386
403
  },
387
- replyPhoto: (photo, params) => {
388
- const { chatId, messageId, businessConnectionId } = mustGetMsg();
404
+ replyPhoto(photo, params) {
405
+ const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
389
406
  const replyTo = getReplyTo(params?.quote, chatId, messageId);
390
- return this.sendPhoto(chatId, photo, { ...params, replyTo, businessConnectionId });
407
+ return this.client.sendPhoto(chatId, photo, { ...params, replyTo, businessConnectionId });
391
408
  },
392
- replyMediaGroup: (media, params) => {
393
- const { chatId, messageId, businessConnectionId } = mustGetMsg();
409
+ replyMediaGroup(media, params) {
410
+ const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
394
411
  const replyTo = getReplyTo(params?.quote, chatId, messageId);
395
- return this.sendMediaGroup(chatId, media, { ...params, replyTo, businessConnectionId });
412
+ return this.client.sendMediaGroup(chatId, media, { ...params, replyTo, businessConnectionId });
396
413
  },
397
- replyInvoice: (title, description, payload, currency, prices, params) => {
398
- const { chatId, messageId, businessConnectionId } = mustGetMsg();
414
+ replyInvoice(title, description, payload, currency, prices, params) {
415
+ const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
399
416
  const replyTo = getReplyTo(params?.quote, chatId, messageId);
400
- return this.sendInvoice(chatId, title, description, payload, currency, prices, { ...params, replyTo, businessConnectionId });
417
+ return this.client.sendInvoice(chatId, title, description, payload, currency, prices, { ...params, replyTo, businessConnectionId });
401
418
  },
402
- replyDocument: (document, params) => {
403
- const { chatId, messageId, businessConnectionId } = mustGetMsg();
419
+ replyDocument(document, params) {
420
+ const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
404
421
  const replyTo = getReplyTo(params?.quote, chatId, messageId);
405
- return this.sendDocument(chatId, document, { ...params, replyTo, businessConnectionId });
422
+ return this.client.sendDocument(chatId, document, { ...params, replyTo, businessConnectionId });
406
423
  },
407
- replySticker: (sticker, params) => {
408
- const { chatId, messageId, businessConnectionId } = mustGetMsg();
424
+ replySticker(sticker, params) {
425
+ const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
409
426
  const replyTo = getReplyTo(params?.quote, chatId, messageId);
410
- return this.sendSticker(chatId, sticker, { ...params, replyTo, businessConnectionId });
427
+ return this.client.sendSticker(chatId, sticker, { ...params, replyTo, businessConnectionId });
411
428
  },
412
- replyContact: (firstName, number, params) => {
413
- const { chatId, messageId, businessConnectionId } = mustGetMsg();
429
+ replyContact(firstName, number, params) {
430
+ const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
414
431
  const replyTo = getReplyTo(params?.quote, chatId, messageId);
415
- return this.sendContact(chatId, firstName, number, { ...params, replyTo, businessConnectionId });
432
+ return this.client.sendContact(chatId, firstName, number, { ...params, replyTo, businessConnectionId });
416
433
  },
417
- replyLocation: (latitude, longitude, params) => {
418
- const { chatId, messageId, businessConnectionId } = mustGetMsg();
434
+ replyLocation(latitude, longitude, params) {
435
+ const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
419
436
  const replyTo = getReplyTo(params?.quote, chatId, messageId);
420
- return this.sendLocation(chatId, latitude, longitude, { ...params, replyTo, businessConnectionId });
437
+ return this.client.sendLocation(chatId, latitude, longitude, { ...params, replyTo, businessConnectionId });
421
438
  },
422
- replyDice: (params) => {
423
- const { chatId, messageId, businessConnectionId } = mustGetMsg();
439
+ replyDice(params) {
440
+ const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
424
441
  const replyTo = getReplyTo(params?.quote, chatId, messageId);
425
- return this.sendDice(chatId, { ...params, replyTo, businessConnectionId });
442
+ return this.client.sendDice(chatId, { ...params, replyTo, businessConnectionId });
426
443
  },
427
- replyVenue: (latitude, longitude, title, address, params) => {
428
- const { chatId, messageId, businessConnectionId } = mustGetMsg();
444
+ replyVenue(latitude, longitude, title, address, params) {
445
+ const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
429
446
  const replyTo = getReplyTo(params?.quote, chatId, messageId);
430
- return this.sendVenue(chatId, latitude, longitude, title, address, { ...params, replyTo, businessConnectionId });
447
+ return this.client.sendVenue(chatId, latitude, longitude, title, address, { ...params, replyTo, businessConnectionId });
431
448
  },
432
- replyVideo: (video, params) => {
433
- const { chatId, messageId, businessConnectionId } = mustGetMsg();
449
+ replyVideo(video, params) {
450
+ const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
434
451
  const replyTo = getReplyTo(params?.quote, chatId, messageId);
435
- return this.sendVideo(chatId, video, { ...params, replyTo, businessConnectionId });
452
+ return this.client.sendVideo(chatId, video, { ...params, replyTo, businessConnectionId });
436
453
  },
437
- replyAnimation: (document, params) => {
438
- const { chatId, messageId, businessConnectionId } = mustGetMsg();
454
+ replyAnimation(document, params) {
455
+ const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
439
456
  const replyTo = getReplyTo(params?.quote, chatId, messageId);
440
- return this.sendAnimation(chatId, document, { ...params, replyTo, businessConnectionId });
457
+ return this.client.sendAnimation(chatId, document, { ...params, replyTo, businessConnectionId });
441
458
  },
442
- replyVoice: (document, params) => {
443
- const { chatId, messageId, businessConnectionId } = mustGetMsg();
459
+ replyVoice(document, params) {
460
+ const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
444
461
  const replyTo = getReplyTo(params?.quote, chatId, messageId);
445
- return this.sendVoice(chatId, document, { ...params, replyTo, businessConnectionId });
462
+ return this.client.sendVoice(chatId, document, { ...params, replyTo, businessConnectionId });
446
463
  },
447
- replyAudio: (document, params) => {
448
- const { chatId, messageId, businessConnectionId } = mustGetMsg();
464
+ replyAudio(document, params) {
465
+ const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
449
466
  const replyTo = getReplyTo(params?.quote, chatId, messageId);
450
- return this.sendAudio(chatId, document, { ...params, replyTo, businessConnectionId });
467
+ return this.client.sendAudio(chatId, document, { ...params, replyTo, businessConnectionId });
451
468
  },
452
- replyVideoNote: (videoNote, params) => {
453
- const { chatId, messageId, businessConnectionId } = mustGetMsg();
469
+ replyVideoNote(videoNote, params) {
470
+ const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
454
471
  const replyTo = getReplyTo(params?.quote, chatId, messageId);
455
- return this.sendVideoNote(chatId, videoNote, { ...params, replyTo, businessConnectionId });
472
+ return this.client.sendVideoNote(chatId, videoNote, { ...params, replyTo, businessConnectionId });
456
473
  },
457
- delete: () => {
458
- const { chatId, messageId } = mustGetMsg();
459
- return this.deleteMessage(chatId, messageId);
474
+ delete() {
475
+ const { chatId, messageId } = mustGetMsg(this);
476
+ return this.client.deleteMessage(chatId, messageId);
460
477
  },
461
- forward: (to, params) => {
462
- const { chatId, messageId } = mustGetMsg();
463
- return this.forwardMessage(chatId, to, messageId, params);
478
+ forward(to, params) {
479
+ const { chatId, messageId } = mustGetMsg(this);
480
+ return this.client.forwardMessage(chatId, to, messageId, params);
464
481
  },
465
- pin: (params) => {
466
- const { chatId, messageId, businessConnectionId } = mustGetMsg();
467
- return this.pinMessage(chatId, messageId, { ...params, businessConnectionId });
482
+ pin(params) {
483
+ const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
484
+ return this.client.pinMessage(chatId, messageId, { ...params, businessConnectionId });
468
485
  },
469
- unpin: () => {
470
- const { chatId, messageId, businessConnectionId } = mustGetMsg();
471
- return this.unpinMessage(chatId, messageId, { businessConnectionId });
486
+ unpin() {
487
+ const { chatId, messageId, businessConnectionId } = mustGetMsg(this);
488
+ return this.client.unpinMessage(chatId, messageId, { businessConnectionId });
472
489
  },
473
- banSender: (params) => {
474
- const { chatId, senderId } = mustGetMsg();
490
+ banSender(params) {
491
+ const { chatId, senderId } = mustGetMsg(this);
475
492
  if (!senderId) {
476
493
  unreachable();
477
494
  }
478
- return this.banChatMember(chatId, senderId, params);
495
+ return this.client.banChatMember(chatId, senderId, params);
479
496
  },
480
- kickSender: () => {
481
- const { chatId, senderId } = mustGetMsg();
497
+ kickSender() {
498
+ const { chatId, senderId } = mustGetMsg(this);
482
499
  if (!senderId) {
483
500
  unreachable();
484
501
  }
485
- return this.kickChatMember(chatId, senderId);
502
+ return this.client.kickChatMember(chatId, senderId);
486
503
  },
487
- setSenderRights: (params) => {
488
- const { chatId, senderId } = mustGetMsg();
504
+ setSenderRights(params) {
505
+ const { chatId, senderId } = mustGetMsg(this);
489
506
  if (!senderId) {
490
507
  unreachable();
491
508
  }
492
- return this.setChatMemberRights(chatId, senderId, params);
509
+ return this.client.setChatMemberRights(chatId, senderId, params);
493
510
  },
494
- getChatAdministrators: () => {
495
- const { chatId } = mustGetMsg();
496
- return this.getChatAdministrators(chatId);
511
+ getChatAdministrators() {
512
+ const { chatId } = mustGetMsg(this);
513
+ return this.client.getChatAdministrators(chatId);
497
514
  },
498
- react: (reactions, params) => {
499
- const { chatId, messageId } = mustGetMsg();
500
- return this.setReactions(chatId, messageId, reactions, params);
515
+ react(reactions, params) {
516
+ const { chatId, messageId } = mustGetMsg(this);
517
+ return this.client.setReactions(chatId, messageId, reactions, params);
501
518
  },
502
- answerCallbackQuery: (params) => {
519
+ answerCallbackQuery(params) {
503
520
  if (!("callbackQuery" in update)) {
504
521
  unreachable();
505
522
  }
506
- return this.answerCallbackQuery(update.callbackQuery.id, params);
523
+ return this.client.answerCallbackQuery(update.callbackQuery.id, params);
507
524
  },
508
- answerInlineQuery: (results, params) => {
525
+ answerInlineQuery(results, params) {
509
526
  if (!("inlineQuery" in update)) {
510
527
  unreachable();
511
528
  }
512
- return this.answerInlineQuery(update.inlineQuery.id, results, params);
529
+ return this.client.answerInlineQuery(update.inlineQuery.id, results, params);
513
530
  },
514
- sendChatAction: (chatAction, params) => {
515
- const { chatId } = mustGetMsg();
516
- return this.sendChatAction(chatId, chatAction, params);
531
+ sendChatAction(chatAction, params) {
532
+ const { chatId } = mustGetMsg(this);
533
+ return this.client.sendChatAction(chatId, chatAction, params);
517
534
  },
518
- editInlineMessageText: (text, params) => {
535
+ editInlineMessageText(text, params) {
519
536
  const inlineMessageId = mustGetInlineMsgId();
520
- return this.editInlineMessageText(inlineMessageId, text, params);
537
+ return this.client.editInlineMessageText(inlineMessageId, text, params);
521
538
  },
522
- editInlineMessageMedia: (media, params) => {
539
+ editInlineMessageMedia(media, params) {
523
540
  const inlineMessageId = mustGetInlineMsgId();
524
- return this.editInlineMessageMedia(inlineMessageId, media, params);
541
+ return this.client.editInlineMessageMedia(inlineMessageId, media, params);
525
542
  },
526
- editInlineMessageCaption: (params) => {
543
+ editInlineMessageCaption(params) {
527
544
  const inlineMessageId = mustGetInlineMsgId();
528
- return this.editInlineMessageCaption(inlineMessageId, params);
545
+ return this.client.editInlineMessageCaption(inlineMessageId, params);
529
546
  },
530
- editInlineMessageLiveLocation: (latitude, longitude, params) => {
547
+ editInlineMessageLiveLocation(latitude, longitude, params) {
531
548
  const inlineMessageId = mustGetInlineMsgId();
532
- return this.editInlineMessageLiveLocation(inlineMessageId, latitude, longitude, params);
549
+ return this.client.editInlineMessageLiveLocation(inlineMessageId, latitude, longitude, params);
533
550
  },
534
- editInlineMessageReplyMarkup: (params) => {
551
+ editInlineMessageReplyMarkup(params) {
535
552
  const inlineMessageId = mustGetInlineMsgId();
536
- return this.editInlineMessageReplyMarkup(inlineMessageId, params);
553
+ return this.client.editInlineMessageReplyMarkup(inlineMessageId, params);
537
554
  },
538
- editMessageText: (messageId, text, params) => {
539
- const { chatId } = mustGetMsg();
540
- return this.editMessageText(chatId, messageId, text, params);
555
+ editMessageText(messageId, text, params) {
556
+ const { chatId } = mustGetMsg(this);
557
+ return this.client.editMessageText(chatId, messageId, text, params);
541
558
  },
542
- editMessageCaption: (messageId, params) => {
543
- const { chatId } = mustGetMsg();
544
- return this.editMessageCaption(chatId, messageId, params);
559
+ editMessageCaption(messageId, params) {
560
+ const { chatId } = mustGetMsg(this);
561
+ return this.client.editMessageCaption(chatId, messageId, params);
545
562
  },
546
- editMessageMedia: (messageId, media, params) => {
547
- const { chatId } = mustGetMsg();
548
- return this.editMessageMedia(chatId, messageId, media, params);
563
+ editMessageMedia(messageId, media, params) {
564
+ const { chatId } = mustGetMsg(this);
565
+ return this.client.editMessageMedia(chatId, messageId, media, params);
549
566
  },
550
- editMessageLiveLocation: (messageId, latitude, longitude, params) => {
551
- const { chatId } = mustGetMsg();
552
- return this.editMessageLiveLocation(chatId, messageId, latitude, longitude, params);
567
+ editMessageLiveLocation(messageId, latitude, longitude, params) {
568
+ const { chatId } = mustGetMsg(this);
569
+ return this.client.editMessageLiveLocation(chatId, messageId, latitude, longitude, params);
553
570
  },
554
- editMessageReplyMarkup: (messageId, params) => {
555
- const { chatId } = mustGetMsg();
556
- return this.editMessageReplyMarkup(chatId, messageId, params);
571
+ editMessageReplyMarkup(messageId, params) {
572
+ const { chatId } = mustGetMsg(this);
573
+ return this.client.editMessageReplyMarkup(chatId, messageId, params);
557
574
  },
558
- getMessage: (messageId) => {
559
- const { chatId } = mustGetMsg();
560
- return this.getMessage(chatId, messageId);
575
+ getMessage(messageId) {
576
+ const { chatId } = mustGetMsg(this);
577
+ return this.client.getMessage(chatId, messageId);
561
578
  },
562
- getMessages: (messageIds) => {
563
- const { chatId } = mustGetMsg();
564
- return this.getMessages(chatId, messageIds);
579
+ getMessages(messageIds) {
580
+ const { chatId } = mustGetMsg(this);
581
+ return this.client.getMessages(chatId, messageIds);
565
582
  },
566
- forwardMessage: (to, messageId, params) => {
567
- const { chatId } = mustGetMsg();
568
- return this.forwardMessage(chatId, to, messageId, params);
583
+ forwardMessage(to, messageId, params) {
584
+ const { chatId } = mustGetMsg(this);
585
+ return this.client.forwardMessage(chatId, to, messageId, params);
569
586
  },
570
- forwardMessages: (to, messageIds, params) => {
571
- const { chatId } = mustGetMsg();
572
- return this.forwardMessages(chatId, to, messageIds, params);
587
+ forwardMessages(to, messageIds, params) {
588
+ const { chatId } = mustGetMsg(this);
589
+ return this.client.forwardMessages(chatId, to, messageIds, params);
573
590
  },
574
- deleteMessage: (messageId, params) => {
575
- const { chatId } = mustGetMsg();
576
- return this.deleteMessage(chatId, messageId, params);
591
+ deleteMessage(messageId, params) {
592
+ const { chatId } = mustGetMsg(this);
593
+ return this.client.deleteMessage(chatId, messageId, params);
577
594
  },
578
- deleteMessages: (messageIds, params) => {
579
- const { chatId } = mustGetMsg();
580
- return this.deleteMessages(chatId, messageIds, params);
595
+ deleteMessages(messageIds, params) {
596
+ const { chatId } = mustGetMsg(this);
597
+ return this.client.deleteMessages(chatId, messageIds, params);
581
598
  },
582
- pinMessage: (messageId, params) => {
583
- const { chatId } = mustGetMsg();
584
- return this.pinMessage(chatId, messageId, params);
599
+ pinMessage(messageId, params) {
600
+ const { chatId } = mustGetMsg(this);
601
+ return this.client.pinMessage(chatId, messageId, params);
585
602
  },
586
- unpinMessage: (messageId) => {
587
- const { chatId } = mustGetMsg();
588
- return this.unpinMessage(chatId, messageId);
603
+ unpinMessage(messageId) {
604
+ const { chatId } = mustGetMsg(this);
605
+ return this.client.unpinMessage(chatId, messageId);
589
606
  },
590
- unpinMessages: () => {
591
- const { chatId } = mustGetMsg();
592
- return this.unpinMessages(chatId);
607
+ unpinMessages() {
608
+ const { chatId } = mustGetMsg(this);
609
+ return this.client.unpinMessages(chatId);
593
610
  },
594
- setAvailableReactions: (availableReactions) => {
595
- const { chatId } = mustGetMsg();
596
- return this.setAvailableReactions(chatId, availableReactions);
611
+ setAvailableReactions(availableReactions) {
612
+ const { chatId } = mustGetMsg(this);
613
+ return this.client.setAvailableReactions(chatId, availableReactions);
597
614
  },
598
- addReaction: (messageId, reaction, params) => {
599
- const { chatId } = mustGetMsg();
600
- return this.addReaction(chatId, messageId, reaction, params);
615
+ addReaction(messageId, reaction, params) {
616
+ const { chatId } = mustGetMsg(this);
617
+ return this.client.addReaction(chatId, messageId, reaction, params);
601
618
  },
602
- removeReaction: (messageId, reaction) => {
603
- const { chatId } = mustGetMsg();
604
- return this.removeReaction(chatId, messageId, reaction);
619
+ removeReaction(messageId, reaction) {
620
+ const { chatId } = mustGetMsg(this);
621
+ return this.client.removeReaction(chatId, messageId, reaction);
605
622
  },
606
- setReactions: (messageId, reactions, params) => {
607
- const { chatId } = mustGetMsg();
608
- return this.setReactions(chatId, messageId, reactions, params);
623
+ setReactions(messageId, reactions, params) {
624
+ const { chatId } = mustGetMsg(this);
625
+ return this.client.setReactions(chatId, messageId, reactions, params);
609
626
  },
610
- read: () => {
611
- const { chatId, messageId } = mustGetMsg();
612
- return this.readMessages(chatId, messageId);
627
+ read() {
628
+ const { chatId, messageId } = mustGetMsg(this);
629
+ return this.client.readMessages(chatId, messageId);
613
630
  },
614
- setChatPhoto: (photo, params) => {
615
- const { chatId } = mustGetMsg();
616
- return this.setChatPhoto(chatId, photo, params);
631
+ setChatPhoto(photo, params) {
632
+ const { chatId } = mustGetMsg(this);
633
+ return this.client.setChatPhoto(chatId, photo, params);
617
634
  },
618
- deleteChatPhoto: () => {
619
- const { chatId } = mustGetMsg();
620
- return this.deleteChatPhoto(chatId);
635
+ deleteChatPhoto() {
636
+ const { chatId } = mustGetMsg(this);
637
+ return this.client.deleteChatPhoto(chatId);
621
638
  },
622
- banChatMember: (memberId, params) => {
623
- const { chatId } = mustGetMsg();
624
- return this.banChatMember(chatId, memberId, params);
639
+ banChatMember(memberId, params) {
640
+ const { chatId } = mustGetMsg(this);
641
+ return this.client.banChatMember(chatId, memberId, params);
625
642
  },
626
- unbanChatMember: (memberId) => {
627
- const { chatId } = mustGetMsg();
628
- return this.unbanChatMember(chatId, memberId);
643
+ unbanChatMember(memberId) {
644
+ const { chatId } = mustGetMsg(this);
645
+ return this.client.unbanChatMember(chatId, memberId);
629
646
  },
630
- kickChatMember: (memberId) => {
631
- const { chatId } = mustGetMsg();
632
- return this.kickChatMember(chatId, memberId);
647
+ kickChatMember(memberId) {
648
+ const { chatId } = mustGetMsg(this);
649
+ return this.client.kickChatMember(chatId, memberId);
633
650
  },
634
- setChatMemberRights: (memberId, params) => {
635
- const { chatId } = mustGetMsg();
636
- return this.setChatMemberRights(chatId, memberId, params);
651
+ setChatMemberRights(memberId, params) {
652
+ const { chatId } = mustGetMsg(this);
653
+ return this.client.setChatMemberRights(chatId, memberId, params);
637
654
  },
638
- deleteChatMemberMessages: (userId) => {
639
- const { chatId } = mustGetMsg();
640
- return this.deleteChatMemberMessages(chatId, userId);
655
+ deleteChatMemberMessages(userId) {
656
+ const { chatId } = mustGetMsg(this);
657
+ return this.client.deleteChatMemberMessages(chatId, userId);
641
658
  },
642
- searchMessages: (params) => {
643
- const { chatId } = mustGetMsg();
659
+ searchMessages(params) {
660
+ const { chatId } = mustGetMsg(this);
644
661
  params ??= {};
645
662
  params.chatId = chatId;
646
- return this.searchMessages(params);
663
+ return this.client.searchMessages(params);
647
664
  },
648
- setBoostsRequiredToCircumventRestrictions: (boosts) => {
649
- const { chatId } = mustGetMsg();
650
- return this.setBoostsRequiredToCircumventRestrictions(chatId, boosts);
665
+ setBoostsRequiredToCircumventRestrictions(boosts) {
666
+ const { chatId } = mustGetMsg(this);
667
+ return this.client.setBoostsRequiredToCircumventRestrictions(chatId, boosts);
651
668
  },
652
- createInviteLink: (params) => {
653
- const { chatId } = mustGetMsg();
654
- return this.createInviteLink(chatId, params);
669
+ createInviteLink(params) {
670
+ const { chatId } = mustGetMsg(this);
671
+ return this.client.createInviteLink(chatId, params);
655
672
  },
656
- getCreatedInviteLinks: (params) => {
657
- const { chatId } = mustGetMsg();
658
- return this.getCreatedInviteLinks(chatId, params);
673
+ getCreatedInviteLinks(params) {
674
+ const { chatId } = mustGetMsg(this);
675
+ return this.client.getCreatedInviteLinks(chatId, params);
659
676
  },
660
- leave: () => {
661
- const { chatId } = mustGetMsg();
662
- return this.leaveChat(chatId);
677
+ leave() {
678
+ const { chatId } = mustGetMsg(this);
679
+ return this.client.leaveChat(chatId);
663
680
  },
664
- block: () => {
665
- return this.blockUser(mustGetUserId());
681
+ block() {
682
+ return this.client.blockUser(mustGetUserId(this));
666
683
  },
667
- unblock: () => {
668
- return this.unblockUser(mustGetUserId());
684
+ unblock() {
685
+ return this.client.unblockUser(mustGetUserId(this));
669
686
  },
670
- getChatMember: (userId) => {
671
- const { chatId } = mustGetMsg();
672
- return this.getChatMember(chatId, userId);
687
+ getChatMember(userId) {
688
+ const { chatId } = mustGetMsg(this);
689
+ return this.client.getChatMember(chatId, userId);
673
690
  },
674
- getChatMembers: (params) => {
675
- const { chatId } = mustGetMsg();
676
- return this.getChatMembers(chatId, params);
691
+ getChatMembers(params) {
692
+ const { chatId } = mustGetMsg(this);
693
+ return this.client.getChatMembers(chatId, params);
677
694
  },
678
- setChatStickerSet: (setName) => {
679
- const { chatId } = mustGetMsg();
680
- return this.setChatStickerSet(chatId, setName);
695
+ setChatStickerSet(setName) {
696
+ const { chatId } = mustGetMsg(this);
697
+ return this.client.setChatStickerSet(chatId, setName);
681
698
  },
682
- deleteChatStickerSet: () => {
683
- const { chatId } = mustGetMsg();
684
- return this.deleteChatStickerSet(chatId);
699
+ deleteChatStickerSet() {
700
+ const { chatId } = mustGetMsg(this);
701
+ return this.client.deleteChatStickerSet(chatId);
685
702
  },
686
- getBusinessConnection: () => {
687
- const { businessConnectionId } = mustGetMsg();
703
+ getBusinessConnection() {
704
+ const { businessConnectionId } = mustGetMsg(this);
688
705
  if (!businessConnectionId) {
689
706
  unreachable();
690
707
  }
691
- return this.getBusinessConnection(businessConnectionId);
708
+ return this.client.getBusinessConnection(businessConnectionId);
692
709
  },
693
- answerPreCheckoutQuery: (ok, params) => {
710
+ answerPreCheckoutQuery(ok, params) {
694
711
  if (!("preCheckoutQuery" in update)) {
695
712
  unreachable();
696
713
  }
697
- return this.answerPreCheckoutQuery(update.preCheckoutQuery.id, ok, params);
714
+ return this.client.answerPreCheckoutQuery(update.preCheckoutQuery.id, ok, params);
698
715
  },
699
- approveJoinRequest: () => {
700
- const { chatId, userId } = mustGetMsg();
716
+ approveJoinRequest() {
717
+ const { chatId, userId } = mustGetMsg(this);
701
718
  if (!userId) {
702
719
  unreachable();
703
720
  }
704
- return this.approveJoinRequest(chatId, userId);
721
+ return this.client.approveJoinRequest(chatId, userId);
705
722
  },
706
- declineJoinRequest: () => {
707
- const { chatId, userId } = mustGetMsg();
723
+ declineJoinRequest() {
724
+ const { chatId, userId } = mustGetMsg(this);
708
725
  if (!userId) {
709
726
  unreachable();
710
727
  }
711
- return this.declineJoinRequest(chatId, userId);
728
+ return this.client.declineJoinRequest(chatId, userId);
712
729
  },
713
730
  };
714
731
  return cleanObject(context);
@@ -730,6 +747,7 @@ export class Client extends Composer {
730
747
  await this.storage.initialize();
731
748
  if (!this.#guaranteeUpdateDelivery) {
732
749
  await this.storage.deleteUpdates();
750
+ await this.storage.commit(true);
733
751
  }
734
752
  this.#storageInited = true;
735
753
  }
@@ -750,28 +768,39 @@ export class Client extends Composer {
750
768
  if (this.#authString && !this.#authStringImported) {
751
769
  await this.importAuthString(this.#authString);
752
770
  }
753
- const [authKey, dc] = await Promise.all([this.storage.getAuthKey(), this.storage.getDc()]);
754
- if (authKey !== null && dc !== null) {
755
- if (!this.#client || this.#client.dc !== dc) {
771
+ const auth = this.storage.auth.mustGet();
772
+ if (auth.authKey !== null && auth.dc !== null) {
773
+ if (!this.#client || this.#client.dc !== auth.dc) {
756
774
  this.#client?.disconnect();
757
- this.#setMainClient(this.#newClient(dc, true, false));
775
+ this.#setMainClient(this.#newClient(auth.dc, true, false));
758
776
  }
759
- await this.#client.setAuthKey(authKey);
777
+ await this.#client.setAuthKey(auth.authKey);
760
778
  if (this.#client.serverSalt === 0n) {
761
779
  this.#client.serverSalt = await this.storage.getServerSalt() ?? 0n;
762
780
  }
763
781
  }
764
782
  else {
765
- const dc = await this.storage.getDc() ?? this.#initialDc;
783
+ const dc = auth.dc ?? this.#initialDc;
766
784
  if (!this.#client || this.#client.dc !== dc) {
767
785
  this.#client?.disconnect();
768
786
  this.#setMainClient(this.#newClient(dc, true, false));
769
787
  }
770
788
  }
771
789
  await this.#client.connect();
772
- await Promise.all([this.storage.setAuthKey(this.#client.authKey), this.storage.setDc(this.#client.dc), this.storage.setServerSalt(this.#client.serverSalt)]);
773
- this.#startUpdateGapRecoveryLoop();
774
- this.#startClientDisconnectionLoop();
790
+ await this.storage.auth.update((v) => {
791
+ v.authKey = this.#client.authKey;
792
+ v.dc = this.#client.dc;
793
+ });
794
+ await this.storage.setServerSalt(this.#client.serverSalt);
795
+ this.#updateGapRecoveryLoop.start();
796
+ this.#clientDisconnectionLoop.start();
797
+ if (!this.#messageStorage_.isMemory) {
798
+ this.#storageWriteLoop.start();
799
+ }
800
+ else {
801
+ this.#L.debug("not starting storageWriteLoop");
802
+ }
803
+ await this.storage.commit(true);
775
804
  }
776
805
  finally {
777
806
  unlock();
@@ -783,16 +812,20 @@ export class Client extends Composer {
783
812
  newDc += "-test";
784
813
  }
785
814
  this.disconnect();
786
- await this.storage.setDc(newDc);
787
- await this.storage.setAuthKey(null);
815
+ await this.storage.auth.update((v) => {
816
+ v.authKey = null;
817
+ v.dc = newDc;
818
+ });
788
819
  await this.connect();
789
820
  this.#LhandleMigrationError.debug(`migrated to DC${newDc}`);
790
821
  }
791
- disconnect() {
822
+ async disconnect() {
792
823
  this.#disconnectAllClients();
793
- this.#clientDisconnectionLoopAbortController?.abort();
794
- this.#updateGapRecoveryLoopAbortController?.abort();
824
+ this.#clientDisconnectionLoop.abort();
825
+ this.#updateGapRecoveryLoop.abort();
826
+ this.#storageWriteLoop.abort();
795
827
  this.#updateManager.closeAllChats();
828
+ await this.messageStorage.commit(true);
796
829
  }
797
830
  #lastPropagatedAuthorizationState = null;
798
831
  async #propagateAuthorizationState(authorized) {
@@ -816,68 +849,50 @@ export class Client extends Composer {
816
849
  return this.#lastGetMe?.isPremium ?? false;
817
850
  }
818
851
  #lastUpdates = new Date();
819
- #updateGapRecoveryLoopAbortController;
820
- #startUpdateGapRecoveryLoop() {
821
- drop(this.#updateGapRecoveryLoop());
822
- }
823
- async #updateGapRecoveryLoop() {
824
- this.#updateGapRecoveryLoopAbortController?.abort();
825
- const controller = this.#updateGapRecoveryLoopAbortController = new AbortController();
826
- while (this.connected) {
827
- try {
828
- await delay(60 * SECOND, { signal: controller.signal });
829
- if (!this.connected) {
830
- break;
831
- }
832
- controller.signal.throwIfAborted();
833
- if (Date.now() - this.#lastUpdates.getTime() >= 15 * MINUTE) {
834
- drop(this.#updateManager.recoverUpdateGap("lastUpdates").then(() => {
835
- this.#lastUpdates = new Date();
836
- }));
837
- }
838
- }
839
- catch (err) {
840
- if (err instanceof DOMException && err.name === "AbortError") {
841
- break;
842
- }
843
- else if (!this.connected) {
844
- break;
845
- }
846
- this.#LupdateGapRecoveryLoop.error(err);
847
- }
852
+ #updateGapRecoveryLoop = new AbortableLoop(async (loop, signal) => {
853
+ await delay(60 * SECOND, { signal });
854
+ if (!this.connected) {
855
+ loop.abort();
856
+ return;
848
857
  }
849
- }
850
- #clientDisconnectionLoopAbortController;
851
- #startClientDisconnectionLoop() {
852
- drop(this.#clientDisconnectionLoop());
853
- }
854
- async #clientDisconnectionLoop() {
855
- const controller = this.#clientDisconnectionLoopAbortController = new AbortController();
856
- while (this.connected) {
857
- try {
858
- await delay(60 * SECOND, { signal: controller.signal });
859
- if (!this.connected) {
860
- break;
861
- }
862
- controller.signal.throwIfAborted();
863
- const now = Date.now();
864
- const disconnectAfter = 5 * MINUTE;
865
- this.#clients.map((client, i) => {
866
- if (i > 0 && !client.disconnected && client.lastRequest && now - client.lastRequest.getTime() >= disconnectAfter) {
867
- client?.disconnect();
868
- }
869
- });
870
- }
871
- catch (err) {
872
- if (err instanceof DOMException && err.name === "AbortError") {
873
- break;
874
- }
875
- else if (!this.connected) {
876
- break;
877
- }
858
+ if (Date.now() - this.#lastUpdates.getTime() >= 15 * MINUTE) {
859
+ drop(this.#updateManager.recoverUpdateGap("lastUpdates").then(() => {
860
+ this.#lastUpdates = new Date();
861
+ }));
862
+ }
863
+ }, (loop, err) => {
864
+ if (!this.connected) {
865
+ loop.abort();
866
+ }
867
+ else {
868
+ this.#LupdateGapRecoveryLoop.error(err);
869
+ }
870
+ });
871
+ #clientDisconnectionLoop = new AbortableLoop(async (loop, signal) => {
872
+ await delay(60 * SECOND, { signal });
873
+ if (!this.connected) {
874
+ loop.abort();
875
+ return;
876
+ }
877
+ const now = Date.now();
878
+ const disconnectAfter = 5 * MINUTE;
879
+ for (const [i, client] of this.#clients.entries()) {
880
+ if (i > 0 && !client.disconnected && client.lastRequest && now - client.lastRequest.getTime() >= disconnectAfter) {
881
+ client?.disconnect();
878
882
  }
879
883
  }
880
- }
884
+ }, (loop) => {
885
+ if (!this.connected) {
886
+ loop.abort();
887
+ }
888
+ });
889
+ #storageWriteLoop = new AbortableLoop(async (_loop, signal) => {
890
+ await delay(60 * SECOND, { signal });
891
+ await this.messageStorage.commit();
892
+ await this.storage.commit();
893
+ }, (err) => {
894
+ this.#LstorageWriteLoop.error(err);
895
+ });
881
896
  /**
882
897
  * Signs in using the provided parameters if not already signed in.
883
898
  * If no parameters are provided, the credentials will be prompted in runtime.
@@ -919,8 +934,11 @@ export class Client extends Composer {
919
934
  while (true) {
920
935
  try {
921
936
  const auth = await this.invoke({ _: "auth.importBotAuthorization", api_id: this.#apiId, api_hash: this.#apiHash, bot_auth_token: params.botToken, flags: 0 });
922
- await this.storage.setAccountId(Number(Api.as("auth.authorization", auth).user.id));
923
- await this.storage.setAccountType("bot");
937
+ await this.storage.auth.update((v) => {
938
+ v.userId = Number(Api.as("auth.authorization", auth).user.id);
939
+ v.isBot = true;
940
+ });
941
+ await this.storage.commit(true);
924
942
  break;
925
943
  }
926
944
  catch (err) {
@@ -986,8 +1004,10 @@ export class Client extends Composer {
986
1004
  phone_code: code,
987
1005
  phone_code_hash: sentCode.phone_code_hash,
988
1006
  });
989
- await this.storage.setAccountId(Number(Api.as("auth.authorization", auth).user.id));
990
- await this.storage.setAccountType("user");
1007
+ await this.storage.auth.update((v) => {
1008
+ v.userId = Number(Api.as("auth.authorization", auth).user.id);
1009
+ v.isBot = false;
1010
+ });
991
1011
  this.#LsignIn.debug("signed in as user");
992
1012
  await this.#propagateAuthorizationState(true);
993
1013
  await this.#updateManager.fetchState("signIn");
@@ -1015,8 +1035,11 @@ export class Client extends Composer {
1015
1035
  const password = typeof params.password === "string" ? params.password : await params.password(ap.hint ?? null);
1016
1036
  const input = await checkPassword(password, ap);
1017
1037
  const auth = await this.invoke({ _: "auth.checkPassword", password: input });
1018
- await this.storage.setAccountId(Number(Api.as("auth.authorization", auth).user.id));
1019
- await this.storage.setAccountType("user");
1038
+ await this.storage.auth.update((v) => {
1039
+ v.userId = Number(Api.as("auth.authorization", auth).user.id);
1040
+ v.isBot = false;
1041
+ });
1042
+ await this.storage.commit(true);
1020
1043
  this.#LsignIn.debug("signed in as user");
1021
1044
  await this.#propagateAuthorizationState(true);
1022
1045
  await this.#updateManager.fetchState("signIn");
@@ -1146,18 +1169,19 @@ export class Client extends Composer {
1146
1169
  async #setupClient(client) {
1147
1170
  const storage = client.dc === this.#client.dc ? this.storage : new StorageOperations(this.storage.provider.branch(client.dc + (client.cdn ? "_cdn" : "")));
1148
1171
  await storage.initialize();
1149
- const [authKey, serverSalt] = await Promise.all([storage.getAuthKey(), storage.getServerSalt()]);
1150
- if (authKey) {
1151
- await client.setAuthKey(authKey);
1172
+ const auth = storage.auth.mustGet();
1173
+ const serverSalt = await storage.getServerSalt();
1174
+ if (auth.authKey !== null) {
1175
+ await client.setAuthKey(auth.authKey);
1152
1176
  if (serverSalt) {
1153
1177
  client.serverSalt = serverSalt;
1154
1178
  }
1155
1179
  }
1156
1180
  await client.connect();
1157
- if (!authKey) {
1181
+ if (auth.authKey === null) {
1158
1182
  await this.#importAuthorization(client);
1159
1183
  }
1160
- await storage.setAuthKey(client.authKey);
1184
+ await storage.auth.update((v) => v.authKey = client.authKey);
1161
1185
  if (client.dc !== this.#client.dc) {
1162
1186
  await storage.setServerSalt(client.serverSalt);
1163
1187
  client.handlers.onNewServerSalt = async (serverSalt) => {
@@ -1167,9 +1191,10 @@ export class Client extends Composer {
1167
1191
  }
1168
1192
  async #importAuthorization(client) {
1169
1193
  if (this.#client.dc === client.dc && this.#client.cdn === client.cdn) {
1170
- const [authKey, serverSalt] = await Promise.all([this.storage.getAuthKey(), this.storage.getServerSalt()]);
1171
- if (authKey) {
1172
- await client.setAuthKey(authKey);
1194
+ const auth = this.storage.auth.mustGet();
1195
+ const serverSalt = await this.storage.getServerSalt();
1196
+ if (auth.authKey !== null) {
1197
+ await client.setAuthKey(auth.authKey);
1173
1198
  if (serverSalt) {
1174
1199
  client.serverSalt = serverSalt;
1175
1200
  }
@@ -1255,23 +1280,17 @@ export class Client extends Composer {
1255
1280
  await this.storage.importAuthString(authString);
1256
1281
  this.#authStringImported = true;
1257
1282
  if (!this.#apiId) {
1258
- this.#apiId = await this.storage.getApiId() ?? 0;
1283
+ this.#apiId = this.storage.auth.mustGet().apiId;
1259
1284
  }
1260
1285
  }
1261
1286
  async #getUserAccessHash(userId) {
1262
1287
  const users = await this.invoke({ _: "users.getUsers", id: [{ _: "inputUser", user_id: userId, access_hash: 0n }] });
1263
1288
  const user = Api.is("user", users[0]) ? users[0] : undefined;
1264
- if (user) {
1265
- await this.messageStorage.setEntity(user);
1266
- }
1267
1289
  return user?.access_hash ?? 0n;
1268
1290
  }
1269
1291
  async #getChannelAccessHash(channelId) {
1270
1292
  const channels = await this.invoke({ _: "channels.getChannels", id: [{ _: "inputChannel", channel_id: channelId, access_hash: 0n }] });
1271
1293
  const channel = Api.is("channel", channels.chats[0]) ? channels.chats[0] : undefined;
1272
- if (channel) {
1273
- await this.messageStorage.setEntity(channel);
1274
- }
1275
1294
  return channel?.access_hash ?? 0n;
1276
1295
  }
1277
1296
  /**
@@ -1284,7 +1303,7 @@ export class Client extends Composer {
1284
1303
  return { _: "inputPeerSelf" };
1285
1304
  }
1286
1305
  const inputPeer = await this.#getInputPeerInner(id);
1287
- if (((Api.is("inputPeerUser", inputPeer) || Api.is("inputPeerChannel", inputPeer)) && inputPeer.access_hash === 0n) && await this.storage.getAccountType() === "bot") {
1306
+ if (((Api.is("inputPeerUser", inputPeer) || Api.is("inputPeerChannel", inputPeer)) && inputPeer.access_hash === 0n) && this.storage.isBot) {
1288
1307
  if ("channel_id" in inputPeer) {
1289
1308
  inputPeer.access_hash = await this.#getChannelAccessHash(inputPeer.channel_id);
1290
1309
  }
@@ -1341,7 +1360,7 @@ export class Client extends Composer {
1341
1360
  if (typeof id === "string") {
1342
1361
  id = getUsername(id);
1343
1362
  let resolvedId = 0;
1344
- const maybeUsername = await this.messageStorage.getUsername(id);
1363
+ const maybeUsername = await this.messageStorage.usernames.get([id]);
1345
1364
  if (maybeUsername !== null && Date.now() - maybeUsername[1].getTime() < USERNAME_TTL) {
1346
1365
  const [id] = maybeUsername;
1347
1366
  resolvedId = id;
@@ -1388,22 +1407,23 @@ export class Client extends Composer {
1388
1407
  throw new InputError("The ID is of an format unknown.");
1389
1408
  }
1390
1409
  if (!Api.is("inputPeerChat", peer) && !peer.access_hash) {
1391
- const chatId = Api.peerToChatId(peer);
1392
- const minPeerReference = await this.messageStorage.getLastMinPeerReference(chatId);
1393
- if (minPeerReference) {
1394
- const minInputPeer = await this.#getMinInputPeer(canBeInputChannel(peer) ? "channel" : "user", { ...minPeerReference, senderId: chatId });
1395
- if (minInputPeer) {
1396
- this.#Lmin.debug("resolved input min peer", minInputPeer);
1397
- peer = minInputPeer;
1398
- }
1399
- }
1410
+ // TODO
1411
+ // const chatId = Api.peerToChatId(peer);
1412
+ // const minPeerReference = await this.messageStorage.getLastMinPeerReference(chatId);
1413
+ // if (minPeerReference) {
1414
+ // const minInputPeer = await this.#getMinInputPeer(canBeInputChannel(peer) ? "channel" : "user", { ...minPeerReference, senderId: chatId });
1415
+ // if (minInputPeer) {
1416
+ // this.#Lmin.debug("resolved input min peer", minInputPeer);
1417
+ // peer = minInputPeer;
1418
+ // }
1419
+ // }
1400
1420
  }
1401
1421
  return peer;
1402
1422
  }
1403
1423
  async #getMinInputPeer(type, reference) {
1404
- const entity = await this.messageStorage.getEntity(reference.chatId);
1405
- if (Api.isOneOf(["channel", "channelForbidden"], entity) && entity.access_hash) {
1406
- const peer = { _: "inputPeerChannel", channel_id: entity.id, access_hash: entity.access_hash };
1424
+ const peer_ = await this.messageStorage.peers.get([reference.chatId]);
1425
+ if (peer_ !== null && (peer_[0].type === "channel" || peer_[0].type === "supergroup")) {
1426
+ const peer = { _: "inputPeerChannel", channel_id: BigInt(peer_[0].id), access_hash: peer_[1] };
1407
1427
  if (type === "user") {
1408
1428
  return { _: "inputPeerUserFromMessage", peer, msg_id: reference.messageId, user_id: Api.chatIdToPeerId(reference.senderId) };
1409
1429
  }
@@ -1415,16 +1435,19 @@ export class Client extends Composer {
1415
1435
  return null;
1416
1436
  }
1417
1437
  }
1418
- async [getEntity](peer) {
1438
+ async [getPeer](peer) {
1419
1439
  const id = Api.peerToChatId(peer);
1420
- const entity = await this.messageStorage.getEntity(id);
1421
- if (entity === null && await this.storage.getAccountType() === "bot" && Api.is("peerUser", peer) || Api.is("peerChannel", peer)) {
1440
+ const entity = await this.messageStorage.peers.get([id]);
1441
+ if (entity === null && this.storage.isBot && Api.is("peerUser", peer) || Api.is("peerChannel", peer)) {
1422
1442
  await this.getInputPeer(id);
1423
1443
  }
1424
1444
  else {
1425
1445
  return entity;
1426
1446
  }
1427
- return await this.messageStorage.getEntity(id);
1447
+ return await this.messageStorage.peers.get([id]);
1448
+ }
1449
+ [mustGetPeer](peer) {
1450
+ return this.messageStorage.peers.mustGet([peerToChatId(peer)]);
1428
1451
  }
1429
1452
  async #handleCtxUpdate(update) {
1430
1453
  if (this.#disableUpdates && !("authorizationState" in update) && !("connectionState" in update)) {
@@ -1444,65 +1467,81 @@ export class Client extends Composer {
1444
1467
  });
1445
1468
  }
1446
1469
  async #handleUpdate(update) {
1447
- const promises = new Array();
1470
+ const maybePromises = new Array();
1448
1471
  if (Api.is("updateUserName", update)) {
1449
- await this.messageStorage.updateUsernames(Number(update.user_id), update.usernames.map((v) => v.username));
1472
+ const value = [Number(update.user_id), new Date()];
1473
+ for (const username_ of update.usernames) {
1474
+ const username = username_.username.toLowerCase();
1475
+ this.messageStorage.usernames.set([username], value);
1476
+ }
1450
1477
  const peer = { ...update, _: "peerUser" };
1451
- const entity = await this[getEntity](peer);
1452
- if (entity !== null) {
1453
- entity.usernames = update.usernames;
1454
- entity.first_name = update.first_name;
1455
- entity.last_name = update.last_name;
1456
- await this.messageStorage.setEntity(entity);
1478
+ const peer_ = await this[getPeer](peer);
1479
+ if (peer_ !== null) {
1480
+ const username = update.usernames[0];
1481
+ if (username !== undefined) {
1482
+ peer_[0].username = username.username;
1483
+ const also = update.usernames.filter((v) => v !== username);
1484
+ if (also.length) {
1485
+ peer_[0].also = also.map((v) => v.username);
1486
+ }
1487
+ else {
1488
+ delete peer_[0].also;
1489
+ }
1490
+ }
1491
+ else {
1492
+ delete peer_[0].username;
1493
+ }
1494
+ this.messageStorage.setPeer2(peer_[0], peer_[1]);
1457
1495
  }
1458
1496
  }
1459
1497
  if (this.#messageManager.canHandleUpdate(update)) {
1460
- promises.push(() => this.#messageManager.handleUpdate(update));
1498
+ maybePromises.push(() => this.#messageManager.handleUpdate(update));
1461
1499
  }
1462
1500
  if (this.#chatManager.canHandleUpdate(update)) {
1463
- promises.push(() => this.#chatManager.handleUpdate(update));
1501
+ maybePromises.push(() => this.#chatManager.handleUpdate(update));
1464
1502
  }
1465
1503
  if (this.#pollManager.canHandleUpdate(update)) {
1466
- promises.push(() => this.#pollManager.handleUpdate(update));
1504
+ maybePromises.push(() => this.#pollManager.handleUpdate(update));
1467
1505
  }
1468
1506
  if (this.#videoChatManager.canHandleUpdate(update)) {
1469
- promises.push(() => this.#videoChatManager.handleUpdate(update));
1507
+ maybePromises.push(() => this.#videoChatManager.handleUpdate(update));
1470
1508
  }
1471
1509
  if (this.#callbackQueryManager.canHandleUpdate(update)) {
1472
- promises.push(() => this.#callbackQueryManager.handleUpdate(update));
1510
+ maybePromises.push(() => this.#callbackQueryManager.handleUpdate(update));
1473
1511
  }
1474
1512
  if (this.#inlineQueryManager.canHandleUpdate(update)) {
1475
- promises.push(() => this.#inlineQueryManager.handleUpdate(update));
1513
+ maybePromises.push(() => this.#inlineQueryManager.handleUpdate(update));
1476
1514
  }
1477
1515
  if (this.#linkPreviewManager.canHandleUpdate(update)) {
1478
- promises.push(() => this.#linkPreviewManager.handleUpdate(update));
1516
+ maybePromises.push(() => this.#linkPreviewManager.handleUpdate(update));
1479
1517
  }
1480
1518
  if (this.#reactionManager.canHandleUpdate(update)) {
1481
- promises.push(() => this.#reactionManager.handleUpdate(update));
1519
+ maybePromises.push(() => this.#reactionManager.handleUpdate(update));
1482
1520
  }
1483
1521
  if (this.#chatListManager.canHandleUpdate(update)) {
1484
- promises.push(() => this.#chatListManager.handleUpdate(update));
1522
+ maybePromises.push(() => this.#chatListManager.handleUpdate(update));
1485
1523
  }
1486
1524
  if (this.#storyManager.canHandleUpdate(update)) {
1487
- promises.push(() => this.#storyManager.handleUpdate(update));
1525
+ maybePromises.push(() => this.#storyManager.handleUpdate(update));
1488
1526
  }
1489
1527
  if (this.#businessConnectionManager.canHandleUpdate(update)) {
1490
- promises.push(() => this.#businessConnectionManager.handleUpdate(update));
1528
+ maybePromises.push(() => this.#businessConnectionManager.handleUpdate(update));
1491
1529
  }
1492
1530
  if (this.#storyManager.canHandleUpdate(update)) {
1493
- promises.push(() => this.#storyManager.handleUpdate(update));
1531
+ maybePromises.push(() => this.#storyManager.handleUpdate(update));
1494
1532
  }
1495
1533
  if (this.#paymentManager.canHandleUpdate(update)) {
1496
- promises.push(() => this.#paymentManager.handleUpdate(update));
1534
+ maybePromises.push(() => this.#paymentManager.handleUpdate(update));
1497
1535
  }
1498
1536
  if (this.#translationsManager.canHandleUpdate(update)) {
1499
- promises.push(() => this.#translationsManager.handleUpdate(update));
1537
+ maybePromises.push(() => this.#translationsManager.handleUpdate(update));
1500
1538
  }
1501
1539
  return () => Promise.resolve().then(async () => {
1502
- const updates = new Array();
1503
- for (const promise of promises) {
1540
+ const updates = [{ update }];
1541
+ for (const maybePromise of maybePromises) {
1504
1542
  try {
1505
- const update = await promise();
1543
+ const value = maybePromise();
1544
+ const update = value instanceof Promise ? await value : value;
1506
1545
  if (update) {
1507
1546
  updates.push(update);
1508
1547
  }
@@ -1519,7 +1558,6 @@ export class Client extends Composer {
1519
1558
  if ("deletedMessages" in update) {
1520
1559
  for (const { chatId, messageId } of update.deletedMessages) {
1521
1560
  await this.messageStorage.setMessage(chatId, messageId, null);
1522
- await this.#chatListManager.reassignChatLastMessage(chatId);
1523
1561
  }
1524
1562
  }
1525
1563
  }
@@ -1560,14 +1598,13 @@ export class Client extends Composer {
1560
1598
  * @method ac
1561
1599
  */
1562
1600
  async getMe() {
1563
- let user_ = await this[getEntity]({ _: "peerUser", user_id: BigInt(await this.#getSelfId()) });
1564
- if (user_ === null) {
1601
+ let chatP = (await this[getPeer]({ _: "peerUser", user_id: BigInt(await this.#getSelfId()) }))?.[0] ?? null;
1602
+ if (chatP === null) {
1565
1603
  const users = await this.invoke({ _: "users.getUsers", id: [{ _: "inputUserSelf" }] });
1566
- user_ = Api.as("user", users[0]);
1567
- await this.messageStorage.setEntity(user_);
1568
- await this.storage.setIsPremium(user_.premium ?? false);
1604
+ chatP = constructChatP(Api.as("user", users[0]));
1605
+ await this.storage.setIsPremium(chatP.isPremium);
1569
1606
  }
1570
- const user = constructUser(user_);
1607
+ const user = constructUser2(chatP);
1571
1608
  this.#lastGetMe = user;
1572
1609
  return user;
1573
1610
  }
@@ -2810,9 +2847,10 @@ export class Client extends Composer {
2810
2847
  * @method ch
2811
2848
  * @param chatId The identifier of the group.
2812
2849
  * @param enabled Whether topics should be enabled in the group.
2850
+ * @param tabs Whether topics should be displayed as tabs.
2813
2851
  */
2814
- async setTopicsEnabled(chatId, enabled) {
2815
- await this.#chatManager.setTopicsEnabled(chatId, enabled);
2852
+ async setTopicsEnabled(chatId, enabled, tabs) {
2853
+ await this.#chatManager.setTopicsEnabled(chatId, enabled, tabs);
2816
2854
  }
2817
2855
  /**
2818
2856
  * Enable or disable automatic anti-spam in a group. User-only.