@mtkruto/browser 0.119.0 → 0.120.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 (128) hide show
  1. package/README.md +1 -1
  2. package/esm/0_errors.d.ts.map +1 -1
  3. package/esm/0_errors.js +9 -31
  4. package/esm/3_errors.js +2 -12
  5. package/esm/4_errors.js +2 -12
  6. package/esm/_dnt.polyfills.d.ts +0 -99
  7. package/esm/_dnt.polyfills.d.ts.map +1 -1
  8. package/esm/_dnt.polyfills.js +1 -127
  9. package/esm/client/0_abortable_loop.js +26 -39
  10. package/esm/client/0_storage_operations.js +179 -218
  11. package/esm/client/1_client_plain.js +4 -22
  12. package/esm/client/2_account_manager.js +140 -149
  13. package/esm/client/2_bot_info_manager.js +26 -38
  14. package/esm/client/2_business_connection_manager.js +10 -23
  15. package/esm/client/2_client_encrypted.js +198 -215
  16. package/esm/client/2_file_manager.js +255 -262
  17. package/esm/client/2_network_statistics_manager.js +31 -44
  18. package/esm/client/2_payment_manager.js +7 -20
  19. package/esm/client/2_reaction_manager.js +7 -20
  20. package/esm/client/2_translations_manager.js +101 -111
  21. package/esm/client/2_update_manager.js +750 -745
  22. package/esm/client/3_client_encrypted_pool.js +10 -26
  23. package/esm/client/3_message_manager.js +503 -508
  24. package/esm/client/3_video_chat_manager.js +57 -68
  25. package/esm/client/4_callback_query_manager.js +18 -30
  26. package/esm/client/4_chat_list_manager.js +140 -146
  27. package/esm/client/4_chat_manager.js +161 -169
  28. package/esm/client/4_checklist_manager.js +26 -39
  29. package/esm/client/4_context.js +244 -259
  30. package/esm/client/4_forum_manager.js +67 -73
  31. package/esm/client/4_gift_manager.js +22 -35
  32. package/esm/client/4_inline_query_manager.js +16 -28
  33. package/esm/client/4_link_preview_manager.js +6 -19
  34. package/esm/client/4_poll_manager.js +44 -57
  35. package/esm/client/4_story_manager.js +41 -53
  36. package/esm/client/5_composer.js +13 -26
  37. package/esm/client/6_client.js +866 -896
  38. package/esm/client/6_client_dispatcher.js +308 -325
  39. package/esm/client/7_client_worker.js +16 -29
  40. package/esm/connection/1_connection_tcp.js +55 -82
  41. package/esm/connection/1_connection_web_socket.js +75 -91
  42. package/esm/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
  43. package/esm/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +31 -47
  44. package/esm/deps/jsr.io/@std/async/1.2.0/tee.js +11 -34
  45. package/esm/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +30 -47
  46. package/esm/deps/jsr.io/@std/datetime/0.225.7/_date_time_formatter.js +4 -17
  47. package/esm/session/0_session_state.js +12 -38
  48. package/esm/session/1_session.js +49 -72
  49. package/esm/session/2_session_encrypted.js +422 -420
  50. package/esm/storage/2_storage_indexed_db.js +26 -44
  51. package/esm/storage/2_storage_local_storage.js +3 -16
  52. package/esm/storage/2_storage_memory.js +24 -41
  53. package/esm/storage/2_storage_session_storage.js +3 -16
  54. package/esm/tl/1_tl_reader.d.ts +1 -1
  55. package/esm/tl/1_tl_reader.d.ts.map +1 -1
  56. package/esm/tl/1_tl_reader.js +95 -103
  57. package/esm/tl/1_tl_writer.js +169 -178
  58. package/esm/transport/0_transport.js +1 -8
  59. package/esm/transport/1_transport_abridged.js +11 -24
  60. package/esm/transport/1_transport_intermediate.js +10 -23
  61. package/esm/utilities/0_mutex.js +4 -19
  62. package/esm/utilities/0_part_stream.js +11 -25
  63. package/esm/utilities/1_crypto.js +42 -53
  64. package/esm/utilities/2_queue.js +29 -47
  65. package/package.json +1 -1
  66. package/script/0_errors.d.ts.map +1 -1
  67. package/script/0_errors.js +9 -31
  68. package/script/3_errors.js +2 -12
  69. package/script/4_errors.js +2 -12
  70. package/script/_dnt.polyfills.d.ts +0 -99
  71. package/script/_dnt.polyfills.d.ts.map +1 -1
  72. package/script/_dnt.polyfills.js +0 -128
  73. package/script/client/0_abortable_loop.js +27 -40
  74. package/script/client/0_storage_operations.js +179 -218
  75. package/script/client/1_client_plain.js +4 -22
  76. package/script/client/2_account_manager.js +140 -149
  77. package/script/client/2_bot_info_manager.js +26 -38
  78. package/script/client/2_business_connection_manager.js +10 -23
  79. package/script/client/2_client_encrypted.js +199 -216
  80. package/script/client/2_file_manager.js +255 -262
  81. package/script/client/2_network_statistics_manager.js +32 -45
  82. package/script/client/2_payment_manager.js +7 -20
  83. package/script/client/2_reaction_manager.js +7 -20
  84. package/script/client/2_translations_manager.js +102 -112
  85. package/script/client/2_update_manager.js +750 -745
  86. package/script/client/3_client_encrypted_pool.js +10 -26
  87. package/script/client/3_message_manager.js +503 -508
  88. package/script/client/3_video_chat_manager.js +57 -68
  89. package/script/client/4_callback_query_manager.js +18 -30
  90. package/script/client/4_chat_list_manager.js +140 -146
  91. package/script/client/4_chat_manager.js +161 -169
  92. package/script/client/4_checklist_manager.js +26 -39
  93. package/script/client/4_context.js +244 -259
  94. package/script/client/4_forum_manager.js +67 -73
  95. package/script/client/4_gift_manager.js +22 -35
  96. package/script/client/4_inline_query_manager.js +16 -28
  97. package/script/client/4_link_preview_manager.js +6 -19
  98. package/script/client/4_poll_manager.js +44 -57
  99. package/script/client/4_story_manager.js +41 -53
  100. package/script/client/5_composer.js +13 -26
  101. package/script/client/6_client.js +866 -896
  102. package/script/client/6_client_dispatcher.js +308 -325
  103. package/script/client/7_client_worker.js +16 -29
  104. package/script/connection/1_connection_tcp.js +55 -82
  105. package/script/connection/1_connection_web_socket.js +75 -91
  106. package/script/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
  107. package/script/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +31 -47
  108. package/script/deps/jsr.io/@std/async/1.2.0/tee.js +11 -34
  109. package/script/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +30 -47
  110. package/script/deps/jsr.io/@std/datetime/0.225.7/_date_time_formatter.js +4 -17
  111. package/script/session/0_session_state.js +12 -38
  112. package/script/session/1_session.js +49 -72
  113. package/script/session/2_session_encrypted.js +423 -421
  114. package/script/storage/2_storage_indexed_db.js +26 -44
  115. package/script/storage/2_storage_local_storage.js +3 -16
  116. package/script/storage/2_storage_memory.js +24 -41
  117. package/script/storage/2_storage_session_storage.js +3 -16
  118. package/script/tl/1_tl_reader.d.ts +1 -1
  119. package/script/tl/1_tl_reader.d.ts.map +1 -1
  120. package/script/tl/1_tl_reader.js +96 -104
  121. package/script/tl/1_tl_writer.js +170 -179
  122. package/script/transport/0_transport.js +1 -8
  123. package/script/transport/1_transport_abridged.js +11 -24
  124. package/script/transport/1_transport_intermediate.js +10 -23
  125. package/script/utilities/0_mutex.js +4 -19
  126. package/script/utilities/0_part_stream.js +11 -25
  127. package/script/utilities/1_crypto.js +43 -54
  128. 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 peer = await __classPrivateFieldGet(this, _ForumManager_c, "f").getInputPeer(chatId);
