@mtkruto/node 0.67.2 → 0.68.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 (244) hide show
  1. package/esm/0_errors.js +2 -6
  2. package/esm/3_errors.js +2 -12
  3. package/esm/3_types.d.ts +1 -0
  4. package/esm/3_types.d.ts.map +1 -1
  5. package/esm/3_types.js +1 -0
  6. package/esm/4_errors.js +2 -12
  7. package/esm/_dnt.polyfills.d.ts +99 -0
  8. package/esm/_dnt.polyfills.d.ts.map +1 -1
  9. package/esm/_dnt.polyfills.js +127 -1
  10. package/esm/_dnt.test_polyfills.d.ts.map +1 -0
  11. package/esm/client/0_filters_test.d.ts.map +1 -1
  12. package/esm/client/0_markdown_test.d.ts.map +1 -1
  13. package/esm/client/0_params.d.ts +2 -0
  14. package/esm/client/0_params.d.ts.map +1 -1
  15. package/esm/client/0_password.d.ts +5 -5
  16. package/esm/client/0_password.d.ts.map +1 -1
  17. package/esm/client/0_password_test.d.ts.map +1 -1
  18. package/esm/client/0_storage_operations.js +143 -155
  19. package/esm/client/0_storage_operations_test.d.ts.map +1 -1
  20. package/esm/client/0_utilities.d.ts +1 -1
  21. package/esm/client/0_utilities_test.d.ts.map +1 -1
  22. package/esm/client/1_client_plain.js +4 -22
  23. package/esm/client/1_composer.js +8 -21
  24. package/esm/client/2_account_manager.js +85 -97
  25. package/esm/client/2_bot_info_manager.js +26 -38
  26. package/esm/client/2_business_connection_manager.js +10 -23
  27. package/esm/client/2_client_encrypted.js +194 -211
  28. package/esm/client/2_file_manager.d.ts +4 -3
  29. package/esm/client/2_file_manager.d.ts.map +1 -1
  30. package/esm/client/2_file_manager.js +268 -224
  31. package/esm/client/2_file_manager_test.d.ts.map +1 -1
  32. package/esm/client/2_network_statistics_manager.js +8 -21
  33. package/esm/client/2_payment_manager.js +7 -20
  34. package/esm/client/2_reaction_manager.js +7 -20
  35. package/esm/client/2_translations_manager.js +97 -107
  36. package/esm/client/2_update_manager.js +764 -759
  37. package/esm/client/3_client_encrypted_pool.js +10 -26
  38. package/esm/client/3_client_encrypted_pool_test.d.ts.map +1 -1
  39. package/esm/client/3_message_manager.d.ts +1 -1
  40. package/esm/client/3_message_manager.js +441 -448
  41. package/esm/client/3_message_manager_test.d.ts.map +1 -1
  42. package/esm/client/3_video_chat_manager.d.ts +1 -1
  43. package/esm/client/3_video_chat_manager.js +57 -68
  44. package/esm/client/4_callback_query_manager.js +18 -30
  45. package/esm/client/4_chat_list_manager.js +322 -318
  46. package/esm/client/4_chat_manager.js +118 -131
  47. package/esm/client/4_forum_manager.js +67 -73
  48. package/esm/client/4_gift_manager.js +16 -29
  49. package/esm/client/4_inline_query_manager.js +16 -28
  50. package/esm/client/4_link_preview_manager.js +6 -19
  51. package/esm/client/4_poll_manager.js +44 -57
  52. package/esm/client/4_story_manager.js +41 -53
  53. package/esm/client/5_client.d.ts +7 -0
  54. package/esm/client/5_client.d.ts.map +1 -1
  55. package/esm/client/5_client.js +1269 -1288
  56. package/esm/connection/1_connection_tcp.node.js +48 -65
  57. package/esm/connection/1_connection_web_socket.js +75 -91
  58. package/esm/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
  59. package/esm/deps/jsr.io/@std/async/1.0.13/mux_async_iterator.js +31 -47
  60. package/esm/deps/jsr.io/@std/async/1.0.13/tee.js +11 -34
  61. package/esm/deps/jsr.io/@std/datetime/0.225.5/_date_time_formatter.js +4 -17
  62. package/esm/mod.js +2 -12
  63. package/esm/session/0_session_state.js +12 -38
  64. package/esm/session/1_session.js +49 -72
  65. package/esm/session/2_session_encrypted.js +324 -320
  66. package/esm/storage/1_utilities_test.d.ts.map +1 -1
  67. package/esm/storage/2_storage_indexed_db.js +26 -44
  68. package/esm/storage/2_storage_local_storage.node.js +12 -25
  69. package/esm/storage/2_storage_memory.js +24 -41
  70. package/esm/storage/2_storage_session_storage.js +3 -16
  71. package/esm/tl/0_utilities_test.d.ts.map +1 -1
  72. package/esm/tl/1_tl_reader.js +80 -88
  73. package/esm/tl/1_tl_reader_test.d.ts.map +1 -1
  74. package/esm/tl/1_tl_writer.js +155 -164
  75. package/esm/tl/1_tl_writer_test.d.ts.map +1 -1
  76. package/esm/transport/0_transport.js +1 -8
  77. package/esm/transport/1_transport_abridged.js +11 -24
  78. package/esm/transport/1_transport_intermediate.js +10 -23
  79. package/esm/transport/2_transport_provider_web_socket.d.ts.map +1 -1
  80. package/esm/types/0_upload_progress.d.ts +29 -0
  81. package/esm/types/0_upload_progress.d.ts.map +1 -0
  82. package/esm/types/0_upload_progress.js +20 -0
  83. package/esm/types/1_sticker.d.ts +1 -1
  84. package/esm/types/1_sticker.d.ts.map +1 -1
  85. package/esm/types/2_poll_answer.d.ts +19 -0
  86. package/esm/types/2_poll_answer.d.ts.map +1 -1
  87. package/esm/types/2_poll_answer.js +19 -0
  88. package/esm/types/7_update.d.ts +21 -2
  89. package/esm/types/7_update.d.ts.map +1 -1
  90. package/esm/utilities/0_bigint_test.d.ts.map +1 -1
  91. package/esm/utilities/0_buffer.d.ts +1 -1
  92. package/esm/utilities/0_buffer.d.ts.map +1 -1
  93. package/esm/utilities/0_buffer_test.d.ts.map +1 -1
  94. package/esm/utilities/0_hash.d.ts +2 -2
  95. package/esm/utilities/0_hash.d.ts.map +1 -1
  96. package/esm/utilities/0_mutex.js +4 -19
  97. package/esm/utilities/0_part_stream.js +11 -25
  98. package/esm/utilities/0_part_stream_test.d.ts.map +1 -1
  99. package/esm/utilities/0_rle.d.ts +2 -2
  100. package/esm/utilities/0_rle.d.ts.map +1 -1
  101. package/esm/utilities/0_rle_test.d.ts.map +1 -1
  102. package/esm/utilities/0_text.d.ts +20 -1
  103. package/esm/utilities/0_text.d.ts.map +1 -1
  104. package/esm/utilities/0_text.js +19 -0
  105. package/esm/utilities/1_auth.d.ts +1 -1
  106. package/esm/utilities/1_auth.d.ts.map +1 -1
  107. package/esm/utilities/1_base64.d.ts +1 -1
  108. package/esm/utilities/1_base64.d.ts.map +1 -1
  109. package/esm/utilities/1_base64_test.d.ts.map +1 -1
  110. package/esm/utilities/1_crypto.js +42 -53
  111. package/esm/utilities/1_crypto_test.d.ts.map +1 -1
  112. package/esm/utilities/1_logger.d.ts +2 -2
  113. package/esm/utilities/1_math_test.d.ts.map +1 -1
  114. package/esm/utilities/2_queue.js +29 -47
  115. package/package.json +1 -1
  116. package/script/0_errors.js +2 -6
  117. package/script/2_tl.js +17 -7
  118. package/script/3_errors.js +2 -12
  119. package/script/3_types.d.ts +1 -0
  120. package/script/3_types.d.ts.map +1 -1
  121. package/script/3_types.js +1 -0
  122. package/script/4_constants.js +17 -7
  123. package/script/4_errors.js +2 -12
  124. package/script/_dnt.polyfills.d.ts +99 -0
  125. package/script/_dnt.polyfills.d.ts.map +1 -1
  126. package/script/_dnt.polyfills.js +128 -0
  127. package/script/_dnt.test_polyfills.d.ts.map +1 -0
  128. package/script/client/0_filters_test.d.ts.map +1 -1
  129. package/script/client/0_markdown_test.d.ts.map +1 -1
  130. package/script/client/0_params.d.ts +2 -0
  131. package/script/client/0_params.d.ts.map +1 -1
  132. package/script/client/0_password.d.ts +5 -5
  133. package/script/client/0_password.d.ts.map +1 -1
  134. package/script/client/0_password.js +17 -7
  135. package/script/client/0_password_test.d.ts.map +1 -1
  136. package/script/client/0_storage_operations.js +143 -155
  137. package/script/client/0_storage_operations_test.d.ts.map +1 -1
  138. package/script/client/0_utilities.d.ts +1 -1
  139. package/script/client/0_utilities_test.d.ts.map +1 -1
  140. package/script/client/1_client_plain.js +4 -22
  141. package/script/client/1_composer.js +8 -21
  142. package/script/client/2_account_manager.js +85 -97
  143. package/script/client/2_bot_info_manager.js +26 -38
  144. package/script/client/2_business_connection_manager.js +10 -23
  145. package/script/client/2_client_encrypted.js +195 -212
  146. package/script/client/2_file_manager.d.ts +4 -3
  147. package/script/client/2_file_manager.d.ts.map +1 -1
  148. package/script/client/2_file_manager.js +285 -231
  149. package/script/client/2_file_manager_test.d.ts.map +1 -1
  150. package/script/client/2_network_statistics_manager.js +8 -21
  151. package/script/client/2_payment_manager.js +7 -20
  152. package/script/client/2_reaction_manager.js +7 -20
  153. package/script/client/2_translations_manager.js +98 -108
  154. package/script/client/2_update_manager.js +764 -759
  155. package/script/client/3_client_encrypted_pool.js +10 -26
  156. package/script/client/3_client_encrypted_pool_test.d.ts.map +1 -1
  157. package/script/client/3_message_manager.d.ts +1 -1
  158. package/script/client/3_message_manager.js +441 -448
  159. package/script/client/3_message_manager_test.d.ts.map +1 -1
  160. package/script/client/3_video_chat_manager.d.ts +1 -1
  161. package/script/client/3_video_chat_manager.js +57 -68
  162. package/script/client/4_callback_query_manager.js +18 -30
  163. package/script/client/4_chat_list_manager.js +322 -318
  164. package/script/client/4_chat_manager.js +118 -131
  165. package/script/client/4_forum_manager.js +67 -73
  166. package/script/client/4_gift_manager.js +16 -29
  167. package/script/client/4_inline_query_manager.js +16 -28
  168. package/script/client/4_link_preview_manager.js +6 -19
  169. package/script/client/4_poll_manager.js +44 -57
  170. package/script/client/4_story_manager.js +41 -53
  171. package/script/client/5_client.d.ts +7 -0
  172. package/script/client/5_client.d.ts.map +1 -1
  173. package/script/client/5_client.js +1269 -1288
  174. package/script/connection/1_connection_tcp.node.js +48 -65
  175. package/script/connection/1_connection_web_socket.js +92 -98
  176. package/script/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
  177. package/script/deps/jsr.io/@std/assert/1.0.13/equal.js +17 -7
  178. package/script/deps/jsr.io/@std/async/1.0.13/delay.js +17 -7
  179. package/script/deps/jsr.io/@std/async/1.0.13/mux_async_iterator.js +31 -47
  180. package/script/deps/jsr.io/@std/async/1.0.13/tee.js +11 -34
  181. package/script/deps/jsr.io/@std/datetime/0.225.5/_date_time_formatter.js +4 -17
  182. package/script/deps/jsr.io/@std/internal/1.0.10/format.js +17 -7
  183. package/script/deps/jsr.io/@std/internal/1.0.10/styles.js +17 -7
  184. package/script/deps/jsr.io/@std/path/1.1.0/_os.js +17 -7
  185. package/script/mod.js +19 -19
  186. package/script/session/0_session_state.js +12 -38
  187. package/script/session/1_session.js +66 -79
  188. package/script/session/2_session_encrypted.js +325 -321
  189. package/script/storage/1_utilities_test.d.ts.map +1 -1
  190. package/script/storage/2_storage_indexed_db.js +26 -44
  191. package/script/storage/2_storage_local_storage.node.js +12 -25
  192. package/script/storage/2_storage_memory.js +24 -41
  193. package/script/storage/2_storage_session_storage.js +3 -16
  194. package/script/tl/0_utilities_test.d.ts.map +1 -1
  195. package/script/tl/1_tl_reader.js +81 -89
  196. package/script/tl/1_tl_reader_test.d.ts.map +1 -1
  197. package/script/tl/1_tl_writer.js +156 -165
  198. package/script/tl/1_tl_writer_test.d.ts.map +1 -1
  199. package/script/tl/2_telegram.js +17 -7
  200. package/script/transport/0_obfuscation.js +17 -7
  201. package/script/transport/0_transport.js +1 -8
  202. package/script/transport/1_transport_abridged.js +11 -24
  203. package/script/transport/1_transport_intermediate.js +10 -23
  204. package/script/transport/2_transport_provider_web_socket.d.ts.map +1 -1
  205. package/script/types/0_upload_progress.d.ts +29 -0
  206. package/script/types/0_upload_progress.d.ts.map +1 -0
  207. package/script/types/0_upload_progress.js +21 -0
  208. package/script/types/1_sticker.d.ts +1 -1
  209. package/script/types/1_sticker.d.ts.map +1 -1
  210. package/script/types/2_poll_answer.d.ts +19 -0
  211. package/script/types/2_poll_answer.d.ts.map +1 -1
  212. package/script/types/2_poll_answer.js +19 -0
  213. package/script/types/7_update.d.ts +21 -2
  214. package/script/types/7_update.d.ts.map +1 -1
  215. package/script/utilities/0_bigint.js +17 -7
  216. package/script/utilities/0_bigint_test.d.ts.map +1 -1
  217. package/script/utilities/0_buffer.d.ts +1 -1
  218. package/script/utilities/0_buffer.d.ts.map +1 -1
  219. package/script/utilities/0_buffer_test.d.ts.map +1 -1
  220. package/script/utilities/0_env.js +17 -7
  221. package/script/utilities/0_hash.d.ts +2 -2
  222. package/script/utilities/0_hash.d.ts.map +1 -1
  223. package/script/utilities/0_hash.js +17 -7
  224. package/script/utilities/0_misc.js +17 -7
  225. package/script/utilities/0_mutex.js +4 -19
  226. package/script/utilities/0_part_stream.js +11 -25
  227. package/script/utilities/0_part_stream_test.d.ts.map +1 -1
  228. package/script/utilities/0_rle.d.ts +2 -2
  229. package/script/utilities/0_rle.d.ts.map +1 -1
  230. package/script/utilities/0_rle_test.d.ts.map +1 -1
  231. package/script/utilities/0_text.d.ts +20 -1
  232. package/script/utilities/0_text.d.ts.map +1 -1
  233. package/script/utilities/0_text.js +19 -0
  234. package/script/utilities/1_auth.d.ts +1 -1
  235. package/script/utilities/1_auth.d.ts.map +1 -1
  236. package/script/utilities/1_auth.js +17 -7
  237. package/script/utilities/1_base64.d.ts +1 -1
  238. package/script/utilities/1_base64.d.ts.map +1 -1
  239. package/script/utilities/1_base64_test.d.ts.map +1 -1
  240. package/script/utilities/1_crypto.js +60 -61
  241. package/script/utilities/1_crypto_test.d.ts.map +1 -1
  242. package/script/utilities/1_logger.d.ts +2 -2
  243. package/script/utilities/1_math_test.d.ts.map +1 -1
  244. package/script/utilities/2_queue.js +30 -48
