@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.
- package/README.md +1 -1
- package/esm/0_errors.d.ts.map +1 -1
- package/esm/0_errors.js +9 -31
- package/esm/3_errors.js +2 -12
- package/esm/4_errors.js +2 -12
- package/esm/_dnt.polyfills.d.ts +0 -99
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/_dnt.polyfills.js +1 -127
- package/esm/client/0_abortable_loop.js +26 -39
- package/esm/client/0_storage_operations.js +179 -218
- package/esm/client/1_client_plain.js +4 -22
- package/esm/client/2_account_manager.js +140 -149
- package/esm/client/2_bot_info_manager.js +26 -38
- package/esm/client/2_business_connection_manager.js +10 -23
- package/esm/client/2_client_encrypted.js +198 -215
- package/esm/client/2_file_manager.js +255 -262
- package/esm/client/2_network_statistics_manager.js +31 -44
- package/esm/client/2_payment_manager.js +7 -20
- package/esm/client/2_reaction_manager.js +7 -20
- package/esm/client/2_translations_manager.js +101 -111
- package/esm/client/2_update_manager.js +750 -745
- package/esm/client/3_client_encrypted_pool.js +10 -26
- package/esm/client/3_message_manager.js +503 -508
- package/esm/client/3_video_chat_manager.js +57 -68
- package/esm/client/4_callback_query_manager.js +18 -30
- package/esm/client/4_chat_list_manager.js +140 -146
- package/esm/client/4_chat_manager.js +161 -169
- package/esm/client/4_checklist_manager.js +26 -39
- package/esm/client/4_context.js +244 -259
- package/esm/client/4_forum_manager.js +67 -73
- package/esm/client/4_gift_manager.js +22 -35
- package/esm/client/4_inline_query_manager.js +16 -28
- package/esm/client/4_link_preview_manager.js +6 -19
- package/esm/client/4_poll_manager.js +44 -57
- package/esm/client/4_story_manager.js +41 -53
- package/esm/client/5_composer.js +13 -26
- package/esm/client/6_client.js +866 -896
- package/esm/client/6_client_dispatcher.js +308 -325
- package/esm/client/7_client_worker.js +16 -29
- package/esm/connection/1_connection_tcp.js +55 -82
- package/esm/connection/1_connection_web_socket.js +75 -91
- package/esm/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
- package/esm/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +31 -47
- package/esm/deps/jsr.io/@std/async/1.2.0/tee.js +11 -34
- package/esm/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +30 -47
- package/esm/deps/jsr.io/@std/datetime/0.225.7/_date_time_formatter.js +4 -17
- package/esm/session/0_session_state.js +12 -38
- package/esm/session/1_session.js +49 -72
- package/esm/session/2_session_encrypted.js +422 -420
- package/esm/storage/2_storage_indexed_db.js +26 -44
- package/esm/storage/2_storage_local_storage.js +3 -16
- package/esm/storage/2_storage_memory.js +24 -41
- package/esm/storage/2_storage_session_storage.js +3 -16
- package/esm/tl/1_tl_reader.d.ts +1 -1
- package/esm/tl/1_tl_reader.d.ts.map +1 -1
- package/esm/tl/1_tl_reader.js +95 -103
- package/esm/tl/1_tl_writer.js +169 -178
- package/esm/transport/0_transport.js +1 -8
- package/esm/transport/1_transport_abridged.js +11 -24
- package/esm/transport/1_transport_intermediate.js +10 -23
- package/esm/utilities/0_mutex.js +4 -19
- package/esm/utilities/0_part_stream.js +11 -25
- package/esm/utilities/1_crypto.js +42 -53
- package/esm/utilities/2_queue.js +29 -47
- package/package.json +1 -1
- package/script/0_errors.d.ts.map +1 -1
- package/script/0_errors.js +9 -31
- package/script/3_errors.js +2 -12
- package/script/4_errors.js +2 -12
- package/script/_dnt.polyfills.d.ts +0 -99
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +0 -128
- package/script/client/0_abortable_loop.js +27 -40
- package/script/client/0_storage_operations.js +179 -218
- package/script/client/1_client_plain.js +4 -22
- package/script/client/2_account_manager.js +140 -149
- package/script/client/2_bot_info_manager.js +26 -38
- package/script/client/2_business_connection_manager.js +10 -23
- package/script/client/2_client_encrypted.js +199 -216
- package/script/client/2_file_manager.js +255 -262
- package/script/client/2_network_statistics_manager.js +32 -45
- package/script/client/2_payment_manager.js +7 -20
- package/script/client/2_reaction_manager.js +7 -20
- package/script/client/2_translations_manager.js +102 -112
- package/script/client/2_update_manager.js +750 -745
- package/script/client/3_client_encrypted_pool.js +10 -26
- package/script/client/3_message_manager.js +503 -508
- package/script/client/3_video_chat_manager.js +57 -68
- package/script/client/4_callback_query_manager.js +18 -30
- package/script/client/4_chat_list_manager.js +140 -146
- package/script/client/4_chat_manager.js +161 -169
- package/script/client/4_checklist_manager.js +26 -39
- package/script/client/4_context.js +244 -259
- package/script/client/4_forum_manager.js +67 -73
- package/script/client/4_gift_manager.js +22 -35
- package/script/client/4_inline_query_manager.js +16 -28
- package/script/client/4_link_preview_manager.js +6 -19
- package/script/client/4_poll_manager.js +44 -57
- package/script/client/4_story_manager.js +41 -53
- package/script/client/5_composer.js +13 -26
- package/script/client/6_client.js +866 -896
- package/script/client/6_client_dispatcher.js +308 -325
- package/script/client/7_client_worker.js +16 -29
- package/script/connection/1_connection_tcp.js +55 -82
- package/script/connection/1_connection_web_socket.js +75 -91
- package/script/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
- package/script/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +31 -47
- package/script/deps/jsr.io/@std/async/1.2.0/tee.js +11 -34
- package/script/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +30 -47
- package/script/deps/jsr.io/@std/datetime/0.225.7/_date_time_formatter.js +4 -17
- package/script/session/0_session_state.js +12 -38
- package/script/session/1_session.js +49 -72
- package/script/session/2_session_encrypted.js +423 -421
- package/script/storage/2_storage_indexed_db.js +26 -44
- package/script/storage/2_storage_local_storage.js +3 -16
- package/script/storage/2_storage_memory.js +24 -41
- package/script/storage/2_storage_session_storage.js +3 -16
- package/script/tl/1_tl_reader.d.ts +1 -1
- package/script/tl/1_tl_reader.d.ts.map +1 -1
- package/script/tl/1_tl_reader.js +96 -104
- package/script/tl/1_tl_writer.js +170 -179
- package/script/transport/0_transport.js +1 -8
- package/script/transport/1_transport_abridged.js +11 -24
- package/script/transport/1_transport_intermediate.js +10 -23
- package/script/utilities/0_mutex.js +4 -19
- package/script/utilities/0_part_stream.js +11 -25
- package/script/utilities/1_crypto.js +43 -54
- package/script/utilities/2_queue.js +30 -48
|
@@ -18,18 +18,6 @@
|
|
|
18
18
|
* You should have received a copy of the GNU Lesser General Public License
|
|
19
19
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
20
|
*/
|
|
21
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
22
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
23
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
24
|
-
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");
|
|
25
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
26
|
-
};
|
|
27
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
28
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
29
|
-
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");
|
|
30
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
31
|
-
};
|
|
32
|
-
var _VideoChatManager_instances, _VideoChatManager_c, _VideoChatManager_createGroupCall, _VideoChatManager_getInputGroupCall, _VideoChatManager_getCall;
|
|
33
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
22
|
exports.VideoChatManager = void 0;
|
|
35
23
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
@@ -44,23 +32,43 @@ const videoChatManagerUpdates = [
|
|
|
44
32
|
"updateGroupCall",
|
|
45
33
|
];
|
|
46
34
|
class VideoChatManager {
|
|
35
|
+
#c;
|
|
47
36
|
constructor(c) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
37
|
+
this.#c = c;
|
|
38
|
+
}
|
|
39
|
+
async #createGroupCall(chatId, title, liveStream, scheduleDate) {
|
|
40
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
41
|
+
if ((0, _0_utilities_js_1.canBeInputUser)(peer)) {
|
|
42
|
+
throw new _0_errors_js_1.InputError("Video chats are only available for groups and channels.");
|
|
43
|
+
}
|
|
44
|
+
const { updates } = await this.#c.invoke({ _: "phone.createGroupCall", peer, random_id: (0, _1_utilities_js_1.getRandomId)(true), title, rtmp_stream: liveStream, schedule_date: scheduleDate }).then((v) => _2_tl_js_1.Api.as("updates", v));
|
|
45
|
+
const updateGroupCall = updates
|
|
46
|
+
.find((v) => _2_tl_js_1.Api.is("updateGroupCall", v));
|
|
47
|
+
if (!updateGroupCall) {
|
|
48
|
+
(0, _0_deps_js_1.unreachable)();
|
|
49
|
+
}
|
|
50
|
+
return (0, _3_types_js_1.constructVideoChat)(updateGroupCall.call);
|
|
51
51
|
}
|
|
52
52
|
async startVideoChat(chatId, params) {
|
|
53
|
-
|
|
54
|
-
return await
|
|
53
|
+
this.#c.storage.assertUser("startVideoChat");
|
|
54
|
+
return await this.#createGroupCall(chatId, params?.title, params?.isLiveStream || undefined);
|
|
55
55
|
}
|
|
56
56
|
async scheduleVideoChat(chatId, startAt, params) {
|
|
57
|
-
|
|
58
|
-
return await
|
|
57
|
+
this.#c.storage.assertUser("scheduleVideoChat");
|
|
58
|
+
return await this.#createGroupCall(chatId, params?.title, params?.isLiveStream || undefined, startAt);
|
|
59
|
+
}
|
|
60
|
+
async #getInputGroupCall(id_) {
|
|
61
|
+
const id = BigInt(id_);
|
|
62
|
+
const accessHash = await this.#c.messageStorage.getGroupCallAccessHash(id);
|
|
63
|
+
if (accessHash === null) {
|
|
64
|
+
throw new _0_errors_js_1.InputError("Video chat not found.");
|
|
65
|
+
}
|
|
66
|
+
return { _: "inputGroupCall", id, access_hash: accessHash };
|
|
59
67
|
}
|
|
60
68
|
async joinVideoChat(id, params, params_) {
|
|
61
|
-
|
|
62
|
-
const call = await
|
|
63
|
-
const { updates } = await
|
|
69
|
+
this.#c.storage.assertUser("joinVideoChat");
|
|
70
|
+
const call = await this.#getInputGroupCall(id);
|
|
71
|
+
const { updates } = await this.#c.invoke({ _: "phone.joinGroupCall", call, join_as: params_?.joinAs ? await this.#c.getInputPeer(params_.joinAs) : { _: "inputPeerSelf" }, params: { _: "dataJSON", data: params }, invite_hash: params_?.inviteHash, muted: params_?.isAudioEnabled ? undefined : true, video_stopped: params_?.isVideoEnabled ? undefined : true }).then((v) => _2_tl_js_1.Api.as("updates", v));
|
|
64
72
|
const updateGroupCall = updates
|
|
65
73
|
.find((v) => _2_tl_js_1.Api.is("updateGroupCallConnection", v));
|
|
66
74
|
if (!updateGroupCall)
|
|
@@ -68,13 +76,13 @@ class VideoChatManager {
|
|
|
68
76
|
return updateGroupCall.params.data;
|
|
69
77
|
}
|
|
70
78
|
async leaveVideoChat(id) {
|
|
71
|
-
|
|
72
|
-
await
|
|
79
|
+
this.#c.storage.assertUser("leaveVideoChat");
|
|
80
|
+
await this.#c.invoke({ _: "phone.leaveGroupCall", call: await this.#getInputGroupCall(id), source: 0 });
|
|
73
81
|
}
|
|
74
82
|
async joinLiveStream(id) {
|
|
75
|
-
|
|
76
|
-
const call = await
|
|
77
|
-
const { updates } = await
|
|
83
|
+
this.#c.storage.assertUser("joinLiveStream");
|
|
84
|
+
const call = await this.#getInputGroupCall(id);
|
|
85
|
+
const { updates } = await this.#c.invoke({
|
|
78
86
|
_: "phone.joinGroupCall",
|
|
79
87
|
call,
|
|
80
88
|
join_as: { _: "inputPeerSelf" },
|
|
@@ -94,9 +102,17 @@ class VideoChatManager {
|
|
|
94
102
|
if (!updateGroupCall)
|
|
95
103
|
(0, _0_deps_js_1.unreachable)();
|
|
96
104
|
}
|
|
105
|
+
async #getCall(id) {
|
|
106
|
+
let groupCall = await this.#c.messageStorage.getGroupCall(BigInt(id));
|
|
107
|
+
if (groupCall === null) {
|
|
108
|
+
const call = await this.#getInputGroupCall(id);
|
|
109
|
+
groupCall = (await this.#c.invoke({ _: "phone.getGroupCall", call, limit: 1 })).call;
|
|
110
|
+
}
|
|
111
|
+
return groupCall;
|
|
112
|
+
}
|
|
97
113
|
async getVideoChat(id) {
|
|
98
|
-
|
|
99
|
-
return (0, _3_types_js_1.constructVideoChat)(await
|
|
114
|
+
this.#c.storage.assertUser("getVideoChat");
|
|
115
|
+
return (0, _3_types_js_1.constructVideoChat)(await this.#getCall(id));
|
|
100
116
|
}
|
|
101
117
|
canHandleUpdate(update) {
|
|
102
118
|
return _2_tl_js_1.Api.isOneOf(videoChatManagerUpdates, update);
|
|
@@ -106,19 +122,19 @@ class VideoChatManager {
|
|
|
106
122
|
return null; // TODO: handle updates with unspecified chat_id
|
|
107
123
|
}
|
|
108
124
|
const chatId = (0, _2_telegram_js_1.peerToChatId)(update.peer);
|
|
109
|
-
const fullChat = await
|
|
125
|
+
const fullChat = await this.#c.messageStorage.getFullChat(chatId).then((v) => v === null ? this.#c.messageStorage.getFullChat(chatId) : v);
|
|
110
126
|
let updateFullChat = false;
|
|
111
127
|
if (_2_tl_js_1.Api.is("groupCallDiscarded", update.call)) {
|
|
112
|
-
await
|
|
113
|
-
await
|
|
128
|
+
await this.#c.messageStorage.setGroupCall(update.call.id, null);
|
|
129
|
+
await this.#c.messageStorage.setGroupCallAccessHash(update.call.id, null);
|
|
114
130
|
if (fullChat !== null) {
|
|
115
131
|
fullChat.call = undefined;
|
|
116
132
|
updateFullChat = true;
|
|
117
133
|
}
|
|
118
134
|
}
|
|
119
135
|
else {
|
|
120
|
-
await
|
|
121
|
-
await
|
|
136
|
+
await this.#c.messageStorage.setGroupCall(update.call.id, update.call);
|
|
137
|
+
await this.#c.messageStorage.setGroupCallAccessHash(update.call.id, update.call.access_hash);
|
|
122
138
|
if (fullChat !== null) {
|
|
123
139
|
if (!("call" in fullChat) || !fullChat.call || !_2_tl_js_1.Api.is("inputGroupCall", fullChat.call) || fullChat.call.id !== update.call.id) {
|
|
124
140
|
fullChat.call = { ...update.call, _: "inputGroupCall" };
|
|
@@ -127,23 +143,23 @@ class VideoChatManager {
|
|
|
127
143
|
}
|
|
128
144
|
}
|
|
129
145
|
if (updateFullChat) {
|
|
130
|
-
await
|
|
146
|
+
await this.#c.messageStorage.setFullChat(chatId, fullChat);
|
|
131
147
|
}
|
|
132
148
|
return { videoChat: (0, _3_types_js_1.constructVideoChat)(update.call) };
|
|
133
149
|
}
|
|
134
150
|
async getLiveStreamChannels(id) {
|
|
135
|
-
|
|
136
|
-
const call = await
|
|
151
|
+
this.#c.storage.assertUser("getLiveStreamChannels");
|
|
152
|
+
const call = await this.#getCall(id);
|
|
137
153
|
if (!(_2_tl_js_1.Api.is("groupCall", call)) || !call.rtmp_stream) {
|
|
138
154
|
throw new _0_errors_js_1.InputError("Not a live stream.");
|
|
139
155
|
}
|
|
140
156
|
const dc = call.stream_dc_id ? (0, _3_transport_js_1.getDc)(call.stream_dc_id) : undefined;
|
|
141
|
-
const streams = await
|
|
157
|
+
const streams = await this.#c.invoke({ _: "phone.getGroupCallStreamChannels", call: await this.#getInputGroupCall(id) }, { dc, type: "download" });
|
|
142
158
|
return streams.channels.map(_3_types_js_1.constructLiveStreamChannel);
|
|
143
159
|
}
|
|
144
160
|
async downloadLiveStreamSegment(id, channel, scale, timestamp, params) {
|
|
145
|
-
|
|
146
|
-
const call = await
|
|
161
|
+
this.#c.storage.assertUser("downloadLiveStreamSegment");
|
|
162
|
+
const call = await this.#getCall(id);
|
|
147
163
|
if (!(_2_tl_js_1.Api.is("groupCall", call)) || !call.rtmp_stream) {
|
|
148
164
|
throw new _0_errors_js_1.InputError("Not a live stream.");
|
|
149
165
|
}
|
|
@@ -159,37 +175,10 @@ class VideoChatManager {
|
|
|
159
175
|
})(),
|
|
160
176
|
};
|
|
161
177
|
const chunks = new Array();
|
|
162
|
-
for await (const chunk of
|
|
178
|
+
for await (const chunk of this.#c.fileManager.downloadInner(location, call.stream_dc_id ?? (0, _0_deps_js_1.unreachable)(), params)) {
|
|
163
179
|
chunks.push(chunk);
|
|
164
180
|
}
|
|
165
181
|
return (0, _0_deps_js_1.concat)(chunks);
|
|
166
182
|
}
|
|
167
183
|
}
|
|
168
184
|
exports.VideoChatManager = VideoChatManager;
|
|
169
|
-
_VideoChatManager_c = new WeakMap(), _VideoChatManager_instances = new WeakSet(), _VideoChatManager_createGroupCall = async function _VideoChatManager_createGroupCall(chatId, title, liveStream, scheduleDate) {
|
|
170
|
-
const peer = await __classPrivateFieldGet(this, _VideoChatManager_c, "f").getInputPeer(chatId);
|
|
171
|
-
if ((0, _0_utilities_js_1.canBeInputUser)(peer)) {
|
|
172
|
-
throw new _0_errors_js_1.InputError("Video chats are only available for groups and channels.");
|
|
173
|
-
}
|
|
174
|
-
const { updates } = await __classPrivateFieldGet(this, _VideoChatManager_c, "f").invoke({ _: "phone.createGroupCall", peer, random_id: (0, _1_utilities_js_1.getRandomId)(true), title, rtmp_stream: liveStream, schedule_date: scheduleDate }).then((v) => _2_tl_js_1.Api.as("updates", v));
|
|
175
|
-
const updateGroupCall = updates
|
|
176
|
-
.find((v) => _2_tl_js_1.Api.is("updateGroupCall", v));
|
|
177
|
-
if (!updateGroupCall) {
|
|
178
|
-
(0, _0_deps_js_1.unreachable)();
|
|
179
|
-
}
|
|
180
|
-
return (0, _3_types_js_1.constructVideoChat)(updateGroupCall.call);
|
|
181
|
-
}, _VideoChatManager_getInputGroupCall = async function _VideoChatManager_getInputGroupCall(id_) {
|
|
182
|
-
const id = BigInt(id_);
|
|
183
|
-
const accessHash = await __classPrivateFieldGet(this, _VideoChatManager_c, "f").messageStorage.getGroupCallAccessHash(id);
|
|
184
|
-
if (accessHash === null) {
|
|
185
|
-
throw new _0_errors_js_1.InputError("Video chat not found.");
|
|
186
|
-
}
|
|
187
|
-
return { _: "inputGroupCall", id, access_hash: accessHash };
|
|
188
|
-
}, _VideoChatManager_getCall = async function _VideoChatManager_getCall(id) {
|
|
189
|
-
let groupCall = await __classPrivateFieldGet(this, _VideoChatManager_c, "f").messageStorage.getGroupCall(BigInt(id));
|
|
190
|
-
if (groupCall === null) {
|
|
191
|
-
const call = await __classPrivateFieldGet(this, _VideoChatManager_instances, "m", _VideoChatManager_getInputGroupCall).call(this, id);
|
|
192
|
-
groupCall = (await __classPrivateFieldGet(this, _VideoChatManager_c, "f").invoke({ _: "phone.getGroupCall", call, limit: 1 })).call;
|
|
193
|
-
}
|
|
194
|
-
return groupCall;
|
|
195
|
-
};
|
|
@@ -18,18 +18,6 @@
|
|
|
18
18
|
* You should have received a copy of the GNU Lesser General Public License
|
|
19
19
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
20
|
*/
|
|
21
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
22
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
23
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
24
|
-
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");
|
|
25
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
26
|
-
};
|
|
27
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
28
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
29
|
-
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");
|
|
30
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
31
|
-
};
|
|
32
|
-
var _CallbackQueryManager_instances, _a, _CallbackQueryManager_c, _CallbackQueryManager_isExpired, _CallbackQueryManager_getPasswordCheck;
|
|
33
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
22
|
exports.CallbackQueryManager = void 0;
|
|
35
23
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
@@ -43,42 +31,42 @@ const callbackQueryManagerUpdates = [
|
|
|
43
31
|
"updateInlineBotCallbackQuery",
|
|
44
32
|
];
|
|
45
33
|
class CallbackQueryManager {
|
|
34
|
+
#c;
|
|
46
35
|
constructor(c) {
|
|
47
|
-
|
|
48
|
-
_CallbackQueryManager_c.set(this, void 0);
|
|
49
|
-
__classPrivateFieldSet(this, _CallbackQueryManager_c, c, "f");
|
|
36
|
+
this.#c = c;
|
|
50
37
|
}
|
|
51
38
|
async answerCallbackQuery(id, params) {
|
|
52
|
-
|
|
39
|
+
this.#c.storage.assertBot("answerCallbackQuery");
|
|
53
40
|
(0, _0_utilities_js_1.checkCallbackQueryId)(id);
|
|
54
|
-
await
|
|
41
|
+
await this.#c.invoke({ _: "messages.setBotCallbackAnswer", query_id: BigInt(id), cache_time: params?.cacheTime ?? 0, message: params?.text, alert: params?.isAlert ? true : undefined });
|
|
55
42
|
}
|
|
56
43
|
async sendCallbackQuery(botId, messageId, question) {
|
|
57
|
-
|
|
44
|
+
this.#c.storage.assertUser("sendCallbackQuery");
|
|
58
45
|
(0, _0_utilities_js_1.checkMessageId)(messageId);
|
|
59
46
|
(0, _3_types_js_1.validateCallbackQueryQuestion)(question);
|
|
60
|
-
const peer = await
|
|
61
|
-
const maybeAnswer = await
|
|
62
|
-
if (maybeAnswer !== null && !
|
|
47
|
+
const peer = await this.#c.getInputPeer(botId), peerId = await this.#c.getInputPeerChatId(peer), questionKey = JSON.stringify(question);
|
|
48
|
+
const maybeAnswer = await this.#c.messageStorage.getCallbackQueryAnswer(peerId, messageId, questionKey);
|
|
49
|
+
if (maybeAnswer !== null && !CallbackQueryManager.#isExpired(maybeAnswer[1], maybeAnswer[0].cache_time)) {
|
|
63
50
|
return (0, _3_types_js_1.constructCallbackQueryAnswer)(maybeAnswer[0]);
|
|
64
51
|
}
|
|
65
|
-
const answer = await
|
|
52
|
+
const answer = await this.#c.invoke({ _: "messages.getBotCallbackAnswer", peer, msg_id: messageId, data: "data" in question ? (0, _1_utilities_js_1.encodeText)(question.data) : undefined, game: question.type === "game" ? true : undefined, password: question.type === "password" ? await this.#getPasswordCheck(question.password) : undefined });
|
|
66
53
|
if (answer.cache_time >= 0) {
|
|
67
|
-
await
|
|
54
|
+
await this.#c.messageStorage.setCallbackQueryAnswer(peerId, messageId, questionKey, answer);
|
|
68
55
|
}
|
|
69
56
|
return (0, _3_types_js_1.constructCallbackQueryAnswer)(answer);
|
|
70
57
|
}
|
|
58
|
+
static #isExpired(date, cacheTime) {
|
|
59
|
+
return (Date.now() - date.getTime()) / _0_deps_js_1.SECOND > cacheTime;
|
|
60
|
+
}
|
|
61
|
+
async #getPasswordCheck(password) {
|
|
62
|
+
const ap = await this.#c.invoke({ _: "account.getPassword" });
|
|
63
|
+
return await (0, _0_password_js_1.checkPassword)(password, ap);
|
|
64
|
+
}
|
|
71
65
|
canHandleUpdate(update) {
|
|
72
66
|
return _2_tl_js_1.Api.isOneOf(callbackQueryManagerUpdates, update);
|
|
73
67
|
}
|
|
74
68
|
async handleUpdate(update) {
|
|
75
|
-
return { callbackQuery: await (0, _3_types_js_1.constructCallbackQuery)(update,
|
|
69
|
+
return { callbackQuery: await (0, _3_types_js_1.constructCallbackQuery)(update, this.#c.getPeer, this.#c.messageManager.getMessageWithReply.bind(this.#c.messageManager)) };
|
|
76
70
|
}
|
|
77
71
|
}
|
|
78
72
|
exports.CallbackQueryManager = CallbackQueryManager;
|
|
79
|
-
_a = CallbackQueryManager, _CallbackQueryManager_c = new WeakMap(), _CallbackQueryManager_instances = new WeakSet(), _CallbackQueryManager_isExpired = function _CallbackQueryManager_isExpired(date, cacheTime) {
|
|
80
|
-
return (Date.now() - date.getTime()) / _0_deps_js_1.SECOND > cacheTime;
|
|
81
|
-
}, _CallbackQueryManager_getPasswordCheck = async function _CallbackQueryManager_getPasswordCheck(password) {
|
|
82
|
-
const ap = await __classPrivateFieldGet(this, _CallbackQueryManager_c, "f").invoke({ _: "account.getPassword" });
|
|
83
|
-
return await (0, _0_password_js_1.checkPassword)(password, ap);
|
|
84
|
-
};
|