@mtkruto/node 0.62.1 → 0.63.0

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 (511) hide show
  1. package/esm/2_tl.d.ts +6 -6
  2. package/esm/2_tl.d.ts.map +1 -1
  3. package/esm/2_tl.js +6 -6
  4. package/esm/3_errors.d.ts +1 -2
  5. package/esm/3_errors.d.ts.map +1 -1
  6. package/esm/3_errors.js +2 -1
  7. package/esm/4_constants.d.ts +0 -1
  8. package/esm/4_constants.d.ts.map +1 -1
  9. package/esm/4_constants.js +0 -1
  10. package/esm/4_errors.d.ts +2 -2
  11. package/esm/4_errors.d.ts.map +1 -1
  12. package/esm/4_session.d.ts +24 -0
  13. package/esm/4_session.d.ts.map +1 -0
  14. package/esm/4_session.js +23 -0
  15. package/esm/5_client.d.ts +1 -1
  16. package/esm/5_client.js +1 -1
  17. package/esm/client/0_client_abstract.d.ts +28 -26
  18. package/esm/client/0_client_abstract.d.ts.map +1 -1
  19. package/esm/client/0_client_abstract.js +16 -88
  20. package/esm/client/0_params.d.ts +5 -0
  21. package/esm/client/0_params.d.ts.map +1 -1
  22. package/esm/client/0_password.d.ts.map +1 -1
  23. package/esm/client/0_password.js +2 -2
  24. package/esm/client/0_storage_operations.d.ts +4 -4
  25. package/esm/client/0_storage_operations.d.ts.map +1 -1
  26. package/esm/client/0_storage_operations.js +14 -14
  27. package/esm/client/0_update_processor.d.ts +19 -0
  28. package/esm/client/0_update_processor.d.ts.map +1 -1
  29. package/esm/client/0_update_processor.js +19 -0
  30. package/esm/client/0_utilities.d.ts +6 -2
  31. package/esm/client/0_utilities.d.ts.map +1 -1
  32. package/esm/client/0_utilities.js +21 -23
  33. package/esm/client/1_client_plain.d.ts +9 -6
  34. package/esm/client/1_client_plain.d.ts.map +1 -1
  35. package/esm/client/1_client_plain.js +26 -41
  36. package/esm/client/1_types.d.ts +4 -23
  37. package/esm/client/1_types.d.ts.map +1 -1
  38. package/esm/client/2_account_manager.js +10 -10
  39. package/esm/client/2_business_connection_manager.d.ts.map +1 -1
  40. package/esm/client/2_business_connection_manager.js +4 -4
  41. package/esm/client/2_client_encrypted.d.ts +58 -0
  42. package/esm/client/2_client_encrypted.d.ts.map +1 -0
  43. package/esm/client/2_client_encrypted.js +265 -0
  44. package/esm/client/2_file_manager.d.ts.map +1 -1
  45. package/esm/client/2_file_manager.js +54 -74
  46. package/esm/client/2_network_statistics_manager.d.ts +1 -1
  47. package/esm/client/2_network_statistics_manager.d.ts.map +1 -1
  48. package/esm/client/2_network_statistics_manager.js +3 -3
  49. package/esm/client/2_payment_manager.d.ts.map +1 -1
  50. package/esm/client/2_payment_manager.js +3 -3
  51. package/esm/client/2_reaction_manager.d.ts.map +1 -1
  52. package/esm/client/2_reaction_manager.js +10 -10
  53. package/esm/client/2_translations_manager.d.ts +19 -0
  54. package/esm/client/2_translations_manager.d.ts.map +1 -1
  55. package/esm/client/2_translations_manager.js +24 -5
  56. package/esm/client/2_update_manager.d.ts +4 -4
  57. package/esm/client/2_update_manager.d.ts.map +1 -1
  58. package/esm/client/2_update_manager.js +69 -79
  59. package/esm/client/3_client_encrypted_pool.d.ts +30 -0
  60. package/esm/client/3_client_encrypted_pool.d.ts.map +1 -0
  61. package/esm/client/3_client_encrypted_pool.js +70 -0
  62. package/esm/client/3_message_manager.d.ts.map +1 -1
  63. package/esm/client/3_message_manager.js +96 -70
  64. package/esm/client/3_video_chat_manager.d.ts.map +1 -1
  65. package/esm/client/3_video_chat_manager.js +15 -20
  66. package/esm/client/4_callback_query_manager.d.ts.map +1 -1
  67. package/esm/client/4_callback_query_manager.js +2 -2
  68. package/esm/client/4_chat_list_manager.d.ts.map +1 -1
  69. package/esm/client/4_chat_list_manager.js +33 -33
  70. package/esm/client/4_chat_manager.d.ts.map +1 -1
  71. package/esm/client/4_chat_manager.js +25 -25
  72. package/esm/client/4_gift_manager.js +2 -2
  73. package/esm/client/4_inline_query_manager.d.ts.map +1 -1
  74. package/esm/client/4_inline_query_manager.js +4 -4
  75. package/esm/client/4_poll_manager.d.ts.map +1 -1
  76. package/esm/client/4_poll_manager.js +5 -5
  77. package/esm/client/4_story_manager.d.ts.map +1 -1
  78. package/esm/client/4_story_manager.js +10 -10
  79. package/esm/client/5_client.d.ts +3 -9
  80. package/esm/client/5_client.d.ts.map +1 -1
  81. package/esm/client/5_client.js +290 -306
  82. package/esm/connection/0_connection.d.ts +5 -4
  83. package/esm/connection/0_connection.d.ts.map +1 -1
  84. package/esm/connection/1_connection_web_socket.js +2 -2
  85. package/esm/mod.d.ts +1 -1
  86. package/esm/mod.d.ts.map +1 -1
  87. package/esm/mod.js +1 -1
  88. package/{script/tl/2_tl_reader.d.ts → esm/session/0_session_error.d.ts} +4 -7
  89. package/esm/session/0_session_error.d.ts.map +1 -0
  90. package/esm/{tl/2_tl_reader.d.ts → session/0_session_error.js} +5 -7
  91. package/esm/{tl/2_tl_writer.d.ts → session/0_session_state.d.ts} +7 -5
  92. package/esm/session/0_session_state.d.ts.map +1 -0
  93. package/esm/session/0_session_state.js +77 -0
  94. package/esm/session/1_session.d.ts +31 -0
  95. package/esm/session/1_session.d.ts.map +1 -0
  96. package/esm/session/1_session.js +149 -0
  97. package/esm/session/2_session_encrypted.d.ts +40 -0
  98. package/esm/session/2_session_encrypted.d.ts.map +1 -0
  99. package/esm/session/2_session_encrypted.js +416 -0
  100. package/esm/session/2_session_plain.d.ts +25 -0
  101. package/esm/session/2_session_plain.d.ts.map +1 -0
  102. package/esm/session/2_session_plain.js +56 -0
  103. package/esm/tl/0_tl_error.d.ts +22 -0
  104. package/esm/tl/0_tl_error.d.ts.map +1 -0
  105. package/esm/tl/0_tl_error.js +21 -0
  106. package/esm/tl/0_types.d.ts +25 -0
  107. package/esm/tl/0_types.d.ts.map +1 -0
  108. package/esm/tl/0_types.js +20 -0
  109. package/esm/tl/0_utilities.d.ts +32 -0
  110. package/esm/tl/0_utilities.d.ts.map +1 -0
  111. package/esm/tl/0_utilities.js +51 -0
  112. package/esm/tl/0_utilities_test.d.ts.map +1 -0
  113. package/esm/tl/1_mtproto_api.d.ts +371 -0
  114. package/esm/tl/1_mtproto_api.d.ts.map +1 -0
  115. package/esm/tl/1_mtproto_api.js +416 -0
  116. package/esm/tl/{0_api.d.ts → 1_telegram_api.d.ts} +23 -340
  117. package/esm/tl/1_telegram_api.d.ts.map +1 -0
  118. package/esm/tl/{0_api.js → 1_telegram_api.js} +4945 -11109
  119. package/{script/tl/0_tl_raw_reader.d.ts → esm/tl/1_tl_reader.d.ts} +5 -2
  120. package/esm/tl/1_tl_reader.d.ts.map +1 -0
  121. package/esm/tl/{2_tl_reader.js → 1_tl_reader.js} +107 -40
  122. package/esm/tl/1_tl_reader_test.d.ts.map +1 -0
  123. package/esm/tl/{0_tl_raw_writer.d.ts → 1_tl_writer.d.ts} +5 -2
  124. package/esm/tl/1_tl_writer.d.ts.map +1 -0
  125. package/esm/tl/{2_tl_writer.js → 1_tl_writer.js} +80 -23
  126. package/esm/tl/1_tl_writer_test.d.ts.map +1 -0
  127. package/esm/tl/1_utilities.d.ts +9 -24
  128. package/esm/tl/1_utilities.d.ts.map +1 -1
  129. package/esm/tl/1_utilities.js +18 -64
  130. package/esm/tl/2_message.d.ts +2 -2
  131. package/esm/tl/2_message.d.ts.map +1 -1
  132. package/esm/tl/2_message.js +7 -7
  133. package/esm/tl/2_mtproto.d.ts +33 -0
  134. package/esm/tl/2_mtproto.d.ts.map +1 -0
  135. package/esm/tl/2_mtproto.js +53 -0
  136. package/{script/tl/2_utilities.d.ts → esm/tl/2_telegram.d.ts} +16 -2
  137. package/esm/tl/2_telegram.d.ts.map +1 -0
  138. package/esm/tl/{2_utilities.js → 2_telegram.js} +46 -1
  139. package/esm/transport/0_transport.d.ts +1 -1
  140. package/esm/transport/0_transport.d.ts.map +1 -1
  141. package/esm/types/0_chat_photo.d.ts.map +1 -1
  142. package/esm/types/0_chat_photo.js +2 -2
  143. package/esm/types/0_giveaway_parameters.d.ts.map +1 -1
  144. package/esm/types/0_giveaway_parameters.js +3 -3
  145. package/esm/types/0_location.d.ts.map +1 -1
  146. package/esm/types/0_location.js +5 -5
  147. package/esm/types/0_message_entity.d.ts.map +1 -1
  148. package/esm/types/0_message_entity.js +20 -20
  149. package/esm/types/0_reaction.d.ts.map +1 -1
  150. package/esm/types/0_reaction.js +4 -4
  151. package/esm/types/0_slow_mode_duration.d.ts +19 -0
  152. package/esm/types/0_slow_mode_duration.d.ts.map +1 -1
  153. package/esm/types/0_slow_mode_duration.js +19 -0
  154. package/esm/types/0_thumbnail.d.ts.map +1 -1
  155. package/esm/types/0_thumbnail.js +3 -3
  156. package/esm/types/0_translation.d.ts +19 -0
  157. package/esm/types/0_translation.d.ts.map +1 -1
  158. package/esm/types/0_translation.js +22 -3
  159. package/esm/types/0_video_chat.d.ts.map +1 -1
  160. package/esm/types/0_video_chat.js +2 -2
  161. package/esm/types/1_animation.d.ts.map +1 -1
  162. package/esm/types/1_animation.js +2 -2
  163. package/esm/types/1_audio.d.ts.map +1 -1
  164. package/esm/types/1_audio.js +2 -2
  165. package/esm/types/1_bot_command_scope.d.ts.map +1 -1
  166. package/esm/types/1_bot_command_scope.js +2 -2
  167. package/esm/types/1_chat_p.d.ts.map +1 -1
  168. package/esm/types/1_chat_p.js +6 -6
  169. package/esm/types/1_document.d.ts.map +1 -1
  170. package/esm/types/1_document.js +2 -2
  171. package/esm/types/1_keyboard_button.d.ts.map +1 -1
  172. package/esm/types/1_keyboard_button.js +10 -10
  173. package/esm/types/1_message_reaction.d.ts.map +1 -1
  174. package/esm/types/1_message_reaction.js +6 -6
  175. package/esm/types/1_photo.d.ts.map +1 -1
  176. package/esm/types/1_photo.js +3 -3
  177. package/esm/types/1_sticker.d.ts.map +1 -1
  178. package/esm/types/1_sticker.js +8 -8
  179. package/esm/types/1_story_privacy.d.ts.map +1 -1
  180. package/esm/types/1_story_privacy.js +7 -7
  181. package/esm/types/1_user.d.ts.map +1 -1
  182. package/esm/types/1_user.js +2 -2
  183. package/esm/types/1_venue.d.ts.map +1 -1
  184. package/esm/types/1_venue.js +2 -2
  185. package/esm/types/1_video.d.ts.map +1 -1
  186. package/esm/types/1_video.js +2 -2
  187. package/esm/types/1_video_note.d.ts.map +1 -1
  188. package/esm/types/1_video_note.js +2 -2
  189. package/esm/types/2_chat.d.ts.map +1 -1
  190. package/esm/types/2_chat.js +8 -8
  191. package/esm/types/2_chat_member.d.ts.map +1 -1
  192. package/esm/types/2_chat_member.js +10 -10
  193. package/esm/types/2_chat_settings.d.ts +19 -0
  194. package/esm/types/2_chat_settings.d.ts.map +1 -1
  195. package/esm/types/2_chat_settings.js +21 -2
  196. package/esm/types/2_chosen_inline_result.d.ts.map +1 -1
  197. package/esm/types/2_chosen_inline_result.js +4 -4
  198. package/esm/types/2_game.d.ts.map +1 -1
  199. package/esm/types/2_game.js +4 -4
  200. package/esm/types/2_gift_upgraded_component.d.ts.map +1 -1
  201. package/esm/types/2_gift_upgraded_component.js +3 -3
  202. package/esm/types/2_inactive_chat.d.ts.map +1 -1
  203. package/esm/types/2_inactive_chat.js +2 -2
  204. package/esm/types/2_inline_keyboard_button.d.ts.map +1 -1
  205. package/esm/types/2_inline_keyboard_button.js +10 -10
  206. package/esm/types/2_inline_query.d.ts.map +1 -1
  207. package/esm/types/2_inline_query.js +7 -7
  208. package/esm/types/2_message_reactions.d.ts.map +1 -1
  209. package/esm/types/2_message_reactions.js +2 -2
  210. package/esm/types/2_story_content.d.ts.map +1 -1
  211. package/esm/types/2_story_content.js +6 -6
  212. package/esm/types/2_story_interactive_area.d.ts.map +1 -1
  213. package/esm/types/2_story_interactive_area.js +9 -9
  214. package/esm/types/3_chat_member_updated.d.ts.map +1 -1
  215. package/esm/types/3_chat_member_updated.js +2 -2
  216. package/esm/types/3_gift.d.ts.map +1 -1
  217. package/esm/types/3_gift.js +3 -3
  218. package/esm/types/3_join_request.d.ts.map +1 -1
  219. package/esm/types/3_join_request.js +2 -2
  220. package/esm/types/3_reply_markup.d.ts.map +1 -1
  221. package/esm/types/3_reply_markup.js +5 -5
  222. package/esm/types/4_claimed_gift.d.ts.map +1 -1
  223. package/esm/types/4_claimed_gift.js +2 -2
  224. package/esm/types/4_inline_query_result.d.ts.map +1 -1
  225. package/esm/types/4_inline_query_result.js +14 -14
  226. package/esm/types/4_message.d.ts.map +1 -1
  227. package/esm/types/4_message.js +57 -57
  228. package/esm/types/5_callback_query.d.ts.map +1 -1
  229. package/esm/types/5_callback_query.js +6 -7
  230. package/esm/types/5_chat_list_item.d.ts.map +1 -1
  231. package/esm/types/5_chat_list_item.js +5 -5
  232. package/esm/types/5_claimed_gifts.d.ts.map +1 -1
  233. package/esm/types/5_claimed_gifts.js +6 -6
  234. package/esm/types/_file_id.d.ts.map +1 -1
  235. package/esm/types/_file_id.js +3 -3
  236. package/package.json +1 -1
  237. package/script/2_tl.d.ts +6 -6
  238. package/script/2_tl.d.ts.map +1 -1
  239. package/script/2_tl.js +11 -11
  240. package/script/3_errors.d.ts +1 -2
  241. package/script/3_errors.d.ts.map +1 -1
  242. package/script/3_errors.js +2 -1
  243. package/script/4_constants.d.ts +0 -1
  244. package/script/4_constants.d.ts.map +1 -1
  245. package/script/4_constants.js +1 -2
  246. package/script/4_errors.d.ts +2 -2
  247. package/script/4_errors.d.ts.map +1 -1
  248. package/script/4_session.d.ts +24 -0
  249. package/script/4_session.d.ts.map +1 -0
  250. package/script/4_session.js +39 -0
  251. package/script/5_client.d.ts +1 -1
  252. package/script/5_client.js +1 -1
  253. package/script/client/0_client_abstract.d.ts +28 -26
  254. package/script/client/0_client_abstract.d.ts.map +1 -1
  255. package/script/client/0_client_abstract.js +18 -113
  256. package/script/client/0_params.d.ts +5 -0
  257. package/script/client/0_params.d.ts.map +1 -1
  258. package/script/client/0_password.d.ts.map +1 -1
  259. package/script/client/0_password.js +1 -1
  260. package/script/client/0_storage_operations.d.ts +4 -4
  261. package/script/client/0_storage_operations.d.ts.map +1 -1
  262. package/script/client/0_storage_operations.js +13 -13
  263. package/script/client/0_update_processor.d.ts +19 -0
  264. package/script/client/0_update_processor.d.ts.map +1 -1
  265. package/script/client/0_update_processor.js +19 -0
  266. package/script/client/0_utilities.d.ts +6 -2
  267. package/script/client/0_utilities.d.ts.map +1 -1
  268. package/script/client/0_utilities.js +22 -24
  269. package/script/client/1_client_plain.d.ts +9 -6
  270. package/script/client/1_client_plain.d.ts.map +1 -1
  271. package/script/client/1_client_plain.js +25 -40
  272. package/script/client/1_types.d.ts +4 -23
  273. package/script/client/1_types.d.ts.map +1 -1
  274. package/script/client/2_account_manager.js +9 -9
  275. package/script/client/2_business_connection_manager.d.ts.map +1 -1
  276. package/script/client/2_business_connection_manager.js +3 -3
  277. package/script/client/2_client_encrypted.d.ts +58 -0
  278. package/script/client/2_client_encrypted.d.ts.map +1 -0
  279. package/script/client/2_client_encrypted.js +269 -0
  280. package/script/client/2_file_manager.d.ts.map +1 -1
  281. package/script/client/2_file_manager.js +52 -72
  282. package/script/client/2_network_statistics_manager.d.ts +1 -1
  283. package/script/client/2_network_statistics_manager.d.ts.map +1 -1
  284. package/script/client/2_network_statistics_manager.js +3 -3
  285. package/script/client/2_payment_manager.d.ts.map +1 -1
  286. package/script/client/2_payment_manager.js +2 -2
  287. package/script/client/2_reaction_manager.d.ts.map +1 -1
  288. package/script/client/2_reaction_manager.js +9 -9
  289. package/script/client/2_translations_manager.d.ts +19 -0
  290. package/script/client/2_translations_manager.d.ts.map +1 -1
  291. package/script/client/2_translations_manager.js +23 -4
  292. package/script/client/2_update_manager.d.ts +4 -4
  293. package/script/client/2_update_manager.d.ts.map +1 -1
  294. package/script/client/2_update_manager.js +68 -78
  295. package/script/client/3_client_encrypted_pool.d.ts +30 -0
  296. package/script/client/3_client_encrypted_pool.d.ts.map +1 -0
  297. package/script/client/3_client_encrypted_pool.js +74 -0
  298. package/script/client/3_message_manager.d.ts.map +1 -1
  299. package/script/client/3_message_manager.js +95 -69
  300. package/script/client/3_video_chat_manager.d.ts.map +1 -1
  301. package/script/client/3_video_chat_manager.js +14 -19
  302. package/script/client/4_callback_query_manager.d.ts.map +1 -1
  303. package/script/client/4_callback_query_manager.js +1 -1
  304. package/script/client/4_chat_list_manager.d.ts.map +1 -1
  305. package/script/client/4_chat_list_manager.js +32 -32
  306. package/script/client/4_chat_manager.d.ts.map +1 -1
  307. package/script/client/4_chat_manager.js +24 -24
  308. package/script/client/4_gift_manager.js +1 -1
  309. package/script/client/4_inline_query_manager.d.ts.map +1 -1
  310. package/script/client/4_inline_query_manager.js +3 -3
  311. package/script/client/4_poll_manager.d.ts.map +1 -1
  312. package/script/client/4_poll_manager.js +4 -4
  313. package/script/client/4_story_manager.d.ts.map +1 -1
  314. package/script/client/4_story_manager.js +9 -9
  315. package/script/client/5_client.d.ts +3 -9
  316. package/script/client/5_client.d.ts.map +1 -1
  317. package/script/client/5_client.js +284 -300
  318. package/script/connection/0_connection.d.ts +5 -4
  319. package/script/connection/0_connection.d.ts.map +1 -1
  320. package/script/connection/1_connection_web_socket.js +2 -2
  321. package/script/mod.d.ts +1 -1
  322. package/script/mod.d.ts.map +1 -1
  323. package/script/mod.js +1 -2
  324. package/script/session/0_session_error.d.ts +24 -0
  325. package/script/session/0_session_error.d.ts.map +1 -0
  326. package/script/session/0_session_error.js +29 -0
  327. package/script/{tl/2_tl_writer.d.ts → session/0_session_state.d.ts} +7 -5
  328. package/script/session/0_session_state.d.ts.map +1 -0
  329. package/script/session/0_session_state.js +81 -0
  330. package/script/session/1_session.d.ts +31 -0
  331. package/script/session/1_session.d.ts.map +1 -0
  332. package/script/session/1_session.js +176 -0
  333. package/script/session/2_session_encrypted.d.ts +40 -0
  334. package/script/session/2_session_encrypted.d.ts.map +1 -0
  335. package/script/session/2_session_encrypted.js +420 -0
  336. package/script/session/2_session_plain.d.ts +25 -0
  337. package/script/session/2_session_plain.d.ts.map +1 -0
  338. package/script/session/2_session_plain.js +60 -0
  339. package/script/tl/0_tl_error.d.ts +22 -0
  340. package/script/tl/0_tl_error.d.ts.map +1 -0
  341. package/script/tl/0_tl_error.js +25 -0
  342. package/script/tl/0_types.d.ts +25 -0
  343. package/script/tl/0_types.d.ts.map +1 -0
  344. package/script/tl/0_types.js +21 -0
  345. package/script/tl/0_utilities.d.ts +32 -0
  346. package/script/tl/0_utilities.d.ts.map +1 -0
  347. package/script/tl/0_utilities.js +59 -0
  348. package/script/tl/0_utilities_test.d.ts.map +1 -0
  349. package/script/tl/1_mtproto_api.d.ts +371 -0
  350. package/script/tl/1_mtproto_api.d.ts.map +1 -0
  351. package/script/tl/1_mtproto_api.js +419 -0
  352. package/script/tl/{0_api.d.ts → 1_telegram_api.d.ts} +23 -340
  353. package/script/tl/1_telegram_api.d.ts.map +1 -0
  354. package/script/tl/{0_api.js → 1_telegram_api.js} +4947 -11134
  355. package/{esm/tl/0_tl_raw_reader.d.ts → script/tl/1_tl_reader.d.ts} +5 -2
  356. package/script/tl/1_tl_reader.d.ts.map +1 -0
  357. package/script/tl/1_tl_reader.js +218 -0
  358. package/script/tl/1_tl_reader_test.d.ts.map +1 -0
  359. package/script/tl/{0_tl_raw_writer.d.ts → 1_tl_writer.d.ts} +5 -2
  360. package/script/tl/1_tl_writer.d.ts.map +1 -0
  361. package/script/tl/{2_tl_writer.js → 1_tl_writer.js} +102 -45
  362. package/script/tl/1_tl_writer_test.d.ts.map +1 -0
  363. package/script/tl/1_utilities.d.ts +9 -24
  364. package/script/tl/1_utilities.d.ts.map +1 -1
  365. package/script/tl/1_utilities.js +19 -72
  366. package/script/tl/2_message.d.ts +2 -2
  367. package/script/tl/2_message.d.ts.map +1 -1
  368. package/script/tl/2_message.js +7 -7
  369. package/script/tl/2_mtproto.d.ts +33 -0
  370. package/script/tl/2_mtproto.d.ts.map +1 -0
  371. package/script/tl/2_mtproto.js +78 -0
  372. package/{esm/tl/2_utilities.d.ts → script/tl/2_telegram.d.ts} +16 -2
  373. package/script/tl/2_telegram.d.ts.map +1 -0
  374. package/script/tl/2_telegram.js +167 -0
  375. package/script/transport/0_transport.d.ts +1 -1
  376. package/script/transport/0_transport.d.ts.map +1 -1
  377. package/script/types/0_chat_photo.d.ts.map +1 -1
  378. package/script/types/0_chat_photo.js +1 -1
  379. package/script/types/0_giveaway_parameters.d.ts.map +1 -1
  380. package/script/types/0_giveaway_parameters.js +2 -2
  381. package/script/types/0_location.d.ts.map +1 -1
  382. package/script/types/0_location.js +4 -4
  383. package/script/types/0_message_entity.d.ts.map +1 -1
  384. package/script/types/0_message_entity.js +19 -19
  385. package/script/types/0_reaction.d.ts.map +1 -1
  386. package/script/types/0_reaction.js +3 -3
  387. package/script/types/0_slow_mode_duration.d.ts +19 -0
  388. package/script/types/0_slow_mode_duration.d.ts.map +1 -1
  389. package/script/types/0_slow_mode_duration.js +19 -0
  390. package/script/types/0_thumbnail.d.ts.map +1 -1
  391. package/script/types/0_thumbnail.js +2 -2
  392. package/script/types/0_translation.d.ts +19 -0
  393. package/script/types/0_translation.d.ts.map +1 -1
  394. package/script/types/0_translation.js +21 -2
  395. package/script/types/0_video_chat.d.ts.map +1 -1
  396. package/script/types/0_video_chat.js +1 -1
  397. package/script/types/1_animation.d.ts.map +1 -1
  398. package/script/types/1_animation.js +1 -1
  399. package/script/types/1_audio.d.ts.map +1 -1
  400. package/script/types/1_audio.js +1 -1
  401. package/script/types/1_bot_command_scope.d.ts.map +1 -1
  402. package/script/types/1_bot_command_scope.js +1 -1
  403. package/script/types/1_chat_p.d.ts.map +1 -1
  404. package/script/types/1_chat_p.js +5 -5
  405. package/script/types/1_document.d.ts.map +1 -1
  406. package/script/types/1_document.js +1 -1
  407. package/script/types/1_keyboard_button.d.ts.map +1 -1
  408. package/script/types/1_keyboard_button.js +9 -9
  409. package/script/types/1_message_reaction.d.ts.map +1 -1
  410. package/script/types/1_message_reaction.js +5 -5
  411. package/script/types/1_photo.d.ts.map +1 -1
  412. package/script/types/1_photo.js +2 -2
  413. package/script/types/1_sticker.d.ts.map +1 -1
  414. package/script/types/1_sticker.js +7 -7
  415. package/script/types/1_story_privacy.d.ts.map +1 -1
  416. package/script/types/1_story_privacy.js +6 -6
  417. package/script/types/1_user.d.ts.map +1 -1
  418. package/script/types/1_user.js +1 -1
  419. package/script/types/1_venue.d.ts.map +1 -1
  420. package/script/types/1_venue.js +1 -1
  421. package/script/types/1_video.d.ts.map +1 -1
  422. package/script/types/1_video.js +1 -1
  423. package/script/types/1_video_note.d.ts.map +1 -1
  424. package/script/types/1_video_note.js +1 -1
  425. package/script/types/2_chat.d.ts.map +1 -1
  426. package/script/types/2_chat.js +7 -7
  427. package/script/types/2_chat_member.d.ts.map +1 -1
  428. package/script/types/2_chat_member.js +9 -9
  429. package/script/types/2_chat_settings.d.ts +19 -0
  430. package/script/types/2_chat_settings.d.ts.map +1 -1
  431. package/script/types/2_chat_settings.js +20 -1
  432. package/script/types/2_chosen_inline_result.d.ts.map +1 -1
  433. package/script/types/2_chosen_inline_result.js +3 -3
  434. package/script/types/2_game.d.ts.map +1 -1
  435. package/script/types/2_game.js +3 -3
  436. package/script/types/2_gift_upgraded_component.d.ts.map +1 -1
  437. package/script/types/2_gift_upgraded_component.js +2 -2
  438. package/script/types/2_inactive_chat.d.ts.map +1 -1
  439. package/script/types/2_inactive_chat.js +1 -1
  440. package/script/types/2_inline_keyboard_button.d.ts.map +1 -1
  441. package/script/types/2_inline_keyboard_button.js +9 -9
  442. package/script/types/2_inline_query.d.ts.map +1 -1
  443. package/script/types/2_inline_query.js +6 -6
  444. package/script/types/2_message_reactions.d.ts.map +1 -1
  445. package/script/types/2_message_reactions.js +1 -1
  446. package/script/types/2_story_content.d.ts.map +1 -1
  447. package/script/types/2_story_content.js +5 -5
  448. package/script/types/2_story_interactive_area.d.ts.map +1 -1
  449. package/script/types/2_story_interactive_area.js +8 -8
  450. package/script/types/3_chat_member_updated.d.ts.map +1 -1
  451. package/script/types/3_chat_member_updated.js +1 -1
  452. package/script/types/3_gift.d.ts.map +1 -1
  453. package/script/types/3_gift.js +2 -2
  454. package/script/types/3_join_request.d.ts.map +1 -1
  455. package/script/types/3_join_request.js +1 -1
  456. package/script/types/3_reply_markup.d.ts.map +1 -1
  457. package/script/types/3_reply_markup.js +4 -4
  458. package/script/types/4_claimed_gift.d.ts.map +1 -1
  459. package/script/types/4_claimed_gift.js +1 -1
  460. package/script/types/4_inline_query_result.d.ts.map +1 -1
  461. package/script/types/4_inline_query_result.js +13 -13
  462. package/script/types/4_message.d.ts.map +1 -1
  463. package/script/types/4_message.js +56 -56
  464. package/script/types/5_callback_query.d.ts.map +1 -1
  465. package/script/types/5_callback_query.js +5 -6
  466. package/script/types/5_chat_list_item.d.ts.map +1 -1
  467. package/script/types/5_chat_list_item.js +4 -4
  468. package/script/types/5_claimed_gifts.d.ts.map +1 -1
  469. package/script/types/5_claimed_gifts.js +5 -5
  470. package/script/types/_file_id.d.ts.map +1 -1
  471. package/script/types/_file_id.js +2 -2
  472. package/esm/client/0_message.d.ts +0 -29
  473. package/esm/client/0_message.d.ts.map +0 -1
  474. package/esm/client/0_message.js +0 -83
  475. package/esm/client/1_client_encrypted.d.ts +0 -52
  476. package/esm/client/1_client_encrypted.d.ts.map +0 -1
  477. package/esm/client/1_client_encrypted.js +0 -381
  478. package/esm/tl/0_api.d.ts.map +0 -1
  479. package/esm/tl/0_tl_raw_reader.d.ts.map +0 -1
  480. package/esm/tl/0_tl_raw_reader.js +0 -97
  481. package/esm/tl/0_tl_raw_reader_test.d.ts.map +0 -1
  482. package/esm/tl/0_tl_raw_writer.d.ts.map +0 -1
  483. package/esm/tl/0_tl_raw_writer.js +0 -86
  484. package/esm/tl/0_tl_raw_writer_test.d.ts.map +0 -1
  485. package/esm/tl/1_utilities_test.d.ts.map +0 -1
  486. package/esm/tl/2_tl_reader.d.ts.map +0 -1
  487. package/esm/tl/2_tl_reader_test.d.ts.map +0 -1
  488. package/esm/tl/2_tl_writer.d.ts.map +0 -1
  489. package/esm/tl/2_tl_writer_test.d.ts.map +0 -1
  490. package/esm/tl/2_utilities.d.ts.map +0 -1
  491. package/script/client/0_message.d.ts +0 -29
  492. package/script/client/0_message.d.ts.map +0 -1
  493. package/script/client/0_message.js +0 -90
  494. package/script/client/1_client_encrypted.d.ts +0 -52
  495. package/script/client/1_client_encrypted.d.ts.map +0 -1
  496. package/script/client/1_client_encrypted.js +0 -385
  497. package/script/tl/0_api.d.ts.map +0 -1
  498. package/script/tl/0_tl_raw_reader.d.ts.map +0 -1
  499. package/script/tl/0_tl_raw_reader.js +0 -102
  500. package/script/tl/0_tl_raw_reader_test.d.ts.map +0 -1
  501. package/script/tl/0_tl_raw_writer.d.ts.map +0 -1
  502. package/script/tl/0_tl_raw_writer.js +0 -90
  503. package/script/tl/0_tl_raw_writer_test.d.ts.map +0 -1
  504. package/script/tl/1_utilities_test.d.ts.map +0 -1
  505. package/script/tl/2_tl_reader.d.ts.map +0 -1
  506. package/script/tl/2_tl_reader.js +0 -150
  507. package/script/tl/2_tl_reader_test.d.ts.map +0 -1
  508. package/script/tl/2_tl_writer.d.ts.map +0 -1
  509. package/script/tl/2_tl_writer_test.d.ts.map +0 -1
  510. package/script/tl/2_utilities.d.ts.map +0 -1
  511. package/script/tl/2_utilities.js +0 -98