@@ -17,36 +17,31 @@
17
17
  * You should have received a copy of the GNU Lesser General Public License
18
18
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
19
  */
20
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
21
- if (kind === "m") throw new TypeError("Private method is not writable");
22
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
23
- 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");
24
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
25
- };
26
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
27
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
28
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
29
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
30
- };
31
- var _ForumManager_instances, _a, _ForumManager_c, _ForumManager_validateTopicTitle, _ForumManager_assertNongenralTopicIdValid, _ForumManager_assertAnyTopicIdValid, _ForumManager_toggleGeneralTopicHidden, _ForumManager_toggleNongeneralTopicClosed, _ForumManager_setTopicPinned;
20
+ var _a;
32
21
  import { InputError } from "../0_errors.js";
33
22
  import { getRandomId } from "../1_utilities.js";
34
23
  import { assertMessageType, constructTopic } from "../3_types.js";
35
24
  export class ForumManager {
25
+ #c;
36
26
  constructor(c) {
37
- _ForumManager_instances.add(this);
38
- _ForumManager_c.set(this, void 0);
39
- __classPrivateFieldSet(this, _ForumManager_c, c, "f");
27
+ this.#c = c;
28
+ }
29
+ static #validateTopicTitle(title) {
30
+ title = title.trim();
31
+ if (!title) {
32
+ throw new InputEvent("Invalid topic title.");
33
+ }
34
+ return title;
40
35
  }