49
- const updates = await __classPrivateFieldGet(this, _ForumManager_c, "f").invoke({
43
+ const peer = await this.#c.getInputPeer(chatId);
44
+ const updates = await this.#c.invoke({
50
45
  _: "messages.createForumTopic",
51
46
  peer,
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 peer = await __classPrivateFieldGet(this, _ForumManager_c, "f").getInputPeer(chatId);
65
- const updates = await __classPrivateFieldGet(this, _ForumManager_c, "f").invoke({
67
+ _a.#assertNongenralTopicIdValid(topicId);
68
+ title = _a.#validateTopicTitle(title);
69
+ const peer = await this.#c.getInputPeer(chatId);
70
+ const updates = await this.#c.invoke({
66
71
  _: "messages.editForumTopic",
67
72
  peer,
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 peer = await this.#c.getInputPeer(chatId);
82
+ await this.#c.invoke({
83
+ _: "messages.editForumTopic",
84
+ peer,
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 peer = await this.#c.getInputPeer(chatId);
98
+ await this.#c.invoke({
99
+ _: "messages.editForumTopic",
100
+ peer,
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 peer = await this.#c.getInputPeer(chatId);
114
+ await this.#c.invoke({
115
+ _: "messages.updatePinnedForumTopic",
116
+ peer,
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 peer = await __classPrivateFieldGet(this, _ForumManager_c, "f").getInputPeer(chatId);
110
- await __classPrivateFieldGet(this, _ForumManager_c, "f").invoke({
111
- _: "messages.editForumTopic",
112
- peer,
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 peer = await __classPrivateFieldGet(this, _ForumManager_c, "f").getInputPeer(chatId);
119
- await __classPrivateFieldGet(this, _ForumManager_c, "f").invoke({
120
- _: "messages.editForumTopic",
121
- peer,
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 peer = await __classPrivateFieldGet(this, _ForumManager_c, "f").getInputPeer(chatId);
128
- await __classPrivateFieldGet(this, _ForumManager_c, "f").invoke({
129
- _: "messages.updatePinnedForumTopic",
130
- peer,
131
- topic_id: 1,
132
- pinned,
133
- });
134
- };
128
+ _a = ForumManager;
@@ -17,64 +17,52 @@
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, inputGiftToTlObject } 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").getPeer)));
35
+ return await Promise.all(gifts.gifts.map((v) => constructGift(v, this.#c.getPeer)));
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 constructClaimedGifts(result, __classPrivateFieldGet(this, _GiftManager_c, "f").getPeer);
41
+ const peer = await this.#c.getInputPeer(chatId);
42
+ const result = await this.#c.invoke({ _: "payments.getSavedStarGifts", peer, offset, limit });
43
+ return constructClaimedGifts(result, this.#c.getPeer);
56
44
  }
57
45
  async sendGift(chatId, giftId, params) {
58
46
  const hide_name = params?.isPrivate ? 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(gift) {
72
- const stargift = await inputGiftToTlObject(gift, __classPrivateFieldGet(this, _GiftManager_c, "f").getInputPeer);
73
- await __classPrivateFieldGet(this, _GiftManager_c, "f").invoke({ _: "payments.convertStarGift", stargift });
60
+ const stargift = await inputGiftToTlObject(gift, this.#c.getInputPeer);
61
+ await this.#c.invoke({ _: "payments.convertStarGift", stargift });
74
62
  }
75
63
  async craftGifts(gifts) {
76
- const stargift = await Promise.all(gifts.map((v) => inputGiftToTlObject(v, __classPrivateFieldGet(this, _GiftManager_c, "f").getInputPeer)));
77
- await __classPrivateFieldGet(this, _GiftManager_c, "f").invoke({ _: "payments.craftStarGift", stargift });
64
+ const stargift = await Promise.all(gifts.map((v) => inputGiftToTlObject(v, this.#c.getInputPeer)));
65
+ await this.#c.invoke({ _: "payments.craftStarGift", stargift });
78
66
  }
79
67
  async getGift(slug) {
80
68
  if (slug.length > 100) {
@@ -84,14 +72,13 @@ export class GiftManager {
84
72
  if (!/^[a-z]+-[1-9][0-9]*$/.test(slug)) {
85
73
  throw new InputError("Invalid slug.");
86
74
  }
87
- const result = await __classPrivateFieldGet(this, _GiftManager_c, "f").invoke({ _: "payments.getUniqueStarGift", slug });
88
- return constructGift(result.gift, __classPrivateFieldGet(this, _GiftManager_c, "f").getPeer.bind(this));
75
+ const result = await this.#c.invoke({ _: "payments.getUniqueStarGift", slug });
76
+ return constructGift(result.gift, this.#c.getPeer.bind(this));
89
77
  }
90
78
  async transferGift(chatId, gift) {
91
- __classPrivateFieldGet(this, _GiftManager_c, "f").storage.assertUser("transferGift");
92
- const stargift = await inputGiftToTlObject(gift, __classPrivateFieldGet(this, _GiftManager_c, "f").getInputPeer);
93
- const to_id = await __classPrivateFieldGet(this, _GiftManager_c, "f").getInputPeer(chatId);
94
- await __classPrivateFieldGet(this, _GiftManager_c, "f").invoke({ _: "payments.transferStarGift", stargift, to_id });
79
+ this.#c.storage.assertUser("transferGift");
80
+ const stargift = await inputGiftToTlObject(gift, this.#c.getInputPeer);
81
+ const to_id = await this.#c.getInputPeer(chatId);
82
+ await this.#c.invoke({ _: "payments.transferStarGift", stargift, to_id });
95
83
  }
96
84
  }
97
- _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 { SECOND, 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
  handleUpdate(update) {
54
42
  if (Api.is("updateBotInlineQuery", update)) {
55
- return { inlineQuery: constructInlineQuery(update, __classPrivateFieldGet(this, _InlineQueryManager_c, "f").getPeer) };
43
+ return { inlineQuery: constructInlineQuery(update, this.#c.getPeer) };
56
44
  }
57
45
  else if (Api.is("updateBotInlineSend", update)) {
58
- return { chosenInlineResult: constructChosenInlineResult(update, __classPrivateFieldGet(this, _InlineQueryManager_c, "f").getPeer) };
46
+ return { chosenInlineResult: constructChosenInlineResult(update, this.#c.getPeer) };
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()) / SECOND > cacheTime;
69
+ }
79
70
  }
80
- _a = InlineQueryManager, _InlineQueryManager_c = new WeakMap(), _InlineQueryManager_isExpired = function _InlineQueryManager_isExpired(date, cacheTime) {
81
- return (Date.now() - date.getTime()) / SECOND > 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 constructLinkPreview(result.media, undefined, __classPrivateFieldGet(this, _LinkPreviewManager_c, "f").getPeer);
38
+ return constructLinkPreview(result.media, undefined, this.#c.getPeer);
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
  handleUpdate(update) {
60
- const linkPreview = constructLinkPreview({ _: "messageMediaWebPage", webpage: update.webpage }, undefined, __classPrivateFieldGet(this, _LinkPreviewManager_c, "f").getPeer);
48
+ const linkPreview = constructLinkPreview({ _: "messageMediaWebPage", webpage: update.webpage }, undefined, this.#c.getPeer);
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.isChosen).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.isChosen]).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").messageStorage.setPollResults(update.poll_id, update.results);
83
+ await this.#c.messageStorage.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").messageStorage.setPoll(poll.id, poll);
87
+ await this.#c.messageStorage.setPoll(poll.id, poll);
67
88
  }
68
89
  else {
69
- poll = await __classPrivateFieldGet(this, _PollManager_c, "f").messageStorage.getPoll(update.poll_id);
90
+ poll = await this.#c.messageStorage.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 = constructPollAnswer(update, __classPrivateFieldGet(this, _PollManager_c, "f").getPeer);
101
+ const pollAnswer = constructPollAnswer(update, this.#c.getPeer);
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.isChosen).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.isChosen]).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
- };