@@ -28,32 +28,32 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
28
28
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
29
29
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
30
30
  };
31
- var _Client_instances, _a, _Client_client, _Client_guaranteeUpdateDelivery, _Client_accountManager, _Client_botInfoManager, _Client_businessConnectionManager, _Client_fileManager, _Client_networkStatisticsManager, _Client_paymentManager, _Client_reactionManager, _Client_translationsManager, _Client_updateManager, _Client_messageManager, _Client_videoChatManager, _Client_callbackQueryManager, _Client_chatListManager, _Client_chatManager, _Client_forumManager, _Client_giftManager, _Client_inlineQueryManager, _Client_pollManager, _Client_storyManager, _Client_managers, _Client_storage_, _Client_messageStorage_, _Client_parseMode, _Client_apiId, _Client_apiHash, _Client_publicKeys, _Client_outgoingMessages, _Client_persistCache, _Client_disableUpdates, _Client_authString, _Client_cdn, _Client_L, _Client_LsignIn, _Client_LpingLoop, _Client_LhandleMigrationError, _Client_L$initConncetion, _Client_Lmin, _Client_reconnecting, _Client_reconnect, _Client_getApiId, _Client_getCdnConnectionPool, _Client_getCdnConnection, _Client_constructContext, _Client_propagateConnectionState, _Client_lastPropagatedConnectionState, _Client_stateChangeHandler, _Client_storageInited, _Client_initStorage, _Client_connectMutex, _Client_lastConnect, _Client_connectionInited, _Client_lastPropagatedAuthorizationState, _Client_propagateAuthorizationState, _Client_getSelfId, _Client_connectionInsuranceLoopStarted, _Client_connectionInsuranceLoopAbortController, _Client_startConnectionInsuranceLoop, _Client_connectionInsuranceLoop, _Client_pingLoopAbortController, _Client_pingInterval, _Client_lastUpdates, _Client_startPingLoop, _Client_pingLoop, _Client_invoke, _Client_handleInvokeError, _Client_authStringImported, _Client_getUserAccessHash, _Client_getChannelAccessHash, _Client_getInputPeerChatId, _Client_getInputPeerInner, _Client_getMinInputPeer, _Client_handleCtxUpdate, _Client_queueHandleCtxUpdate, _Client_handleUpdate, _Client_lastGetMe, _Client_getMe;
31
+ var _Client_instances, _Client_clients, _Client_downloadPools, _Client_uploadPools, _Client_guaranteeUpdateDelivery, _Client_accountManager, _Client_botInfoManager, _Client_businessConnectionManager, _Client_fileManager, _Client_networkStatisticsManager, _Client_paymentManager, _Client_reactionManager, _Client_translationsManager, _Client_updateManager, _Client_messageManager, _Client_videoChatManager, _Client_callbackQueryManager, _Client_chatListManager, _Client_chatManager, _Client_forumManager, _Client_giftManager, _Client_inlineQueryManager, _Client_pollManager, _Client_storyManager, _Client_managers, _Client_storage_, _Client_messageStorage_, _Client_parseMode, _Client_apiId, _Client_apiHash, _Client_transportProvider, _Client_publicKeys, _Client_outgoingMessages, _Client_persistCache, _Client_disableUpdates, _Client_authString, _Client_L, _Client_LsignIn, _Client_LupdateGapRecoveryLoop, _Client_LhandleMigrationError, _Client_Lmin, _Client_setMainClient, _Client_newClient, _Client_disconnectAllClients, _Client_client_get, _Client_getApiId, _Client_constructContext, _Client_propagateConnectionState, _Client_lastPropagatedConnectionState, _Client_stateChangeHandler, _Client_storageInited, _Client_initStorage, _Client_connectMutex, _Client_lastConnect, _Client_lastPropagatedAuthorizationState, _Client_propagateAuthorizationState, _Client_getSelfId, _Client_lastUpdates, _Client_updateGapRecoveryLoopAbortController, _Client_startUpdateGapRecoveryLoop, _Client_updateGapRecoveryLoop, _Client_clientDisconnectionLoopAbortController, _Client_startClientDisconnectionLoop, _Client_clientDisconnectionLoop, _Client_getClient, _Client_getMainClientMutex, _Client_getMainClient, _Client_getDownloadClient, _Client_getUploadClient, _Client_setupClient, _Client_importAuthorization, _Client_invoke, _Client_handleInvokeError, _Client_authStringImported, _Client_getUserAccessHash, _Client_getChannelAccessHash, _Client_getInputPeerChatId, _Client_getInputPeerInner, _Client_getMinInputPeer, _Client_handleCtxUpdate, _Client_queueHandleCtxUpdate, _Client_handleUpdate, _Client_lastGetMe, _Client_getMe, _Client_previouslyConnected, _Client_lastConnectionState, _Client_onConnectionStateChange;
32
32
  import { MINUTE, SECOND, unreachable } from "../0_deps.js";