41
36
  async createTopic(chatId, title, params) {
42
- title = __classPrivateFieldGet(_a, _a, "m", _ForumManager_validateTopicTitle).call(_a, title);
37
+ title = _a.#validateTopicTitle(title);
43
38
  let send_as;
44
39
  if (params?.sendAs) {
45
- __classPrivateFieldGet(this, _ForumManager_c, "f").storage.assertUser("sendAs");
46
- send_as = await __classPrivateFieldGet(this, _ForumManager_c, "f").getInputPeer(params.sendAs);
40
+ this.#c.storage.assertUser("sendAs");
41
+ send_as = await this.#c.getInputPeer(params.sendAs);
47
42
  }
48
- const channel = await __classPrivateFieldGet(this, _ForumManager_c, "f").getInputChannel(chatId);
49
- const updates = await __classPrivateFieldGet(this, _ForumManager_c, "f").invoke({
43
+ const channel = await this.#c.getInputChannel(chatId);
44
+ const updates = await this.#c.invoke({
50
45
  _: "channels.createForumTopic",
51
46
  channel,
52
47
  title,
@@ -55,80 +50,79 @@ export class ForumManager {
55
50
  send_as,
56
51
  random_id: getRandomId(),
57
52
  });
58
- const message = (await __classPrivateFieldGet(this, _ForumManager_c, "f").messageManager.updatesToMessages(chatId, updates))[0];
53
+ const message = (await this.#c.messageManager.updatesToMessages(chatId, updates))[0];
59
54
  return constructTopic(assertMessageType(message, "forumTopicCreated"));
60
55
  }
56
+ static #assertNongenralTopicIdValid(topicId) {
57
+ if (!topicId || topicId < 2) {
58
+ throw new InputError("Invalid topic ID.");
59
+ }
60
+ }
61
+ static #assertAnyTopicIdValid(topicId) {
62
+ if (!topicId || topicId < 1) {
63
+ throw new InputError("Invalid topic ID.");
64
+ }
65
+ }
61
66
  async editTopic(chatId, topicId, title, params) {
62
- __classPrivateFieldGet(_a, _a, "m", _ForumManager_assertNongenralTopicIdValid).call(_a, topicId);
63
- title = __classPrivateFieldGet(_a, _a, "m", _ForumManager_validateTopicTitle).call(_a, title);
64
- const channel = await __classPrivateFieldGet(this, _ForumManager_c, "f").getInputChannel(chatId);
65
- const updates = await __classPrivateFieldGet(this, _ForumManager_c, "f").invoke({
67
+ _a.#assertNongenralTopicIdValid(topicId);
68
+ title = _a.#validateTopicTitle(title);
69
+ const channel = await this.#c.getInputChannel(chatId);
70
+ const updates = await this.#c.invoke({
66
71
  _: "channels.editForumTopic",
67
72
  channel,
68
73
  topic_id: topicId,
69
74
  title,
70
75
  icon_emoji_id: params?.customEmojiId ? BigInt(params.customEmojiId) : undefined,
71
76
  });
72
- const message = (await __classPrivateFieldGet(this, _ForumManager_c, "f").messageManager.updatesToMessages(chatId, updates))[0];
77
+ const message = (await this.#c.messageManager.updatesToMessages(chatId, updates))[0];
73
78
  return constructTopic(assertMessageType(message, "forumTopicEdited"));
74
79
  }
80
+ async #toggleGeneralTopicHidden(chatId, hidden) {
81
+ const channel = await this.#c.getInputChannel(chatId);
82
+ await this.#c.invoke({
83
+ _: "channels.editForumTopic",
84
+ channel,
85
+ topic_id: 1,
86
+ hidden,
87
+ });
88
+ }
75
89
  async hideGeneralTopic(chatId) {
76
- await __classPrivateFieldGet(this, _ForumManager_instances, "m", _ForumManager_toggleGeneralTopicHidden).call(this, chatId, true);
90
+ await this.#toggleGeneralTopicHidden(chatId, true);
77
91
  }