33
33
  import { AccessError, ConnectionError, InputError } from "../0_errors.js";
34
- import { cleanObject, drop, getLogger, getRandomId, mustPrompt, mustPromptOneOf, Mutex, ZERO_CHANNEL_ID } from "../1_utilities.js";
34
+ import { cleanObject, drop, getLogger, mustPrompt, mustPromptOneOf, Mutex, ZERO_CHANNEL_ID } from "../1_utilities.js";
35
35
  import { StorageMemory } from "../2_storage.js";
36
- import { as, chatIdToPeerId, getChatIdPeerType, is, isOneOf, peerToChatId } from "../2_tl.js";
37
- import { getDc } from "../3_transport.js";
36
+ import { Api, Mtproto } from "../2_tl.js";
37
+ import { getDcId } from "../3_transport.js";
38
38
  import { constructUser } from "../3_types.js";
39
- import { APP_VERSION, DEVICE_MODEL, LANG_CODE, LANG_PACK, LAYER, MAX_CHANNEL_ID, MAX_CHAT_ID, SYSTEM_LANG_CODE, SYSTEM_VERSION, USERNAME_TTL } from "../4_constants.js";
40
- import { AuthKeyUnregistered, ConnectionNotInited, FloodWait, Migrate, PasswordHashInvalid, PhoneNumberInvalid, SessionPasswordNeeded, SessionRevoked } from "../4_errors.js";
39
+ 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";
40
+ import { AuthKeyUnregistered, FloodWait, Migrate, PasswordHashInvalid, PhoneNumberInvalid, SessionPasswordNeeded, SessionRevoked } from "../4_errors.js";
41
41
  import { PhoneCodeInvalid } from "../4_errors.js";
42
42
  import { checkPassword } from "./0_password.js";
43
43
  import { StorageOperations } from "./0_storage_operations.js";
44
- import { canBeInputChannel, canBeInputUser, getUsername, isCdnFunction, isMtprotoFunction, resolve, toInputChannel, toInputUser } from "./0_utilities.js";
45
- import { ClientEncrypted } from "./1_client_encrypted.js";
46
- import { ClientPlain } from "./1_client_plain.js";
44
+ import { canBeInputChannel, canBeInputUser, DOWNLOAD_POOL_SIZE, DOWNLOAD_REQUEST_PER_CONNECTION, getUsername, resolve, toInputChannel, toInputUser, UPLOAD_POOL_SIZE, UPLOAD_REQUEST_PER_CONNECTION } from "./0_utilities.js";
47
45
  import { Composer as Composer_ } from "./1_composer.js";
48
46
  import { AccountManager } from "./2_account_manager.js";
49
47
  import { BotInfoManager } from "./2_bot_info_manager.js";
50
48
  import { BusinessConnectionManager } from "./2_business_connection_manager.js";
49
+ import { ClientEncrypted } from "./2_client_encrypted.js";
51
50
  import { FileManager } from "./2_file_manager.js";
52
51
  import { NetworkStatisticsManager } from "./2_network_statistics_manager.js";
53
52
  import { PaymentManager } from "./2_payment_manager.js";
54
53
  import { ReactionManager } from "./2_reaction_manager.js";
55
54
  import { TranslationsManager } from "./2_translations_manager.js";
56
55
  import { UpdateManager } from "./2_update_manager.js";
56
+ import { ClientEncryptedPool } from "./3_client_encrypted_pool.js";
57
57
  import { MessageManager } from "./3_message_manager.js";
58
58
  import { VideoChatManager } from "./3_video_chat_manager.js";
59
59
  import { CallbackQueryManager } from "./4_callback_query_manager.js";