78
92
  async showGeneralTopic(chatId) {
79
- await __classPrivateFieldGet(this, _ForumManager_instances, "m", _ForumManager_toggleGeneralTopicHidden).call(this, chatId, false);
93
+ await this.#toggleGeneralTopicHidden(chatId, false);
94
+ }
95
+ async #toggleNongeneralTopicClosed(chatId, topicId, closed) {
96
+ _a.#assertNongenralTopicIdValid(topicId);
97
+ const channel = await this.#c.getInputChannel(chatId);
98
+ await this.#c.invoke({
99
+ _: "channels.editForumTopic",
100
+ channel,
101
+ topic_id: 1,
102
+ closed,
103
+ });
80
104
  }
81
105
  async closeTopic(chatId, topicId) {
82
- await __classPrivateFieldGet(this, _ForumManager_instances, "m", _ForumManager_toggleNongeneralTopicClosed).call(this, chatId, topicId, true);
106
+ await this.#toggleNongeneralTopicClosed(chatId, topicId, true);
83
107
  }
84
108
  async reopenTopic(chatId, topicId) {
85
- await __classPrivateFieldGet(this, _ForumManager_instances, "m", _ForumManager_toggleNongeneralTopicClosed).call(this, chatId, topicId, false);
109
+ await this.#toggleNongeneralTopicClosed(chatId, topicId, false);
110
+ }
111
+ async #setTopicPinned(chatId, topicId, pinned) {
112
+ _a.#assertAnyTopicIdValid(topicId);
113
+ const channel = await this.#c.getInputChannel(chatId);
114
+ await this.#c.invoke({
115
+ _: "channels.updatePinnedForumTopic",
116
+ channel,
117
+ topic_id: 1,
118
+ pinned,
119
+ });
86
120
  }
87
121
  async pinTopic(chatId, topicId) {
88
- await __classPrivateFieldGet(this, _ForumManager_instances, "m", _ForumManager_setTopicPinned).call(this, chatId, topicId, true);
122
+ await this.#setTopicPinned(chatId, topicId, true);
89
123
  }
90
124
  async unpinTopic(chatId, topicId) {
91
- await __classPrivateFieldGet(this, _ForumManager_instances, "m", _ForumManager_setTopicPinned).call(this, chatId, topicId, false);
125
+ await this.#setTopicPinned(chatId, topicId, false);
92
126
  }
93
127
  }