@@ -111,7 +111,9 @@ export class Client extends Composer {
111
111
  constructor(params) {
112
112
  super();
113
113
  _Client_instances.add(this);
114
- _Client_client.set(this, void 0);
114
+ _Client_clients.set(this, new Array());
115
+ _Client_downloadPools.set(this, {});
116
+ _Client_uploadPools.set(this, {});
115
117
  _Client_guaranteeUpdateDelivery.set(this, void 0);
116
118
  // 2_
117
119
  _Client_accountManager.set(this, void 0);
@@ -154,6 +156,7 @@ export class Client extends Composer {
154
156
  _Client_parseMode.set(this, void 0);
155
157
  _Client_apiId.set(this, void 0);
156
158
  _Client_apiHash.set(this, void 0);
159
+ _Client_transportProvider.set(this, void 0);
157
160
  Object.defineProperty(this, "appVersion", {
158
161
  enumerable: true,
159
162
  configurable: true,
@@ -195,14 +198,11 @@ export class Client extends Composer {
195
198
  _Client_persistCache.set(this, void 0);
196
199
  _Client_disableUpdates.set(this, void 0);
197
200
  _Client_authString.set(this, void 0);
198
- _Client_cdn.set(this, void 0);
199
201
  _Client_L.set(this, void 0);
200
202
  _Client_LsignIn.set(this, void 0);
201
- _Client_LpingLoop.set(this, void 0);
203
+ _Client_LupdateGapRecoveryLoop.set(this, void 0);
202
204
  _Client_LhandleMigrationError.set(this, void 0);
203
- _Client_L$initConncetion.set(this, void 0);
204
205
  _Client_Lmin.set(this, void 0);
205
- _Client_reconnecting.set(this, false);
206
206
  _Client_constructContext.set(this, async (update) => {
207
207
  const msg = "message" in update ? update.message : "editedMessage" in update ? update.editedMessage : "scheduledMessage" in update ? update.scheduledMessage : "callbackQuery" in update ? update.callbackQuery.message : undefined;
208
208
  const reactions = "messageInteractions" in update ? update.messageInteractions : undefined;
@@ -607,7 +607,6 @@ export class Client extends Composer {
607
607
  });
608
608
  _Client_lastPropagatedConnectionState.set(this, null);
609
609
  _Client_stateChangeHandler.set(this, ((connected) => {
610
- drop(__classPrivateFieldGet(this, _Client_instances, "m", _Client_reconnect).call(this));
611
610
  const connectionState = connected ? "ready" : "notConnected";
612
611
  if (__classPrivateFieldGet(this, _Client_lastPropagatedConnectionState, "f") != connectionState) {
613
612
  __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateConnectionState).call(this, connectionState);
@@ -616,13 +615,11 @@ export class Client extends Composer {
616
615
  _Client_storageInited.set(this, false);
617
616
  _Client_connectMutex.set(this, new Mutex());
618
617
  _Client_lastConnect.set(this, null);
619
- _Client_connectionInited.set(this, false);
620
618
  _Client_lastPropagatedAuthorizationState.set(this, null);
621
- _Client_connectionInsuranceLoopStarted.set(this, false);
622
- _Client_connectionInsuranceLoopAbortController.set(this, null);
623
- _Client_pingLoopAbortController.set(this, null);
624
- _Client_pingInterval.set(this, 56 * SECOND);
625
619
  _Client_lastUpdates.set(this, new Date());
620
+ _Client_updateGapRecoveryLoopAbortController.set(this, null);
621
+ _Client_clientDisconnectionLoopAbortController.set(this, null);
622
+ _Client_getMainClientMutex.set(this, new Mutex());
626
623
  _Client_handleInvokeError.set(this, skipInvoke());
627
624
  /**
628
625
  * Invokes a function waiting and returning its reply if the second parameter is not `true`. Requires the client
@@ -651,34 +648,11 @@ export class Client extends Composer {
651
648
  });
652
649
  _Client_authStringImported.set(this, false);
653
650
  _Client_lastGetMe.set(this, null);
654
- __classPrivateFieldSet(this, _Client_client, new ClientEncrypted(params), "f");
655
- __classPrivateFieldGet(this, _Client_client, "f").stateChangeHandler = __classPrivateFieldGet(this, _Client_stateChangeHandler, "f").bind(this);
656
- __classPrivateFieldGet(this, _Client_client, "f").handlers = {
657
- serverSaltReassigned: async (newServerSalt) => {
658
- await this.storage.setServerSalt(newServerSalt);
659
- },
660
- updates: (updates, call, callback) => {
661
- __classPrivateFieldGet(this, _Client_updateManager, "f").processUpdates(updates, true, call, callback);
662
- __classPrivateFieldSet(this, _Client_lastUpdates, new Date(), "f");
663
- },
664
- result: async (result, callback) => {
665
- await __classPrivateFieldGet(this, _Client_updateManager, "f").processResult(result);
666
- callback();
667
- },
668
- error: async (_err, source) => {
669
- switch (source) {
670
- case "deserialization":
671
- await __classPrivateFieldGet(this, _Client_updateManager, "f").recoverUpdateGap(source);
672
- break;
673
- case "decryption":
674
- await this.reconnect();
675
- await __classPrivateFieldGet(this, _Client_updateManager, "f").recoverUpdateGap(source);
676
- break;
677
- }
678
- },
679
- };
651
+ _Client_previouslyConnected.set(this, false);
652
+ _Client_lastConnectionState.set(this, false);
680
653
  __classPrivateFieldSet(this, _Client_apiId, params?.apiId ?? 0, "f");
681
654
  __classPrivateFieldSet(this, _Client_apiHash, params?.apiHash ?? "", "f");
655
+ __classPrivateFieldSet(this, _Client_transportProvider, params?.transportProvider, "f");
682
656
  __classPrivateFieldSet(this, _Client_storage_, params?.storage || new StorageMemory(), "f");
683
657
  __classPrivateFieldSet(this, _Client_persistCache, params?.persistCache ?? false, "f");
684
658
  if (!__classPrivateFieldGet(this, _Client_persistCache, "f")) {
@@ -706,19 +680,17 @@ export class Client extends Composer {
706
680
  __classPrivateFieldSet(this, _Client_guaranteeUpdateDelivery, params?.guaranteeUpdateDelivery ?? false, "f");
707
681
  const L = __classPrivateFieldSet(this, _Client_L, getLogger("Client").client(id++), "f");
708
682
  __classPrivateFieldSet(this, _Client_LsignIn, L.branch("signIn"), "f");
709
- __classPrivateFieldSet(this, _Client_LpingLoop, L.branch("pingLoop"), "f");
683
+ __classPrivateFieldSet(this, _Client_LupdateGapRecoveryLoop, L.branch("updateGapRecoveryLoop"), "f");
710
684
  __classPrivateFieldSet(this, _Client_LhandleMigrationError, L.branch("[handleMigrationError]"), "f");
711
- __classPrivateFieldSet(this, _Client_L$initConncetion, L.branch("#initConnection"), "f");
712
685
  __classPrivateFieldSet(this, _Client_Lmin, L.branch("min"), "f");
713
- __classPrivateFieldSet(this, _Client_cdn, params?.cdn ?? false, "f");
714
686
  const c = {
715
687
  id,
716
- invoke: async (function_, businessConnectionId) => {
717
- if (businessConnectionId) {
718
- return await this.invoke({ _: "invokeWithBusinessConnection", connection_id: businessConnectionId, query: function_ });
688
+ invoke: async (function_, params) => {
689
+ if (params?.businessConnectionId) {
690
+ return await this.invoke({ _: "invokeWithBusinessConnection", connection_id: params.businessConnectionId, query: function_ }, params);
719
691
  }
720
692
  else {
721
- return await this.invoke(function_);
693
+ return await this.invoke(function_, params);
722
694
  }
723
695
  },
724
696
  storage: this.storage,
@@ -734,9 +706,6 @@ export class Client extends Composer {
734
706
  getEntity: this[getEntity].bind(this),
735
707
  handleUpdate: __classPrivateFieldGet(this, _Client_instances, "m", _Client_queueHandleCtxUpdate).bind(this),
736
708
  parseMode: __classPrivateFieldGet(this, _Client_parseMode, "f"),
737
- getCdnConnection: __classPrivateFieldGet(this, _Client_instances, "m", _Client_getCdnConnection).bind(this),
738
- getCdnConnectionPool: __classPrivateFieldGet(this, _Client_instances, "m", _Client_getCdnConnectionPool).bind(this),
739
- cdn: __classPrivateFieldGet(this, _Client_cdn, "f"),
740
709
  outgoingMessages: __classPrivateFieldGet(this, _Client_outgoingMessages, "f"),
741
710
  dropPendingUpdates: params?.dropPendingUpdates,
742
711
  disconnected: () => this.disconnected,
@@ -766,12 +735,6 @@ export class Client extends Composer {
766
735
  __classPrivateFieldSet(this, _Client_pollManager, new PollManager({ ...c, messageManager }), "f");
767
736
  __classPrivateFieldSet(this, _Client_storyManager, new StoryManager({ ...c, fileManager, messageManager }), "f");
768
737
  __classPrivateFieldGet(this, _Client_updateManager, "f").setUpdateHandler(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleUpdate).bind(this));
769
- const transportProvider = __classPrivateFieldGet(this, _Client_client, "f").transportProvider;
770
- __classPrivateFieldGet(this, _Client_client, "f").transportProvider = (params) => {
771
- const transport = transportProvider(params);
772
- transport.connection.callback = __classPrivateFieldGet(this, _Client_networkStatisticsManager, "f").getTransportReadWriteCallback();
773
- return transport;
774
- };
775
738
  this.invoke.use(async ({ error }, next) => {
776
739
  if (error instanceof ConnectionError) {
777
740
  while (!this.connected) {
@@ -787,7 +750,7 @@ export class Client extends Composer {
787
750
  }
788
751
  return true;
789
752
  }
790
- else if (is("bad_msg_notification", error)) {
753
+ else if (Mtproto.is("bad_msg_notification", error)) {
791
754
  return true;
792
755
  }
793
756
  else {
@@ -809,10 +772,10 @@ export class Client extends Composer {
809
772
  }
810
773
  // direct ClientEncrypted property proxies
811
774
  get connected() {
812
- return __classPrivateFieldGet(this, _Client_client, "f").connected;
775
+ return __classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get)?.connected ?? false;
813
776
  }
814
777
  get disconnected() {
815
- return __classPrivateFieldGet(this, _Client_client, "f").disconnected;
778
+ return __classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get)?.disconnected ?? true;
816
779
  }
817
780
  /**
818
781
  * Sets the DC and resets the auth key stored in the session provider
@@ -827,7 +790,6 @@ export class Client extends Composer {
827
790
  await this.storage.setAuthKey(null);
828
791
  await this.storage.getAuthKey();
829
792
  }
830
- __classPrivateFieldGet(this, _Client_client, "f").setDc(dc);
831
793
  }
832
794
  /**
833
795
  * Loads the session if `setDc` was not called, initializes and connnects
@@ -840,39 +802,33 @@ export class Client extends Composer {
840
802
  if (this.connected) {
841
803
  return;
842
804
  }
843
- if (__classPrivateFieldGet(this, _Client_lastConnect, "f") != null && Date.now() - __classPrivateFieldGet(this, _Client_lastConnect, "f").getTime() <= 10 * SECOND) {
844
- await new Promise((r) => setTimeout(r, 3 * SECOND));
845
- }
846
805
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_initStorage).call(this);
847
806
  if (__classPrivateFieldGet(this, _Client_authString, "f") && !__classPrivateFieldGet(this, _Client_authStringImported, "f")) {
848
807
  await this.importAuthString(__classPrivateFieldGet(this, _Client_authString, "f"));
849
808
  }
850
809
  const [authKey, dc] = await Promise.all([this.storage.getAuthKey(), this.storage.getDc()]);
851
810
  if (authKey != null && dc != null) {
852
- await __classPrivateFieldGet(this, _Client_client, "f").setAuthKey(authKey);
853
- __classPrivateFieldGet(this, _Client_client, "f").setDc(dc);
854
- if (__classPrivateFieldGet(this, _Client_client, "f").serverSalt == 0n) {
855
- __classPrivateFieldGet(this, _Client_client, "f").serverSalt = await this.storage.getServerSalt() ?? 0n;
811
+ if (!__classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get) || __classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get).dc != dc) {
812
+ __classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get)?.disconnect();
813
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMainClient).call(this, await __classPrivateFieldGet(this, _Client_instances, "m", _Client_newClient).call(this, dc, true, false));
814
+ }
815
+ await __classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get).setAuthKey(authKey);
816
+ if (__classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get).serverSalt == 0n) {
817
+ __classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get).serverSalt = await this.storage.getServerSalt() ?? 0n;
856
818
  }
857
819
  }
858
820
  else {
859
- const plain = new ClientPlain({ initialDc: __classPrivateFieldGet(this, _Client_client, "f").initialDc, transportProvider: __classPrivateFieldGet(this, _Client_client, "f").transportProvider, cdn: __classPrivateFieldGet(this, _Client_client, "f").cdn, publicKeys: __classPrivateFieldGet(this, _Client_publicKeys, "f") });
860
- const dc = await this.storage.getDc();
861
- if (dc != null) {
862
- plain.setDc(dc);
863
- __classPrivateFieldGet(this, _Client_client, "f").setDc(dc);
821
+ const dc = await this.storage.getDc() ?? INITIAL_DC;
822
+ if (!__classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get) || __classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get).dc != dc) {
823
+ __classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get)?.disconnect();
824
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMainClient).call(this, await __classPrivateFieldGet(this, _Client_instances, "m", _Client_newClient).call(this, dc, true, false));
864
825
  }
865
- await plain.connect();
866
- const [authKey, serverSalt] = await plain.createAuthKey();
867
- drop(plain.disconnect());
868
- await __classPrivateFieldGet(this, _Client_client, "f").setAuthKey(authKey);
869
- __classPrivateFieldGet(this, _Client_client, "f").serverSalt = serverSalt;
870
826
  }
871
- await __classPrivateFieldGet(this, _Client_client, "f").connect();
827
+ await __classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get).connect();
872
828
  __classPrivateFieldSet(this, _Client_lastConnect, new Date(), "f");
873
- await Promise.all([this.storage.setAuthKey(__classPrivateFieldGet(this, _Client_client, "f").authKey), this.storage.setDc(__classPrivateFieldGet(this, _Client_client, "f").dc), this.storage.setServerSalt(__classPrivateFieldGet(this, _Client_client, "f").serverSalt)]);
874
- __classPrivateFieldGet(this, _Client_instances, "m", _Client_startConnectionInsuranceLoop).call(this);
875
- __classPrivateFieldGet(this, _Client_instances, "m", _Client_startPingLoop).call(this);
829
+ await Promise.all([this.storage.setAuthKey(__classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get).authKey), this.storage.setDc(__classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get).dc), this.storage.setServerSalt(__classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get).serverSalt)]);
830
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_startUpdateGapRecoveryLoop).call(this);
831
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_startClientDisconnectionLoop).call(this);
876
832
  }
877
833
  finally {
878
834
  unlock();
@@ -882,120 +838,54 @@ export class Client extends Composer {
882
838
  if (dc) {
883
839
  await this.setDc(dc);
884
840
  }
885
- await __classPrivateFieldGet(this, _Client_client, "f").reconnect();
841
+ this.disconnect();
842
+ await this.connect();
886
843
  }
887
- async [(_Client_client = new WeakMap(), _Client_guaranteeUpdateDelivery = new WeakMap(), _Client_accountManager = new WeakMap(), _Client_botInfoManager = new WeakMap(), _Client_businessConnectionManager = new WeakMap(), _Client_fileManager = new WeakMap(), _Client_networkStatisticsManager = new WeakMap(), _Client_paymentManager = new WeakMap(), _Client_reactionManager = new WeakMap(), _Client_translationsManager = new WeakMap(), _Client_updateManager = new WeakMap(), _Client_messageManager = new WeakMap(), _Client_videoChatManager = new WeakMap(), _Client_callbackQueryManager = new WeakMap(), _Client_chatListManager = new WeakMap(), _Client_chatManager = new WeakMap(), _Client_forumManager = new WeakMap(), _Client_giftManager = new WeakMap(), _Client_inlineQueryManager = new WeakMap(), _Client_pollManager = new WeakMap(), _Client_storyManager = new WeakMap(), _Client_managers = new WeakMap(), _Client_storage_ = new WeakMap(), _Client_messageStorage_ = new WeakMap(), _Client_parseMode = new WeakMap(), _Client_apiId = new WeakMap(), _Client_apiHash = new WeakMap(), _Client_publicKeys = new WeakMap(), _Client_outgoingMessages = new WeakMap(), _Client_persistCache = new WeakMap(), _Client_disableUpdates = new WeakMap(), _Client_authString = new WeakMap(), _Client_cdn = new WeakMap(), _Client_L = new WeakMap(), _Client_LsignIn = new WeakMap(), _Client_LpingLoop = new WeakMap(), _Client_LhandleMigrationError = new WeakMap(), _Client_L$initConncetion = new WeakMap(), _Client_Lmin = new WeakMap(), _Client_reconnecting = new WeakMap(), _Client_constructContext = new WeakMap(), _Client_lastPropagatedConnectionState = new WeakMap(), _Client_stateChangeHandler = new WeakMap(), _Client_storageInited = new WeakMap(), _Client_connectMutex = new WeakMap(), _Client_lastConnect = new WeakMap(), _Client_connectionInited = new WeakMap(), _Client_lastPropagatedAuthorizationState = new WeakMap(), _Client_connectionInsuranceLoopStarted = new WeakMap(), _Client_connectionInsuranceLoopAbortController = new WeakMap(), _Client_pingLoopAbortController = new WeakMap(), _Client_pingInterval = new WeakMap(), _Client_lastUpdates = new WeakMap(), _Client_handleInvokeError = new WeakMap(), _Client_authStringImported = new WeakMap(), _Client_lastGetMe = new WeakMap(), _Client_instances = new WeakSet(), _Client_reconnect = async function _Client_reconnect() {
888
- if (this.connected) {
889
- return;
890
- }
891
- if (this.disconnected) {
892
- __classPrivateFieldGet(this, _Client_L, "f").debug("not reconnecting");
893
- return;
894
- }
895
- if (__classPrivateFieldGet(this, _Client_reconnecting, "f")) {
896
- return;
844
+ async [(_Client_clients = new WeakMap(), _Client_downloadPools = new WeakMap(), _Client_uploadPools = new WeakMap(), _Client_guaranteeUpdateDelivery = new WeakMap(), _Client_accountManager = new WeakMap(), _Client_botInfoManager = new WeakMap(), _Client_businessConnectionManager = new WeakMap(), _Client_fileManager = new WeakMap(), _Client_networkStatisticsManager = new WeakMap(), _Client_paymentManager = new WeakMap(), _Client_reactionManager = new WeakMap(), _Client_translationsManager = new WeakMap(), _Client_updateManager = new WeakMap(), _Client_messageManager = new WeakMap(), _Client_videoChatManager = new WeakMap(), _Client_callbackQueryManager = new WeakMap(), _Client_chatListManager = new WeakMap(), _Client_chatManager = new WeakMap(), _Client_forumManager = new WeakMap(), _Client_giftManager = new WeakMap(), _Client_inlineQueryManager = new WeakMap(), _Client_pollManager = new WeakMap(), _Client_storyManager = new WeakMap(), _Client_managers = new WeakMap(), _Client_storage_ = new WeakMap(), _Client_messageStorage_ = new WeakMap(), _Client_parseMode = new WeakMap(), _Client_apiId = new WeakMap(), _Client_apiHash = new WeakMap(), _Client_transportProvider = new WeakMap(), _Client_publicKeys = new WeakMap(), _Client_outgoingMessages = new WeakMap(), _Client_persistCache = new WeakMap(), _Client_disableUpdates = new WeakMap(), _Client_authString = new WeakMap(), _Client_L = new WeakMap(), _Client_LsignIn = new WeakMap(), _Client_LupdateGapRecoveryLoop = new WeakMap(), _Client_LhandleMigrationError = new WeakMap(), _Client_Lmin = new WeakMap(), _Client_constructContext = new WeakMap(), _Client_lastPropagatedConnectionState = new WeakMap(), _Client_stateChangeHandler = new WeakMap(), _Client_storageInited = new WeakMap(), _Client_connectMutex = new WeakMap(), _Client_lastConnect = new WeakMap(), _Client_lastPropagatedAuthorizationState = new WeakMap(), _Client_lastUpdates = new WeakMap(), _Client_updateGapRecoveryLoopAbortController = new WeakMap(), _Client_clientDisconnectionLoopAbortController = new WeakMap(), _Client_getMainClientMutex = new WeakMap(), _Client_handleInvokeError = new WeakMap(), _Client_authStringImported = new WeakMap(), _Client_lastGetMe = new WeakMap(), _Client_previouslyConnected = new WeakMap(), _Client_lastConnectionState = new WeakMap(), _Client_instances = new WeakSet(), _Client_setMainClient = function _Client_setMainClient(client) {
845
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_disconnectAllClients).call(this);
846
+ __classPrivateFieldSet(this, _Client_clients, [client], "f");
847
+ client.handlers.onUpdate = (updates) => {
848
+ __classPrivateFieldGet(this, _Client_updateManager, "f").processUpdates(updates, true, null);
849
+ __classPrivateFieldSet(this, _Client_lastUpdates, new Date(), "f");
850
+ };
851
+ client.handlers.onDeserializationError = async () => {
852
+ await __classPrivateFieldGet(this, _Client_updateManager, "f").recoverUpdateGap("deserialization error");
853
+ };
854
+ client.onConnectionStateChange = __classPrivateFieldGet(this, _Client_instances, "m", _Client_onConnectionStateChange).bind(this);
855
+ }, _Client_newClient = async function _Client_newClient(dc, main, cdn) {
856
+ const apiId = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getApiId).call(this);
857
+ const client = new ClientEncrypted(dc, apiId, {
858
+ appVersion: this.appVersion,
859
+ deviceModel: this.deviceModel,
860
+ langCode: this.language,
861
+ langPack: this.platform,
862
+ systemLangCode: this.systemLangCode,
863
+ systemVersion: this.systemVersion,
864
+ transportProvider: __classPrivateFieldGet(this, _Client_transportProvider, "f"),
865
+ cdn,
866
+ disableUpdates: !main || cdn,
867
+ publicKeys: __classPrivateFieldGet(this, _Client_publicKeys, "f"),
868
+ });
869
+ client.connectionCallback = __classPrivateFieldGet(this, _Client_networkStatisticsManager, "f").getTransportReadWriteCallback(cdn);
870
+ return client;
871
+ }, _Client_disconnectAllClients = function _Client_disconnectAllClients() {
872
+ for (const client of __classPrivateFieldGet(this, _Client_clients, "f")) {
873
+ client.disconnect();
897
874
  }
898
- __classPrivateFieldSet(this, _Client_reconnecting, true, "f");
899
- try {
900
- let delay = 5;
901
- while (!this.connected) {
902
- __classPrivateFieldGet(this, _Client_L, "f").debug("reconnecting");
903
- __classPrivateFieldGet(this, _Client_pingLoopAbortController, "f")?.abort();
904
- try {
905
- await this.connect();
906
- __classPrivateFieldGet(this, _Client_L, "f").debug("reconnected");
907
- drop(__classPrivateFieldGet(this, _Client_updateManager, "f").recoverUpdateGap("reconnect"));
908
- break;
909
- }
910
- catch (err) {
911
- if (delay < 15) {
912
- delay += 5;
913
- }
914
- __classPrivateFieldGet(this, _Client_L, "f").debug(`failed to reconnect, retrying in ${delay}:`, err);
915
- }
916
- await new Promise((r) => setTimeout(r, delay * SECOND));
917
- }
875
+ for (const pool of Object.values(__classPrivateFieldGet(this, _Client_downloadPools, "f"))) {
876
+ pool.disconnect();
918
877
  }
919
- finally {
920
- __classPrivateFieldSet(this, _Client_reconnecting, false, "f");
878
+ for (const pool of Object.values(__classPrivateFieldGet(this, _Client_uploadPools, "f"))) {
879
+ pool.disconnect();
921
880
  }
881
+ }, _Client_client_get = function _Client_client_get() {
882
+ return __classPrivateFieldGet(this, _Client_clients, "f")[0];
922
883
  }, _Client_getApiId = async function _Client_getApiId() {
923
884
  const apiId = __classPrivateFieldGet(this, _Client_apiId, "f") || await this.storage.getApiId();
924
885
  if (!apiId) {
925
886
  throw new InputError("apiId not set");
926
887
  }
927
888
  return apiId;
928
- }, _Client_getCdnConnectionPool = function _Client_getCdnConnectionPool(connectionCount, dcId) {
929
- const connections = new Array();
930
- for (let i = 0; i < connectionCount; ++i) {
931
- connections.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_getCdnConnection).call(this, dcId));
932
- }
933
- let prev = 0;
934
- return {
935
- size: connectionCount,
936
- invoke: () => {
937
- if (prev + 1 > connections.length)
938
- prev = 0;
939
- const connection = connections[prev++];
940
- return connection.invoke;
941
- },
942
- connect: async () => {
943
- for await (const connection of connections) {
944
- await connection.connect();
945
- }
946
- },
947
- disconnect: async () => {
948
- for await (const connection of connections) {
949
- await connection.disconnect();
950
- }
951
- },
952
- };
953
- }, _Client_getCdnConnection = function _Client_getCdnConnection(dcId) {
954
- const provider = this.storage.provider;
955
- const client = new _a({
956
- storage: (!dcId || dcId == __classPrivateFieldGet(this, _Client_client, "f").dcId) ? provider : provider.branch(`download_client_${dcId}`),
957
- apiId: __classPrivateFieldGet(this, _Client_apiId, "f"),
958
- apiHash: __classPrivateFieldGet(this, _Client_apiHash, "f"),
959
- transportProvider: __classPrivateFieldGet(this, _Client_client, "f").transportProvider,
960
- appVersion: this.appVersion,
961
- deviceModel: this.deviceModel,
962
- language: this.language,
963
- platform: this.platform,
964
- systemLangCode: this.systemLangCode,
965
- systemVersion: this.systemVersion,
966
- cdn: true,
967
- initialDc: getDc(dcId || __classPrivateFieldGet(this, _Client_client, "f").dcId),
968
- });
969
- __classPrivateFieldGet(client, _Client_client, "f").serverSalt = __classPrivateFieldGet(this, _Client_client, "f").serverSalt;
970
- client.invoke.use(async (ctx, next) => {
971
- if (ctx.error instanceof AuthKeyUnregistered && dcId) {
972
- try {
973
- const exportedAuth = await this.invoke({ _: "auth.exportAuthorization", dc_id: dcId });
974
- await client.invoke({ ...exportedAuth, _: "auth.importAuthorization" });
975
- return true;
976
- }
977
- catch (err) {
978
- throw err;
979
- }
980
- }
981
- else {
982
- return await next();
983
- }
984
- });
985
- return {
986
- invoke: client.invoke.bind(client),
987
- connect: async () => {
988
- await client.connect();
989
- if (dcId && dcId != __classPrivateFieldGet(this, _Client_client, "f").dcId) {
990
- let dc = String(dcId);
991
- if (__classPrivateFieldGet(this, _Client_client, "f").dcId < 0) {
992
- dc += "-test";
993
- }
994
- await client.setDc(dc);
995
- }
996
- },
997
- disconnect: client.disconnect.bind(client),
998
- };
999
889
  }, _Client_propagateConnectionState = function _Client_propagateConnectionState(connectionState) {
1000
890
  __classPrivateFieldGet(this, _Client_instances, "m", _Client_queueHandleCtxUpdate).call(this, { connectionState });
1001
891
  __classPrivateFieldSet(this, _Client_lastPropagatedConnectionState, connectionState, "f");
@@ -1009,18 +899,15 @@ export class Client extends Composer {
1009
899
  }
1010
900
  }, handleMigrationError)](err) {
1011
901
  let newDc = String(err.dc);
1012
- if (Math.abs(__classPrivateFieldGet(this, _Client_client, "f").dcId) >= 10_000) {
902
+ if (Math.abs(getDcId(__classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get).dc, __classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get).cdn)) >= 10_000) {
1013
903
  newDc += "-test";
1014
904
  }
1015
905
  await this.reconnect(newDc);
1016
906
  __classPrivateFieldGet(this, _Client_LhandleMigrationError, "f").debug(`migrated to DC${newDc}`);
1017
907
  }
1018
- async disconnect() {
1019
- __classPrivateFieldSet(this, _Client_connectionInited, false, "f");
1020
- await __classPrivateFieldGet(this, _Client_client, "f").disconnect();
908
+ disconnect() {
909
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_disconnectAllClients).call(this);
1021
910
  __classPrivateFieldGet(this, _Client_updateManager, "f").closeAllChats();
1022
- __classPrivateFieldGet(this, _Client_pingLoopAbortController, "f")?.abort();
1023
- __classPrivateFieldGet(this, _Client_connectionInsuranceLoopAbortController, "f")?.abort();
1024
911
  }
1025
912
  /**
1026
913
  * Signs in using the provided parameters if not already signed in.
@@ -1056,12 +943,12 @@ export class Client extends Composer {
1056
943
  params = { phone: () => mustPrompt("Phone number:"), code: () => mustPrompt("Verification code:"), password: () => mustPrompt("Password:") };
1057
944
  }
1058
945
  }
1059
- __classPrivateFieldGet(this, _Client_LsignIn, "f").debug("authorizing with", typeof params === "string" ? "bot token" : is("auth.exportedAuthorization", params) ? "exported authorization" : "AuthorizeUserParams");
946
+ __classPrivateFieldGet(this, _Client_LsignIn, "f").debug("authorizing with", typeof params === "string" ? "bot token" : Api.is("auth.exportedAuthorization", params) ? "exported authorization" : "AuthorizeUserParams");
1060
947
  if (params && "botToken" in params) {
1061
948
  while (true) {
1062
949
  try {
1063
950
  const auth = await this.invoke({ _: "auth.importBotAuthorization", api_id: apiId, api_hash: __classPrivateFieldGet(this, _Client_apiHash, "f"), bot_auth_token: params.botToken, flags: 0 });
1064
- await this.storage.setAccountId(Number(as("auth.authorization", auth).user.id));
951
+ await this.storage.setAccountId(Number(Api.as("auth.authorization", auth).user.id));
1065
952
  await this.storage.setAccountType("bot");
1066
953
  break;
1067
954
  }
@@ -1093,7 +980,7 @@ export class Client extends Composer {
1093
980
  api_id: __classPrivateFieldGet(this, _Client_apiId, "f"),
1094
981
  api_hash: __classPrivateFieldGet(this, _Client_apiHash, "f"),
1095
982
  settings: { _: "codeSettings" },
1096
- }).then((v) => as("auth.sentCode", v));
983
+ }).then((v) => Api.as("auth.sentCode", v));
1097
984
  try {
1098
985
  sentCode = await sendCode();
1099
986
  }
@@ -1128,7 +1015,7 @@ export class Client extends Composer {
1128
1015
  phone_code: code,
1129
1016
  phone_code_hash: sentCode.phone_code_hash,
1130
1017
  });
1131
- await this.storage.setAccountId(Number(as("auth.authorization", auth).user.id));
1018
+ await this.storage.setAccountId(Number(Api.as("auth.authorization", auth).user.id));
1132
1019
  await this.storage.setAccountType("user");
1133
1020
  __classPrivateFieldGet(this, _Client_LsignIn, "f").debug("signed in as user");
1134
1021
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateAuthorizationState).call(this, true);
@@ -1150,14 +1037,14 @@ export class Client extends Composer {
1150
1037
  }
1151
1038
  password: while (true) {
1152
1039
  const ap = await this.invoke({ _: "account.getPassword" });
1153
- if (!(is("passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow", ap.current_algo))) {
1040
+ if (!(Api.is("passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow", ap.current_algo))) {
1154
1041
  throw new Error(`Handling ${ap.current_algo?._} not implemented`);
1155
1042
  }
1156
1043
  try {
1157
1044
  const password = typeof params.password === "string" ? params.password : await params.password(ap.hint ?? null);
1158
1045
  const input = await checkPassword(password, ap);
1159
1046
  const auth = await this.invoke({ _: "auth.checkPassword", password: input });
1160
- await this.storage.setAccountId(Number(as("auth.authorization", auth).user.id));
1047
+ await this.storage.setAccountId(Number(Api.as("auth.authorization", auth).user.id));
1161
1048
  await this.storage.setAccountType("user");
1162
1049
  __classPrivateFieldGet(this, _Client_LsignIn, "f").debug("signed in as user");
1163
1050
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateAuthorizationState).call(this, true);
@@ -1205,12 +1092,6 @@ export class Client extends Composer {
1205
1092
  await this.connect();
1206
1093
  await this.signIn(params);
1207
1094
  }
1208
- /**
1209
- * Alias for `invoke` with its second parameter being `true`.
1210
- */
1211
- send(function_) {
1212
- return this.invoke(function_, true);
1213
- }
1214
1095
  exportAuthString() {
1215
1096
  return this.storage.exportAuthString(__classPrivateFieldGet(this, _Client_apiId, "f"));
1216
1097
  }
@@ -1232,7 +1113,7 @@ export class Client extends Composer {
1232
1113
  return { _: "inputPeerSelf" };
1233
1114
  }
1234
1115
  const inputPeer = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getInputPeerInner).call(this, id);
1235
- if (((is("inputPeerUser", inputPeer) || is("inputPeerChannel", inputPeer)) && inputPeer.access_hash == 0n) && await this.storage.getAccountType() == "bot") {
1116
+ if (((Api.is("inputPeerUser", inputPeer) || Api.is("inputPeerChannel", inputPeer)) && inputPeer.access_hash == 0n) && await this.storage.getAccountType() == "bot") {
1236
1117
  if ("channel_id" in inputPeer) {
1237
1118
  inputPeer.access_hash = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChannelAccessHash).call(this, inputPeer.channel_id);
1238
1119
  }
@@ -1240,7 +1121,7 @@ export class Client extends Composer {
1240
1121
  inputPeer.access_hash = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getUserAccessHash).call(this, inputPeer.user_id);
1241
1122
  }
1242
1123
  }
1243
- if ((is("inputPeerUser", inputPeer) || is("inputPeerChannel", inputPeer)) && inputPeer.access_hash == 0n && await this.storage.getAccountType() == "user") {
1124
+ if ((Api.is("inputPeerUser", inputPeer) || Api.is("inputPeerChannel", inputPeer)) && inputPeer.access_hash == 0n && await this.storage.getAccountType() == "user") {
1244
1125
  throw new AccessError(`Cannot access the chat ${id} because there is no access hash for it.`);
1245
1126
  }
1246
1127
  return inputPeer;
@@ -1280,110 +1161,202 @@ export class Client extends Composer {
1280
1161
  throw new Error("Unauthorized");
1281
1162
  }
1282
1163
  return id;
1283
- }, _Client_startConnectionInsuranceLoop = function _Client_startConnectionInsuranceLoop() {
1284
- drop(__classPrivateFieldGet(this, _Client_instances, "m", _Client_connectionInsuranceLoop).call(this));
1285
- }, _Client_connectionInsuranceLoop = async function _Client_connectionInsuranceLoop() {
1286
- if (__classPrivateFieldGet(this, _Client_connectionInsuranceLoopStarted, "f")) {
1287
- return;
1288
- }
1289
- __classPrivateFieldSet(this, _Client_connectionInsuranceLoopAbortController, new AbortController(), "f");
1290
- __classPrivateFieldSet(this, _Client_connectionInsuranceLoopStarted, true, "f");
1291
- while (!this.disconnected) {
1164
+ }, _Client_startUpdateGapRecoveryLoop = function _Client_startUpdateGapRecoveryLoop() {
1165
+ drop(__classPrivateFieldGet(this, _Client_instances, "m", _Client_updateGapRecoveryLoop).call(this));
1166
+ }, _Client_updateGapRecoveryLoop = async function _Client_updateGapRecoveryLoop() {
1167
+ __classPrivateFieldSet(this, _Client_updateGapRecoveryLoopAbortController, new AbortController(), "f");
1168
+ while (this.connected) {
1292
1169
  try {
1293
1170
  await new Promise((resolve, reject) => {
1294
- const timeout = setTimeout(resolve, 10 * SECOND);
1295
- __classPrivateFieldGet(this, _Client_connectionInsuranceLoopAbortController, "f").signal.onabort = () => {
1296
- reject(__classPrivateFieldGet(this, _Client_connectionInsuranceLoopAbortController, "f")?.signal.reason);
1171
+ const timeout = setTimeout(resolve, 60 * SECOND);
1172
+ __classPrivateFieldGet(this, _Client_updateGapRecoveryLoopAbortController, "f").signal.onabort = () => {
1173
+ reject(__classPrivateFieldGet(this, _Client_updateGapRecoveryLoopAbortController, "f")?.signal.reason);
1297
1174
  clearTimeout(timeout);
1298
1175
  };
1299
1176
  });
1177
+ if (!this.connected) {
1178
+ continue;
1179
+ }
1180
+ __classPrivateFieldGet(this, _Client_updateGapRecoveryLoopAbortController, "f").signal.throwIfAborted();
1181
+ if (Date.now() - __classPrivateFieldGet(this, _Client_lastUpdates, "f").getTime() >= 15 * MINUTE) {
1182
+ drop(__classPrivateFieldGet(this, _Client_updateManager, "f").recoverUpdateGap("lastUpdates").then(() => {
1183
+ __classPrivateFieldSet(this, _Client_lastUpdates, new Date(), "f");
1184
+ }));
1185
+ }
1300
1186
  }
1301
- catch {
1302
- break;
1303
- }
1304
- if (!this.connected) {
1305
- drop(__classPrivateFieldGet(this, _Client_instances, "m", _Client_reconnect).call(this));
1187
+ catch (err) {
1188
+ if (err instanceof DOMException && err.name == "AbortError") {
1189
+ __classPrivateFieldSet(this, _Client_updateGapRecoveryLoopAbortController, new AbortController(), "f");
1190
+ }
1191
+ if (!this.connected) {
1192
+ continue;
1193
+ }
1194
+ __classPrivateFieldGet(this, _Client_LupdateGapRecoveryLoop, "f").error(err);
1306
1195
  }
1307
1196
  }
1308
- __classPrivateFieldSet(this, _Client_connectionInsuranceLoopStarted, false, "f");
1309
- }, _Client_startPingLoop = function _Client_startPingLoop() {
1310
- drop(__classPrivateFieldGet(this, _Client_instances, "m", _Client_pingLoop).call(this));
1311
- }, _Client_pingLoop = async function _Client_pingLoop() {
1312
- if (__classPrivateFieldGet(this, _Client_cdn, "f")) {
1313
- return;
1314
- }
1315
- __classPrivateFieldSet(this, _Client_pingLoopAbortController, new AbortController(), "f");
1316
- let timeElapsed = 0;
1197
+ }, _Client_startClientDisconnectionLoop = function _Client_startClientDisconnectionLoop() {
1198
+ drop(__classPrivateFieldGet(this, _Client_instances, "m", _Client_clientDisconnectionLoop).call(this));
1199
+ }, _Client_clientDisconnectionLoop = async function _Client_clientDisconnectionLoop() {
1200
+ __classPrivateFieldSet(this, _Client_clientDisconnectionLoopAbortController, new AbortController(), "f");
1317
1201
  while (this.connected) {
1318
- const then = Date.now();
1319
1202
  try {
1320
1203
  await new Promise((resolve, reject) => {
1321
- const timeout = setTimeout(resolve, __classPrivateFieldGet(this, _Client_pingInterval, "f") - timeElapsed);
1322
- __classPrivateFieldGet(this, _Client_pingLoopAbortController, "f").signal.onabort = () => {
1323
- reject(__classPrivateFieldGet(this, _Client_pingLoopAbortController, "f")?.signal.reason);
1204
+ const timeout = setTimeout(resolve, 60 * SECOND);
1205
+ __classPrivateFieldGet(this, _Client_clientDisconnectionLoopAbortController, "f").signal.onabort = () => {
1206
+ reject(__classPrivateFieldGet(this, _Client_clientDisconnectionLoopAbortController, "f")?.signal.reason);
1324
1207
  clearTimeout(timeout);
1325
1208
  };
1326
1209
  });
1327
1210
  if (!this.connected) {
1328
1211
  continue;
1329
1212
  }
1330
- __classPrivateFieldGet(this, _Client_pingLoopAbortController, "f").signal.throwIfAborted();
1331
- await this.invoke({ _: "ping_delay_disconnect", ping_id: getRandomId(), disconnect_delay: __classPrivateFieldGet(this, _Client_pingInterval, "f") / SECOND + 15 });
1332
- __classPrivateFieldGet(this, _Client_pingLoopAbortController, "f").signal.throwIfAborted();
1333
- if (Date.now() - __classPrivateFieldGet(this, _Client_lastUpdates, "f").getTime() >= 15 * MINUTE) {
1334
- drop(__classPrivateFieldGet(this, _Client_updateManager, "f").recoverUpdateGap("lastUpdates").then(() => {
1335
- __classPrivateFieldSet(this, _Client_lastUpdates, new Date(), "f");
1336
- }));
1337
- }
1213
+ __classPrivateFieldGet(this, _Client_clientDisconnectionLoopAbortController, "f").signal.throwIfAborted();
1214
+ const now = Date.now();
1215
+ const disconnectAfter = 5 * MINUTE;
1216
+ __classPrivateFieldGet(this, _Client_clients, "f").map((client, i) => {
1217
+ if (i > 0 && !client.disconnected && client.lastRequest && now - client.lastRequest.getTime() >= disconnectAfter) {
1218
+ client?.disconnect();
1219
+ }
1220
+ });
1338
1221
  }
1339
1222
  catch (err) {
1340
1223
  if (err instanceof DOMException && err.name == "AbortError") {
1341
- __classPrivateFieldSet(this, _Client_pingLoopAbortController, new AbortController(), "f");
1224
+ __classPrivateFieldSet(this, _Client_clientDisconnectionLoopAbortController, new AbortController(), "f");
1342
1225
  }
1343
1226
  if (!this.connected) {
1344
1227
  continue;
1345
1228
  }
1346
- __classPrivateFieldGet(this, _Client_LpingLoop, "f").error(err);
1347
1229
  }
1348
- finally {
1349
- timeElapsed = Date.now() - then;
1230
+ }
1231
+ }, _Client_getClient = async function _Client_getClient(params) {
1232
+ let client;
1233
+ switch (params.type) {
1234
+ case undefined:
1235
+ client = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getMainClient).call(this, params.dc);
1236
+ break;
1237
+ case "download":
1238
+ client = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getDownloadClient).call(this, params.dc);
1239
+ break;
1240
+ case "upload":
1241
+ client = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getUploadClient).call(this);
1242
+ break;
1243
+ }
1244
+ if (client !== __classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get) && !this.disconnected && client.disconnected) {
1245
+ await client.connect();
1246
+ }
1247
+ return client;
1248
+ }, _Client_getMainClient = async function _Client_getMainClient(dc) {
1249
+ if (dc === undefined || dc == __classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get)?.dc) {
1250
+ return __classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get);
1251
+ }
1252
+ let client = __classPrivateFieldGet(this, _Client_clients, "f").find((v) => v.dc == dc);
1253
+ if (client) {
1254
+ return client;
1255
+ }
1256
+ const release = await __classPrivateFieldGet(this, _Client_getMainClientMutex, "f").lock();
1257
+ client = __classPrivateFieldGet(this, _Client_clients, "f").find((v) => v.dc == dc);
1258
+ if (client) {
1259
+ return client;
1260
+ }
1261
+ try {
1262
+ client = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_newClient).call(this, dc, false, false);
1263
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setupClient).call(this, client);
1264
+ __classPrivateFieldGet(this, _Client_clients, "f").push(client);
1265
+ return client;
1266
+ }
1267
+ finally {
1268
+ release();
1269
+ }
1270
+ }, _Client_getDownloadClient = async function _Client_getDownloadClient(dc) {
1271
+ dc ??= __classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get).dc;
1272
+ const pool = __classPrivateFieldGet(this, _Client_downloadPools, "f")[dc] ??= new ClientEncryptedPool(DOWNLOAD_REQUEST_PER_CONNECTION);
1273
+ if (!pool.size) {
1274
+ for (let i = 0; i < DOWNLOAD_POOL_SIZE; ++i) {
1275
+ pool.add(await __classPrivateFieldGet(this, _Client_instances, "m", _Client_newClient).call(this, dc, false, true));
1350
1276
  }
1351
1277
  }
1352
- }, _Client_invoke = async function _Client_invoke(function_, noWait) {
1278
+ const client = pool.nextClient();
1279
+ if (client.authKey.length) {
1280
+ return client;
1281
+ }
1282
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setupClient).call(this, client);
1283
+ return client;
1284
+ }, _Client_getUploadClient = async function _Client_getUploadClient() {
1285
+ const dc = __classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get).dc;
1286
+ const pool = __classPrivateFieldGet(this, _Client_uploadPools, "f")[dc] ??= new ClientEncryptedPool(UPLOAD_REQUEST_PER_CONNECTION);
1287
+ if (!pool.size) {
1288
+ for (let i = 0; i < UPLOAD_POOL_SIZE; ++i) {
1289
+ pool.add(await __classPrivateFieldGet(this, _Client_instances, "m", _Client_newClient).call(this, dc, false, true));
1290
+ }
1291
+ }
1292
+ const client = pool.nextClient();
1293
+ if (client.authKey.length) {
1294
+ return client;
1295
+ }
1296
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setupClient).call(this, client);
1297
+ return client;
1298
+ }, _Client_setupClient = async function _Client_setupClient(client) {
1299
+ const storage = client.dc == __classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get).dc ? this.storage : new StorageOperations(this.storage.provider.branch(client.dc + (client.cdn ? "_cdn" : "")));
1300
+ const [authKey, serverSalt] = await Promise.all([storage.getAuthKey(), storage.getServerSalt()]);
1301
+ if (authKey) {
1302
+ await client.setAuthKey(authKey);
1303
+ if (serverSalt) {
1304
+ client.serverSalt = serverSalt;
1305
+ }
1306
+ }
1307
+ await client.connect();
1308
+ if (!authKey) {
1309
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_importAuthorization).call(this, client);
1310
+ }
1311
+ await Promise.all([storage.setAuthKey(client.authKey), storage.setServerSalt(client.serverSalt)]);
1312
+ client.handlers.onNewServerSalt = async (serverSalt) => {
1313
+ await storage.setServerSalt(serverSalt);
1314
+ };
1315
+ }, _Client_importAuthorization = async function _Client_importAuthorization(client) {
1316
+ if (__classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get).dc == client.dc && __classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get).cdn == client.cdn) {
1317
+ const [authKey, serverSalt] = await Promise.all([this.storage.getAuthKey(), this.storage.getServerSalt()]);
1318
+ if (authKey) {
1319
+ await client.setAuthKey(authKey);
1320
+ if (serverSalt) {
1321
+ client.serverSalt = serverSalt;
1322
+ }
1323
+ }
1324
+ return;
1325
+ }
1326
+ const exportedAuthorization = await __classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get).invoke({ _: "auth.exportAuthorization", dc_id: getDcId(client.dc, client.cdn) });
1327
+ await client.invoke({ ...exportedAuthorization, _: "auth.importAuthorization" });
1328
+ }, _Client_invoke = async function _Client_invoke(function_, params) {
1329
+ if (!__classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get)) {
1330
+ throw new ConnectionError("Not connected.");
1331
+ }
1353
1332
  let n = 1;
1333
+ let client;
1354
1334
  while (true) {
1335
+ client = params ? await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getClient).call(this, params) : __classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get);
1336
+ const main = client === __classPrivateFieldGet(this, _Client_instances, "a", _Client_client_get);
1355
1337
  try {
1356
- if (__classPrivateFieldGet(this, _Client_disableUpdates, "f") && !isMtprotoFunction(function_) && !isCdnFunction(function_)) {
1357
- function_ = { _: "invokeWithoutUpdates", query: function_ };
1358
- }
1359
- if (!__classPrivateFieldGet(this, _Client_connectionInited, "f") && !isMtprotoFunction(function_)) {
1360
- __classPrivateFieldSet(this, _Client_connectionInited, true, "f");
1361
- __classPrivateFieldGet(this, _Client_L, "f").debug("init");
1362
- const result = await __classPrivateFieldGet(this, _Client_client, "f").invoke({
1363
- _: "initConnection",
1364
- api_id: await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getApiId).call(this),
1365
- app_version: this.appVersion,
1366
- device_model: this.deviceModel,
1367
- lang_code: this.language,
1368
- lang_pack: this.platform,
1369
- query: {
1370
- _: "invokeWithLayer",
1371
- layer: LAYER,
1372
- query: function_,
1373
- },
1374
- system_lang_code: this.systemLangCode,
1375
- system_version: this.systemVersion,
1376
- }, noWait);
1377
- __classPrivateFieldGet(this, _Client_L$initConncetion, "f").debug("connection inited");
1378
- return result;
1379
- }
1380
- else {
1381
- return await __classPrivateFieldGet(this, _Client_client, "f").invoke(function_, noWait);
1338
+ const result = await client.invoke(function_);
1339
+ if (main) {
1340
+ try {
1341
+ await __classPrivateFieldGet(this, _Client_updateManager, "f").processResult(result);
1342
+ }
1343
+ catch (err) {
1344
+ __classPrivateFieldGet(this, _Client_L, "f").error("failed to process result:", err);
1345
+ }
1346
+ if (Api.isOfEnum("Update", result) || Api.isOfEnum("Updates", result)) {
1347
+ return new Promise((resolve) => {
1348
+ __classPrivateFieldGet(this, _Client_updateManager, "f").processUpdates(result, true, null, () => resolve(result));
1349
+ });
1350
+ }
1382
1351
  }
1352
+ return result;
1383
1353
  }