94
- _a = ForumManager, _ForumManager_c = new WeakMap(), _ForumManager_instances = new WeakSet(), _ForumManager_validateTopicTitle = function _ForumManager_validateTopicTitle(title) {
95
- title = title.trim();
96
- if (!title) {
97
- throw new InputEvent("Invalid topic title.");
98
- }
99
- return title;
100
- }, _ForumManager_assertNongenralTopicIdValid = function _ForumManager_assertNongenralTopicIdValid(topicId) {
101
- if (!topicId || topicId < 2) {
102
- throw new InputError("Invalid topic ID.");
103
- }
104
- }, _ForumManager_assertAnyTopicIdValid = function _ForumManager_assertAnyTopicIdValid(topicId) {
105
- if (!topicId || topicId < 1) {
106
- throw new InputError("Invalid topic ID.");
107
- }
108
- }, _ForumManager_toggleGeneralTopicHidden = async function _ForumManager_toggleGeneralTopicHidden(chatId, hidden) {
109
- const channel = await __classPrivateFieldGet(this, _ForumManager_c, "f").getInputChannel(chatId);
110
- await __classPrivateFieldGet(this, _ForumManager_c, "f").invoke({
111
- _: "channels.editForumTopic",
112
- channel,
113
- topic_id: 1,
114
- hidden,
115
- });
116
- }, _ForumManager_toggleNongeneralTopicClosed = async function _ForumManager_toggleNongeneralTopicClosed(chatId, topicId, closed) {
117
- __classPrivateFieldGet(_a, _a, "m", _ForumManager_assertNongenralTopicIdValid).call(_a, topicId);
118
- const channel = await __classPrivateFieldGet(this, _ForumManager_c, "f").getInputChannel(chatId);
119
- await __classPrivateFieldGet(this, _ForumManager_c, "f").invoke({
120
- _: "channels.editForumTopic",
121
- channel,
122
- topic_id: 1,
123
- closed,
124
- });
125
- }, _ForumManager_setTopicPinned = async function _ForumManager_setTopicPinned(chatId, topicId, pinned) {
126
- __classPrivateFieldGet(_a, _a, "m", _ForumManager_assertAnyTopicIdValid).call(_a, topicId);
127
- const channel = await __classPrivateFieldGet(this, _ForumManager_c, "f").getInputChannel(chatId);
128
- await __classPrivateFieldGet(this, _ForumManager_c, "f").invoke({
129
- _: "channels.updatePinnedForumTopic",
130
- channel,
131
- topic_id: 1,
132
- pinned,
133
- });
134
- };
128
+ _a = ForumManager;
@@ -17,63 +17,51 @@
17
17
  * You should have received a copy of the GNU Lesser General Public License
18
18
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
19
  */
20
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
21
- if (kind === "m") throw new TypeError("Private method is not writable");
22
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
23
- 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");
24
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
25
- };
26
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
27
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
28
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
29
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
30
- };
31
- var _GiftManager_c;
32
20
  import { unreachable } from "../0_deps.js";
33
21
  import { InputError } from "../0_errors.js";
34
22
  import { Api } from "../2_tl.js";
35
23
  import { constructClaimedGifts, constructGift } from "../3_types.js";
36
24
  import { getLimit } from "./0_utilities.js";