1384
1354
  catch (err) {
1385
- if (err instanceof ConnectionNotInited) {
1386
- __classPrivateFieldSet(this, _Client_connectionInited, false, "f");
1355
+ if (err instanceof AuthKeyUnregistered && !main) {
1356
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_importAuthorization).call(this, client);
1357
+ continue;
1358
+ }
1359
+ else if (err instanceof ConnectionError && !main && !this.disconnected) {
1387
1360
  continue;
1388
1361
  }
1389
1362
  else if (await __classPrivateFieldGet(this, _Client_handleInvokeError, "f").call(this, Object.freeze({ client: this, error: err, function: function_, n: n++ }), () => Promise.resolve(false))) {
@@ -1396,27 +1369,27 @@ export class Client extends Composer {
1396
1369
  }
1397
1370
  }, _Client_getUserAccessHash = async function _Client_getUserAccessHash(userId) {
1398
1371
  const users = await this.invoke({ _: "users.getUsers", id: [{ _: "inputUser", user_id: userId, access_hash: 0n }] });
1399
- const user = as("user", users[0]);
1372
+ const user = Api.as("user", users[0]);
1400
1373
  if (user) {
1401
1374
  await this.messageStorage.setEntity(user);
1402
1375
  }
1403
1376
  return user?.access_hash ?? 0n;
1404
1377
  }, _Client_getChannelAccessHash = async function _Client_getChannelAccessHash(channelId) {
1405
1378
  const channels = await this.invoke({ _: "channels.getChannels", id: [{ _: "inputChannel", channel_id: channelId, access_hash: 0n }] });
1406
- const channel = as("channel", channels.chats[0]);
1379
+ const channel = Api.as("channel", channels.chats[0]);
1407
1380
  if (channel) {
1408
1381
  await this.messageStorage.setEntity(channel);
1409
1382
  }
1410
1383
  return channel?.access_hash ?? 0n;
1411
1384
  }, _Client_getInputPeerChatId = async function _Client_getInputPeerChatId(inputPeer) {
1412
- if (isOneOf(["inputPeerSelf", "inputUserSelf"], inputPeer)) {
1385
+ if (Api.isOneOf(["inputPeerSelf", "inputUserSelf"], inputPeer)) {
1413
1386
  return await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getSelfId).call(this);
1414
1387
  }
1415
- else if (isOneOf(["inputPeerEmpty", "inputUserEmpty", "inputChannelEmpty"], inputPeer)) {
1388
+ else if (Api.isOneOf(["inputPeerEmpty", "inputUserEmpty", "inputChannelEmpty"], inputPeer)) {
1416
1389
  unreachable();
1417
1390
  }
1418
1391
  else {
1419
- return peerToChatId(inputPeer);
1392
+ return Api.peerToChatId(inputPeer);
1420
1393
  }
1421
1394
  }, _Client_getInputPeerInner = async function _Client_getInputPeerInner(id) {
1422
1395
  const idn = Number(id);
@@ -1436,24 +1409,24 @@ export class Client extends Composer {
1436
1409
  const resolved = await this.invoke({ _: "contacts.resolveUsername", username: id });
1437
1410
  await __classPrivateFieldGet(this, _Client_updateManager, "f").processChats(resolved.chats, resolved);
1438
1411
  await __classPrivateFieldGet(this, _Client_updateManager, "f").processUsers(resolved.users, resolved);
1439
- if (is("peerUser", resolved.peer)) {
1440
- resolvedId = peerToChatId(resolved.peer);
1412
+ if (Api.is("peerUser", resolved.peer)) {
1413
+ resolvedId = Api.peerToChatId(resolved.peer);
1441
1414
  }
1442
- else if (is("peerChannel", resolved.peer)) {
1443
- resolvedId = peerToChatId(resolved.peer);
1415
+ else if (Api.is("peerChannel", resolved.peer)) {
1416
+ resolvedId = Api.peerToChatId(resolved.peer);
1444
1417
  }
1445
1418
  else {
1446
1419
  unreachable();
1447
1420
  }
1448
1421
  }
1449
- const resolvedIdType = getChatIdPeerType(resolvedId);
1422
+ const resolvedIdType = Api.getChatIdPeerType(resolvedId);
1450
1423
  if (resolvedIdType == "user") {
1451
1424
  const accessHash = await this.messageStorage.getUserAccessHash(resolvedId);
1452
- peer = { _: "inputPeerUser", user_id: chatIdToPeerId(resolvedId), access_hash: accessHash ?? 0n };
1425
+ peer = { _: "inputPeerUser", user_id: Api.chatIdToPeerId(resolvedId), access_hash: accessHash ?? 0n };
1453
1426
  }
1454
1427
  else if (resolvedIdType == "channel") {
1455
1428
  const accessHash = await this.messageStorage.getChannelAccessHash(resolvedId);
1456
- peer = { _: "inputPeerChannel", channel_id: chatIdToPeerId(resolvedId), access_hash: accessHash ?? 0n };
1429
+ peer = { _: "inputPeerChannel", channel_id: Api.chatIdToPeerId(resolvedId), access_hash: accessHash ?? 0n };
1457
1430
  }
1458
1431
  else {
1459
1432
  unreachable();
@@ -1461,20 +1434,20 @@ export class Client extends Composer {
1461
1434
  }
1462
1435
  else if (id > 0) {
1463
1436
  const accessHash = await this.messageStorage.getUserAccessHash(id);
1464
- peer = { _: "inputPeerUser", user_id: chatIdToPeerId(id), access_hash: accessHash ?? 0n };
1437
+ peer = { _: "inputPeerUser", user_id: Api.chatIdToPeerId(id), access_hash: accessHash ?? 0n };
1465
1438
  }
1466
1439
  else if (-MAX_CHAT_ID <= id) {
1467
1440
  peer = { _: "inputPeerChat", chat_id: BigInt(Math.abs(id)) };
1468
1441
  }
1469
1442
  else if (ZERO_CHANNEL_ID - MAX_CHANNEL_ID <= id && id != ZERO_CHANNEL_ID) {
1470
1443
  const accessHash = await this.messageStorage.getChannelAccessHash(id);
1471
- peer = { _: "inputPeerChannel", channel_id: chatIdToPeerId(id), access_hash: accessHash ?? 0n };
1444
+ peer = { _: "inputPeerChannel", channel_id: Api.chatIdToPeerId(id), access_hash: accessHash ?? 0n };
1472
1445
  }
1473
1446
  else {
1474
1447
  throw new InputError("The ID is of an format unknown.");
1475
1448
  }
1476
- if (!is("inputPeerChat", peer) && !peer.access_hash) {
1477
- const chatId = peerToChatId(peer);
1449
+ if (!Api.is("inputPeerChat", peer) && !peer.access_hash) {
1450
+ const chatId = Api.peerToChatId(peer);
1478
1451
  const minPeerReference = await this.messageStorage.getLastMinPeerReference(chatId);
1479
1452
  if (minPeerReference) {
1480
1453
  const minInputPeer = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getMinInputPeer).call(this, canBeInputChannel(peer) ? "channel" : "user", { ...minPeerReference, senderId: chatId });
@@ -1487,22 +1460,22 @@ export class Client extends Composer {
1487
1460
  return peer;
1488
1461
  }, _Client_getMinInputPeer = async function _Client_getMinInputPeer(type, reference) {
1489
1462
  const entity = await this.messageStorage.getEntity(reference.chatId);
1490
- if (isOneOf(["channel", "channelForbidden"], entity) && entity.access_hash) {
1463
+ if (Api.isOneOf(["channel", "channelForbidden"], entity) && entity.access_hash) {
1491
1464
  const peer = { _: "inputPeerChannel", channel_id: entity.id, access_hash: entity.access_hash };
1492
1465
  if (type == "user") {
1493
- return { _: "inputPeerUserFromMessage", peer, msg_id: reference.messageId, user_id: chatIdToPeerId(reference.senderId) };
1466
+ return { _: "inputPeerUserFromMessage", peer, msg_id: reference.messageId, user_id: Api.chatIdToPeerId(reference.senderId) };
1494
1467
  }
1495
1468
  else {
1496
- return { _: "inputPeerChannelFromMessage", peer, msg_id: reference.messageId, channel_id: chatIdToPeerId(reference.senderId) };
1469
+ return { _: "inputPeerChannelFromMessage", peer, msg_id: reference.messageId, channel_id: Api.chatIdToPeerId(reference.senderId) };
1497
1470
  }
1498
1471
  }
1499
1472
  else {
1500
1473
  return null;
1501
1474
  }
1502
1475
  }, getEntity)](peer) {
1503
- const id = peerToChatId(peer);
1476
+ const id = Api.peerToChatId(peer);
1504
1477
  const entity = await this.messageStorage.getEntity(id);
1505
- if (entity == null && await this.storage.getAccountType() == "bot" && is("peerUser", peer) || is("peerChannel", peer)) {
1478
+ if (entity == null && await this.storage.getAccountType() == "bot" && Api.is("peerUser", peer) || Api.is("peerChannel", peer)) {
1506
1479
  await this.getInputPeer(id);
1507
1480
  }
1508
1481
  else {
@@ -1522,7 +1495,7 @@ export class Client extends Composer {
1522
1495
  let user_ = await this[getEntity]({ _: "peerUser", user_id: BigInt(await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getSelfId).call(this)) });
1523
1496
  if (user_ == null) {
1524
1497
  const users = await this.invoke({ _: "users.getUsers", id: [{ _: "inputUserSelf" }] });
1525
- user_ = as("user", users[0]);
1498
+ user_ = Api.as("user", users[0]);
1526
1499
  await this.messageStorage.setEntity(user_);
1527
1500
  }
1528
1501
  const user = constructUser(user_);
@@ -3320,7 +3293,7 @@ export class Client extends Composer {
3320
3293
  await __classPrivateFieldGet(this, _Client_giftManager, "f").sellGift(userId, messageId);
3321
3294
  }
3322
3295
  }
3323
- _a = Client, _Client_handleCtxUpdate = async function _Client_handleCtxUpdate(update) {
3296
+ _Client_handleCtxUpdate = async function _Client_handleCtxUpdate(update) {
3324
3297
  if (__classPrivateFieldGet(this, _Client_disableUpdates, "f") && !("authorizationState" in update) && !("connectionState" in update)) {
3325
3298
  return;
3326
3299
  }
@@ -3336,7 +3309,7 @@ _a = Client, _Client_handleCtxUpdate = async function _Client_handleCtxUpdate(up
3336
3309
  });
3337
3310
  }, _Client_handleUpdate = async function _Client_handleUpdate(update) {
3338
3311
  const promises = new Array();
3339
- if (is("updateUserName", update)) {
3312
+ if (Api.is("updateUserName", update)) {
3340
3313
  await this.messageStorage.updateUsernames(Number(update.user_id), update.usernames.map((v) => v.username));
3341
3314
  const peer = { ...update, _: "peerUser" };
3342
3315
  const entity = await this[getEntity](peer);
@@ -3452,4 +3425,15 @@ _a = Client, _Client_handleCtxUpdate = async function _Client_handleCtxUpdate(up
3452
3425
  __classPrivateFieldSet(this, _Client_lastGetMe, user, "f");
3453
3426
  return user;
3454
3427
  }
3428
+ }, _Client_onConnectionStateChange = function _Client_onConnectionStateChange(connected) {
3429
+ if (__classPrivateFieldGet(this, _Client_lastConnectionState, "f") != connected) {
3430
+ if (connected) {
3431
+ if (__classPrivateFieldGet(this, _Client_previouslyConnected, "f")) {
3432
+ drop(__classPrivateFieldGet(this, _Client_updateManager, "f").recoverUpdateGap("reconnect"));
3433
+ }
3434
+ __classPrivateFieldSet(this, _Client_previouslyConnected, true, "f");
3435
+ }
3436
+ const connectionState = connected ? "ready" : "notConnected";
3437
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_queueHandleCtxUpdate).call(this, { connectionState });
3438
+ }
3455
3439
  };