37
25
  export class GiftManager {
26
+ #c;
38
27
  constructor(c) {
39
- _GiftManager_c.set(this, void 0);
40
- __classPrivateFieldSet(this, _GiftManager_c, c, "f");
28
+ this.#c = c;
41
29
  }
42
30
  async getGifts() {
43
- const gifts = await __classPrivateFieldGet(this, _GiftManager_c, "f").invoke({ _: "payments.getStarGifts", hash: 0 });
31
+ const gifts = await this.#c.invoke({ _: "payments.getStarGifts", hash: 0 });
44
32
  if (!(Api.is("payments.starGifts", gifts))) {
45
33
  unreachable();
46
34
  }
47
- return await Promise.all(gifts.gifts.map((v) => constructGift(v, __classPrivateFieldGet(this, _GiftManager_c, "f").getEntity)));
35
+ return await Promise.all(gifts.gifts.map((v) => constructGift(v, this.#c.getEntity)));
48
36
  }
49
37
  async getClaimedGifts(chatId, params) {
50
- __classPrivateFieldGet(this, _GiftManager_c, "f").storage.assertUser("getClaimedGifts");
38
+ this.#c.storage.assertUser("getClaimedGifts");
51
39
  const offset = params?.offset ?? "";
52
40
  const limit = getLimit(params?.limit);
53
- const peer = await __classPrivateFieldGet(this, _GiftManager_c, "f").getInputPeer(chatId);
54
- const result = await __classPrivateFieldGet(this, _GiftManager_c, "f").invoke({ _: "payments.getSavedStarGifts", peer, offset, limit });
55
- return await constructClaimedGifts(result, __classPrivateFieldGet(this, _GiftManager_c, "f").getEntity);
41
+ const peer = await this.#c.getInputPeer(chatId);
42
+ const result = await this.#c.invoke({ _: "payments.getSavedStarGifts", peer, offset, limit });
43
+ return await constructClaimedGifts(result, this.#c.getEntity);
56
44
  }
57
45
  async sendGift(chatId, giftId, params) {
58
46
  const hide_name = params?.private ? true : undefined;
59
47
  const include_upgrade = params?.upgrade ? true : undefined;
60
- const peer = await __classPrivateFieldGet(this, _GiftManager_c, "f").getInputPeer(chatId);
48
+ const peer = await this.#c.getInputPeer(chatId);
61
49
  const gift_id = BigInt(giftId);
62
50
  let message;
63
51
  if (params?.message) {
64
- const parsedText = await __classPrivateFieldGet(this, _GiftManager_c, "f").messageManager.parseText(params.message, params);
52
+ const parsedText = await this.#c.messageManager.parseText(params.message, params);
65
53
  message = { _: "textWithEntities", text: parsedText[0], entities: parsedText[1] ?? [] };
66
54
  }
67
55
  const invoice = { _: "inputInvoiceStarGift", hide_name, include_upgrade, peer, gift_id, message };
68
- const paymentForm = await __classPrivateFieldGet(this, _GiftManager_c, "f").invoke({ _: "payments.getPaymentForm", invoice });
69
- await __classPrivateFieldGet(this, _GiftManager_c, "f").invoke({ _: "payments.sendStarsForm", form_id: paymentForm.form_id, invoice });
56
+ const paymentForm = await this.#c.invoke({ _: "payments.getPaymentForm", invoice });
57
+ await this.#c.invoke({ _: "payments.sendStarsForm", form_id: paymentForm.form_id, invoice });
70
58
  }
71
59
  async sellGift(userId, messageId) {
72
- const message = await __classPrivateFieldGet(this, _GiftManager_c, "f").messageManager.getMessage(userId, messageId);
60
+ const message = await this.#c.messageManager.getMessage(userId, messageId);
73
61
  if (message == null) {
74
62
  throw new InputError("Message not found.");
75
63
  }
76
- await __classPrivateFieldGet(this, _GiftManager_c, "f").invoke({ _: "payments.convertStarGift", stargift: { _: "inputSavedStarGiftUser", msg_id: message.id } });
64
+ await this.#c.invoke({ _: "payments.convertStarGift", stargift: { _: "inputSavedStarGiftUser", msg_id: message.id } });
77
65
  }
78
66
  async getGift(slug) {
79
67
  if (slug.length > 100) {
@@ -83,8 +71,7 @@ export class GiftManager {
83
71
  if (!/^[a-z]+-[1-9][0-9]*$/.test(slug)) {
84
72
  throw new InputError("Invalid slug.");
85
73
  }
86
- const result = await __classPrivateFieldGet(this, _GiftManager_c, "f").invoke({ _: "payments.getUniqueStarGift", slug });
87
- return await constructGift(result.gift, __classPrivateFieldGet(this, _GiftManager_c, "f").getEntity.bind(this));
74
+ const result = await this.#c.invoke({ _: "payments.getUniqueStarGift", slug });
75
+ return await constructGift(result.gift, this.#c.getEntity.bind(this));
88
76
  }
89
77
  }
90
- _GiftManager_c = new WeakMap();
@@ -17,18 +17,6 @@
17
17
  * You should have received a copy of the GNU Lesser General Public License
18
18
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
19
  */
20
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
21
- if (kind === "m") throw new TypeError("Private method is not writable");
22
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
23
- 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");
24
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
25
- };
26
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
27
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
28
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
29
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
30
- };
31
- var _a, _InlineQueryManager_c, _InlineQueryManager_isExpired;
32
20
  import { unreachable } from "../0_deps.js";
33
21
  import { Api } from "../2_tl.js";
34
22
  import { constructChosenInlineResult, constructInlineQuery, constructInlineQueryAnswer, inlineQueryResultToTlObject } from "../3_types.js";
@@ -38,45 +26,45 @@ const inlineQueryManagerUpdates = [
38
26
  "updateBotInlineSend",
39
27
  ];
40
28
  export class InlineQueryManager {
29
+ #c;
41
30
  constructor(c) {
42
- _InlineQueryManager_c.set(this, void 0);
43
- __classPrivateFieldSet(this, _InlineQueryManager_c, c, "f");
31
+ this.#c = c;
44
32
  }
45
33
  async answerInlineQuery(id, results, params) {
46
- __classPrivateFieldGet(this, _InlineQueryManager_c, "f").storage.assertBot("answerInlineQuery");
34
+ this.#c.storage.assertBot("answerInlineQuery");
47
35
  checkInlineQueryId(id);
48
- await __classPrivateFieldGet(this, _InlineQueryManager_c, "f").invoke({ _: "messages.setInlineBotResults", query_id: BigInt(id), results: await Promise.all(results.map((v) => inlineQueryResultToTlObject(v, __classPrivateFieldGet(this, _InlineQueryManager_c, "f").messageManager.parseText.bind(__classPrivateFieldGet(this, _InlineQueryManager_c, "f").messageManager), __classPrivateFieldGet(this, _InlineQueryManager_c, "f").messageManager.usernameResolver.bind(__classPrivateFieldGet(this, _InlineQueryManager_c, "f").messageManager)))), cache_time: params?.cacheTime ?? 300, private: params?.isPersonal ? true : undefined, switch_webview: params?.button && params.button.miniApp ? ({ _: "inlineBotWebView", text: params.button.text, url: params.button.miniApp.url }) : undefined, switch_pm: params?.button && params.button.startParameter ? ({ _: "inlineBotSwitchPM", text: params.button.text, start_param: params.button.startParameter }) : undefined, gallery: params?.isGallery ? true : undefined, next_offset: params?.nextOffset });
36
+ await this.#c.invoke({ _: "messages.setInlineBotResults", query_id: BigInt(id), results: await Promise.all(results.map((v) => inlineQueryResultToTlObject(v, this.#c.messageManager.parseText.bind(this.#c.messageManager), this.#c.messageManager.usernameResolver.bind(this.#c.messageManager)))), cache_time: params?.cacheTime ?? 300, private: params?.isPersonal ? true : undefined, switch_webview: params?.button && params.button.miniApp ? ({ _: "inlineBotWebView", text: params.button.text, url: params.button.miniApp.url }) : undefined, switch_pm: params?.button && params.button.startParameter ? ({ _: "inlineBotSwitchPM", text: params.button.text, start_param: params.button.startParameter }) : undefined, gallery: params?.isGallery ? true : undefined, next_offset: params?.nextOffset });
49
37
  }
50
38
  canHandleUpdate(update) {
51
39
  return Api.isOneOf(inlineQueryManagerUpdates, update);
52
40
  }
53
41
  async handleUpdate(update) {
54
42
  if (Api.is("updateBotInlineQuery", update)) {
55
- return { inlineQuery: await constructInlineQuery(update, __classPrivateFieldGet(this, _InlineQueryManager_c, "f").getEntity) };
43
+ return { inlineQuery: await constructInlineQuery(update, this.#c.getEntity) };
56
44
  }
57
45
  else if (Api.is("updateBotInlineSend", update)) {
58
- return { chosenInlineResult: await constructChosenInlineResult(update, __classPrivateFieldGet(this, _InlineQueryManager_c, "f").getEntity) };
46
+ return { chosenInlineResult: await constructChosenInlineResult(update, this.#c.getEntity) };
59
47
  }
60
48
  else {
61
49
  unreachable();
62
50
  }
63
51
  }
64
52
  async sendInlineQuery(botId_, chatId, params) {
65
- __classPrivateFieldGet(this, _InlineQueryManager_c, "f").storage.assertUser("sendInlineQuery");
66
- const bot = await __classPrivateFieldGet(this, _InlineQueryManager_c, "f").getInputUser(botId_), peer = await __classPrivateFieldGet(this, _InlineQueryManager_c, "f").getInputPeer(chatId), query = params?.query ?? "", offset = params?.offset ?? "";
67
- const botId = await __classPrivateFieldGet(this, _InlineQueryManager_c, "f").getInputPeerChatId(bot), peerId = await __classPrivateFieldGet(this, _InlineQueryManager_c, "f").getInputPeerChatId(peer);
68
- const maybeResults = await __classPrivateFieldGet(this, _InlineQueryManager_c, "f").messageStorage.getInlineQueryAnswer(botId, peerId, query, offset);
69
- if (maybeResults != null && !__classPrivateFieldGet(_a, _a, "m", _InlineQueryManager_isExpired).call(_a, maybeResults[1], maybeResults[0].cache_time)) {
53
+ this.#c.storage.assertUser("sendInlineQuery");
54
+ const bot = await this.#c.getInputUser(botId_), peer = await this.#c.getInputPeer(chatId), query = params?.query ?? "", offset = params?.offset ?? "";
55
+ const botId = await this.#c.getInputPeerChatId(bot), peerId = await this.#c.getInputPeerChatId(peer);
56
+ const maybeResults = await this.#c.messageStorage.getInlineQueryAnswer(botId, peerId, query, offset);
57
+ if (maybeResults != null && !InlineQueryManager.#isExpired(maybeResults[1], maybeResults[0].cache_time)) {
70
58
  return constructInlineQueryAnswer(maybeResults[0]);
71
59
  }
72
60
  const then = new Date();
73
- const results = await __classPrivateFieldGet(this, _InlineQueryManager_c, "f").invoke({ _: "messages.getInlineBotResults", bot, peer, query, offset });
61
+ const results = await this.#c.invoke({ _: "messages.getInlineBotResults", bot, peer, query, offset });
74
62
  if (results.cache_time > 0) {
75
- await __classPrivateFieldGet(this, _InlineQueryManager_c, "f").messageStorage.setInlineQueryAnswer(botId, peerId, query, offset, results, then);
63
+ await this.#c.messageStorage.setInlineQueryAnswer(botId, peerId, query, offset, results, then);
76
64
  }
77
65
  return constructInlineQueryAnswer(results);
78
66
  }
67
+ static #isExpired(date, cacheTime) {
68
+ return (Date.now() - date.getTime()) / 1000 > cacheTime;
69
+ }
79
70
  }
80
- _a = InlineQueryManager, _InlineQueryManager_c = new WeakMap(), _InlineQueryManager_isExpired = function _InlineQueryManager_isExpired(date, cacheTime) {
81
- return (Date.now() - date.getTime()) / 1000 > cacheTime;
82
- };
@@ -17,37 +17,25 @@
17
17
  * You should have received a copy of the GNU Lesser General Public License
18
18
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
19
  */
20
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
21
- if (kind === "m") throw new TypeError("Private method is not writable");
22
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
23
- 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");
24
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
25
- };
26
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
27
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
28
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
29
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
30
- };
31
- var _LinkPreviewManager_c;
32
20
  import { Api } from "../2_tl.js";
33
21
  import { constructLinkPreview } from "../3_types.js";
34
22
  const linkPreviewManagerUpdates = [
35
23
  "updateWebPage",
36
24
  ];
37
25
  export class LinkPreviewManager {
26
+ #c;
38
27
  constructor(c) {
39
- _LinkPreviewManager_c.set(this, void 0);
40
- __classPrivateFieldSet(this, _LinkPreviewManager_c, c, "f");
28
+ this.#c = c;
41
29
  }
42
30
  async getLinkPreview(text, params) {
43
- const [text_, entities_] = await __classPrivateFieldGet(this, _LinkPreviewManager_c, "f").messageManager.parseText(text, params);
44
- const result = await __classPrivateFieldGet(this, _LinkPreviewManager_c, "f").invoke({
31
+ const [text_, entities_] = await this.#c.messageManager.parseText(text, params);
32
+ const result = await this.#c.invoke({
45
33
  _: "messages.getWebPagePreview",
46
34
  message: text_,
47
35
  entities: entities_,
48
36
  });
49
37
  if (Api.is("messageMediaWebPage", result.media)) {
50
- return await constructLinkPreview(result.media, undefined, __classPrivateFieldGet(this, _LinkPreviewManager_c, "f").getEntity);
38
+ return await constructLinkPreview(result.media, undefined, this.#c.getEntity);
51
39
  }
52
40
  else {
53
41
  return null;
@@ -57,8 +45,7 @@ export class LinkPreviewManager {
57
45
  return Api.isOneOf(linkPreviewManagerUpdates, update);
58
46
  }
59
47
  async handleUpdate(update) {
60
- const linkPreview = await constructLinkPreview({ _: "messageMediaWebPage", webpage: update.webpage }, undefined, __classPrivateFieldGet(this, _LinkPreviewManager_c, "f").getEntity);
48
+ const linkPreview = await constructLinkPreview({ _: "messageMediaWebPage", webpage: update.webpage }, undefined, this.#c.getEntity);
61
49
  return { linkPreview };
62
50
  }
63
51
  }
64
- _LinkPreviewManager_c = new WeakMap();
@@ -17,18 +17,6 @@
17
17
  * You should have received a copy of the GNU Lesser General Public License
18
18
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
19
  */
20
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
21
- if (kind === "m") throw new TypeError("Private method is not writable");
22
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
23
- 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");
24
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
25
- };
26
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
27
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
28
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
29
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
30
- };
31
- var _PollManager_instances, _PollManager_c, _PollManager_voteInner;
32
20
  import { unreachable } from "../0_deps.js";
33
21
  import { InputError } from "../0_errors.js";
34
22
  import { Api } from "../2_tl.js";
@@ -38,35 +26,68 @@ const pollManagerUpdates = [
38
26
  "updateMessagePollVote",
39
27
  ];
40
28
  export class PollManager {
29
+ #c;
41
30
  constructor(c) {
42
- _PollManager_instances.add(this);
43
- _PollManager_c.set(this, void 0);
44
- __classPrivateFieldSet(this, _PollManager_c, c, "f");
31
+ this.#c = c;
45
32
  }
46
33
  async vote(chatId, messageId, optionIndexes) {
47
- __classPrivateFieldGet(this, _PollManager_c, "f").storage.assertUser("vote");
34
+ this.#c.storage.assertUser("vote");
48
35
  if (!optionIndexes.length) {
49
36
  throw new InputError("No options provided.");
50
37
  }
51
- await __classPrivateFieldGet(this, _PollManager_instances, "m", _PollManager_voteInner).call(this, chatId, messageId, optionIndexes);
38
+ await this.#voteInner(chatId, messageId, optionIndexes);
52
39
  }
53
40
  async retractVote(chatId, messageId) {
54
- __classPrivateFieldGet(this, _PollManager_c, "f").storage.assertUser("retractVote");
55
- await __classPrivateFieldGet(this, _PollManager_instances, "m", _PollManager_voteInner).call(this, chatId, messageId, []);
41
+ this.#c.storage.assertUser("retractVote");
42
+ await this.#voteInner(chatId, messageId, []);
43
+ }
44
+ async #voteInner(chatId, messageId, optionIndexes) {
45
+ const message = await this.#c.messageManager.getMessage(chatId, messageId);
46
+ if (!("poll" in message)) {
47
+ throw new InputError("Message not a poll.");
48
+ }
49
+ if (message.poll.options.filter((v) => v.chosen).length == 0 && optionIndexes.length == 0) {
50
+ throw new InputError("No vote has been casted.");
51
+ }
52
+ if (!message.poll.allowMultipleAnswers && optionIndexes.length > 1) {
53
+ throw new InputError("Cannot cast multiple options for this vote.");
54
+ }
55
+ for (const optionIndex of optionIndexes) {
56
+ if (optionIndex + 1 > message.poll.options.length) {
57
+ throw new InputError("Got invalid option index.");
58
+ }
59
+ }
60
+ if (optionIndexes.length > 0 && message.poll.options.map((v, i) => [i, v.chosen]).filter((v) => v[1]).every(([v]) => optionIndexes.includes(v))) {
61
+ throw new InputError("The same options are already casted.");
62
+ }
63
+ const peer = await this.#c.getInputPeer(chatId);
64
+ const chatId_ = Api.peerToChatId(peer);
65
+ const message_ = await this.#c.messageStorage.getMessage(chatId_, messageId);
66
+ if (!Api.is("message", message_)) {
67
+ unreachable();
68
+ }
69
+ const media = message_.media;
70
+ if (!Api.is("messageMediaPoll", media)) {
71
+ unreachable();
72
+ }
73
+ const poll = media.poll;
74
+ optionIndexes = Array.from(new Set(optionIndexes));
75
+ const options = optionIndexes.map((i) => poll.answers[i].option);
76
+ await this.#c.invoke({ _: "messages.sendVote", peer, msg_id: messageId, options });
56
77
  }
57
78
  canHandleUpdate(update) {
58
79
  return Api.isOneOf(pollManagerUpdates, update);
59
80
  }
60
81
  async handleUpdate(update) {
61
82
  if (Api.is("updateMessagePoll", update)) {
62
- await __classPrivateFieldGet(this, _PollManager_c, "f").storage.setPollResults(update.poll_id, update.results);
83
+ await this.#c.storage.setPollResults(update.poll_id, update.results);
63
84
  let poll = null;
64
85
  if (update.poll) {
65
86
  poll = update.poll;
66
- await __classPrivateFieldGet(this, _PollManager_c, "f").storage.setPoll(poll.id, poll);
87
+ await this.#c.storage.setPoll(poll.id, poll);
67
88
  }
68
89
  else {
69
- poll = await __classPrivateFieldGet(this, _PollManager_c, "f").storage.getPoll(update.poll_id);
90
+ poll = await this.#c.storage.getPoll(update.poll_id);
70
91
  }
71
92
  if (poll) {
72
93
  const messageMediaPoll = { _: "messageMediaPoll", poll, results: update.results };
@@ -77,42 +98,8 @@ export class PollManager {
77
98
  }
78
99
  }
79
100
  else {
80
- const pollAnswer = await constructPollAnswer(update, __classPrivateFieldGet(this, _PollManager_c, "f").getEntity);
101
+ const pollAnswer = await constructPollAnswer(update, this.#c.getEntity);
81
102
  return { pollAnswer };
82
103
  }
83
104
  }
84
105
  }
85
- _PollManager_c = new WeakMap(), _PollManager_instances = new WeakSet(), _PollManager_voteInner = async function _PollManager_voteInner(chatId, messageId, optionIndexes) {
86
- const message = await __classPrivateFieldGet(this, _PollManager_c, "f").messageManager.getMessage(chatId, messageId);
87
- if (!("poll" in message)) {
88
- throw new InputError("Message not a poll.");
89
- }
90
- if (message.poll.options.filter((v) => v.chosen).length == 0 && optionIndexes.length == 0) {
91
- throw new InputError("No vote has been casted.");
92
- }
93
- if (!message.poll.allowMultipleAnswers && optionIndexes.length > 1) {
94
- throw new InputError("Cannot cast multiple options for this vote.");
95
- }
96
- for (const optionIndex of optionIndexes) {
97
- if (optionIndex + 1 > message.poll.options.length) {
98
- throw new InputError("Got invalid option index.");
99
- }
100
- }
101
- if (optionIndexes.length > 0 && message.poll.options.map((v, i) => [i, v.chosen]).filter((v) => v[1]).every(([v]) => optionIndexes.includes(v))) {
102
- throw new InputError("The same options are already casted.");
103
- }
104
- const peer = await __classPrivateFieldGet(this, _PollManager_c, "f").getInputPeer(chatId);
105
- const chatId_ = Api.peerToChatId(peer);
106
- const message_ = await __classPrivateFieldGet(this, _PollManager_c, "f").messageStorage.getMessage(chatId_, messageId);
107
- if (!Api.is("message", message_)) {
108
- unreachable();
109
- }
110
- const media = message_.media;
111
- if (!Api.is("messageMediaPoll", media)) {
112
- unreachable();
113
- }
114
- const poll = media.poll;
115
- optionIndexes = Array.from(new Set(optionIndexes));
116
- const options = optionIndexes.map((i) => poll.answers[i].option);
117
- await __classPrivateFieldGet(this, _PollManager_c, "f").invoke({ _: "messages.sendVote", peer, msg_id: messageId, options });
118
- };