@mtkruto/browser 0.119.0 → 0.119.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
|
@@ -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 _VideoChatManager_instances, _VideoChatManager_c, _VideoChatManager_createGroupCall, _VideoChatManager_getInputGroupCall, _VideoChatManager_getCall;
|
|
32
20
|
import { concat, unreachable } from "../0_deps.js";
|
|
33
21
|
import { InputError } from "../0_errors.js";
|
|
34
22
|
import { getRandomId } from "../1_utilities.js";
|
|
@@ -41,23 +29,43 @@ const videoChatManagerUpdates = [
|
|
|
41
29
|
"updateGroupCall",
|
|
42
30
|
];
|
|
43
31
|
export class VideoChatManager {
|
|
32
|
+
#c;
|
|
44
33
|
constructor(c) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
34
|
+
this.#c = c;
|
|
35
|
+
}
|
|
36
|
+
async #createGroupCall(chatId, title, liveStream, scheduleDate) {
|
|
37
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
38
|
+
if (canBeInputUser(peer)) {
|
|
39
|
+
throw new InputError("Video chats are only available for groups and channels.");
|
|
40
|
+
}
|
|
41
|
+
const { updates } = await this.#c.invoke({ _: "phone.createGroupCall", peer, random_id: getRandomId(true), title, rtmp_stream: liveStream, schedule_date: scheduleDate }).then((v) => Api.as("updates", v));
|
|
42
|
+
const updateGroupCall = updates
|
|
43
|
+
.find((v) => Api.is("updateGroupCall", v));
|
|
44
|
+
if (!updateGroupCall) {
|
|
45
|
+
unreachable();
|
|
46
|
+
}
|
|
47
|
+
return constructVideoChat(updateGroupCall.call);
|
|
48
48
|
}
|
|
49
49
|
async startVideoChat(chatId, params) {
|
|
50
|
-
|
|
51
|
-
return await
|
|
50
|
+
this.#c.storage.assertUser("startVideoChat");
|
|
51
|
+
return await this.#createGroupCall(chatId, params?.title, params?.isLiveStream || undefined);
|
|
52
52
|
}
|
|
53
53
|
async scheduleVideoChat(chatId, startAt, params) {
|
|
54
|
-
|
|
55
|
-
return await
|
|
54
|
+
this.#c.storage.assertUser("scheduleVideoChat");
|
|
55
|
+
return await this.#createGroupCall(chatId, params?.title, params?.isLiveStream || undefined, startAt);
|
|
56
|
+
}
|
|
57
|
+
async #getInputGroupCall(id_) {
|
|
58
|
+
const id = BigInt(id_);
|
|
59
|
+
const accessHash = await this.#c.messageStorage.getGroupCallAccessHash(id);
|
|
60
|
+
if (accessHash === null) {
|
|
61
|
+
throw new InputError("Video chat not found.");
|
|
62
|
+
}
|
|
63
|
+
return { _: "inputGroupCall", id, access_hash: accessHash };
|
|
56
64
|
}
|
|
57
65
|
async joinVideoChat(id, params, params_) {
|
|
58
|
-
|
|
59
|
-
const call = await
|
|
60
|
-
const { updates } = await
|
|
66
|
+
this.#c.storage.assertUser("joinVideoChat");
|
|
67
|
+
const call = await this.#getInputGroupCall(id);
|
|
68
|
+
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) => Api.as("updates", v));
|
|
61
69
|
const updateGroupCall = updates
|
|
62
70
|
.find((v) => Api.is("updateGroupCallConnection", v));
|
|
63
71
|
if (!updateGroupCall)
|
|
@@ -65,13 +73,13 @@ export class VideoChatManager {
|
|
|
65
73
|
return updateGroupCall.params.data;
|
|
66
74
|
}
|
|
67
75
|
async leaveVideoChat(id) {
|
|
68
|
-
|
|
69
|
-
await
|
|
76
|
+
this.#c.storage.assertUser("leaveVideoChat");
|
|
77
|
+
await this.#c.invoke({ _: "phone.leaveGroupCall", call: await this.#getInputGroupCall(id), source: 0 });
|
|
70
78
|
}
|
|
71
79
|
async joinLiveStream(id) {
|
|
72
|
-
|
|
73
|
-
const call = await
|
|
74
|
-
const { updates } = await
|
|
80
|
+
this.#c.storage.assertUser("joinLiveStream");
|
|
81
|
+
const call = await this.#getInputGroupCall(id);
|
|
82
|
+
const { updates } = await this.#c.invoke({
|
|
75
83
|
_: "phone.joinGroupCall",
|
|
76
84
|
call,
|
|
77
85
|
join_as: { _: "inputPeerSelf" },
|
|
@@ -91,9 +99,17 @@ export class VideoChatManager {
|
|
|
91
99
|
if (!updateGroupCall)
|
|
92
100
|
unreachable();
|
|
93
101
|
}
|
|
102
|
+
async #getCall(id) {
|
|
103
|
+
let groupCall = await this.#c.messageStorage.getGroupCall(BigInt(id));
|
|
104
|
+
if (groupCall === null) {
|
|
105
|
+
const call = await this.#getInputGroupCall(id);
|
|
106
|
+
groupCall = (await this.#c.invoke({ _: "phone.getGroupCall", call, limit: 1 })).call;
|
|
107
|
+
}
|
|
108
|
+
return groupCall;
|
|
109
|
+
}
|
|
94
110
|
async getVideoChat(id) {
|
|
95
|
-
|
|
96
|
-
return constructVideoChat(await
|
|
111
|
+
this.#c.storage.assertUser("getVideoChat");
|
|
112
|
+
return constructVideoChat(await this.#getCall(id));
|
|
97
113
|
}
|
|
98
114
|
canHandleUpdate(update) {
|
|
99
115
|
return Api.isOneOf(videoChatManagerUpdates, update);
|
|
@@ -103,19 +119,19 @@ export class VideoChatManager {
|
|
|
103
119
|
return null; // TODO: handle updates with unspecified chat_id
|
|
104
120
|
}
|
|
105
121
|
const chatId = peerToChatId(update.peer);
|
|
106
|
-
const fullChat = await
|
|
122
|
+
const fullChat = await this.#c.messageStorage.getFullChat(chatId).then((v) => v === null ? this.#c.messageStorage.getFullChat(chatId) : v);
|
|
107
123
|
let updateFullChat = false;
|
|
108
124
|
if (Api.is("groupCallDiscarded", update.call)) {
|
|
109
|
-
await
|
|
110
|
-
await
|
|
125
|
+
await this.#c.messageStorage.setGroupCall(update.call.id, null);
|
|
126
|
+
await this.#c.messageStorage.setGroupCallAccessHash(update.call.id, null);
|
|
111
127
|
if (fullChat !== null) {
|
|
112
128
|
fullChat.call = undefined;
|
|
113
129
|
updateFullChat = true;
|
|
114
130
|
}
|
|
115
131
|
}
|
|
116
132
|
else {
|
|
117
|
-
await
|
|
118
|
-
await
|
|
133
|
+
await this.#c.messageStorage.setGroupCall(update.call.id, update.call);
|
|
134
|
+
await this.#c.messageStorage.setGroupCallAccessHash(update.call.id, update.call.access_hash);
|
|
119
135
|
if (fullChat !== null) {
|
|
120
136
|
if (!("call" in fullChat) || !fullChat.call || !Api.is("inputGroupCall", fullChat.call) || fullChat.call.id !== update.call.id) {
|
|
121
137
|
fullChat.call = { ...update.call, _: "inputGroupCall" };
|
|
@@ -124,23 +140,23 @@ export class VideoChatManager {
|
|
|
124
140
|
}
|
|
125
141
|
}
|
|
126
142
|
if (updateFullChat) {
|
|
127
|
-
await
|
|
143
|
+
await this.#c.messageStorage.setFullChat(chatId, fullChat);
|
|
128
144
|
}
|
|
129
145
|
return { videoChat: constructVideoChat(update.call) };
|
|
130
146
|
}
|
|
131
147
|
async getLiveStreamChannels(id) {
|
|
132
|
-
|
|
133
|
-
const call = await
|
|
148
|
+
this.#c.storage.assertUser("getLiveStreamChannels");
|
|
149
|
+
const call = await this.#getCall(id);
|
|
134
150
|
if (!(Api.is("groupCall", call)) || !call.rtmp_stream) {
|
|
135
151
|
throw new InputError("Not a live stream.");
|
|
136
152
|
}
|
|
137
153
|
const dc = call.stream_dc_id ? getDc(call.stream_dc_id) : undefined;
|
|
138
|
-
const streams = await
|
|
154
|
+
const streams = await this.#c.invoke({ _: "phone.getGroupCallStreamChannels", call: await this.#getInputGroupCall(id) }, { dc, type: "download" });
|
|
139
155
|
return streams.channels.map(constructLiveStreamChannel);
|
|
140
156
|
}
|
|
141
157
|
async downloadLiveStreamSegment(id, channel, scale, timestamp, params) {
|
|
142
|
-
|
|
143
|
-
const call = await
|
|
158
|
+
this.#c.storage.assertUser("downloadLiveStreamSegment");
|
|
159
|
+
const call = await this.#getCall(id);
|
|
144
160
|
if (!(Api.is("groupCall", call)) || !call.rtmp_stream) {
|
|
145
161
|
throw new InputError("Not a live stream.");
|
|
146
162
|
}
|
|
@@ -156,36 +172,9 @@ export class VideoChatManager {
|
|
|
156
172
|
})(),
|
|
157
173
|
};
|
|
158
174
|
const chunks = new Array();
|
|
159
|
-
for await (const chunk of
|
|
175
|
+
for await (const chunk of this.#c.fileManager.downloadInner(location, call.stream_dc_id ?? unreachable(), params)) {
|
|
160
176
|
chunks.push(chunk);
|
|
161
177
|
}
|
|
162
178
|
return concat(chunks);
|
|
163
179
|
}
|
|
164
180
|
}
|
|
165
|
-
_VideoChatManager_c = new WeakMap(), _VideoChatManager_instances = new WeakSet(), _VideoChatManager_createGroupCall = async function _VideoChatManager_createGroupCall(chatId, title, liveStream, scheduleDate) {
|
|
166
|
-
const peer = await __classPrivateFieldGet(this, _VideoChatManager_c, "f").getInputPeer(chatId);
|
|
167
|
-
if (canBeInputUser(peer)) {
|
|
168
|
-
throw new InputError("Video chats are only available for groups and channels.");
|
|
169
|
-
}
|
|
170
|
-
const { updates } = await __classPrivateFieldGet(this, _VideoChatManager_c, "f").invoke({ _: "phone.createGroupCall", peer, random_id: getRandomId(true), title, rtmp_stream: liveStream, schedule_date: scheduleDate }).then((v) => Api.as("updates", v));
|
|
171
|
-
const updateGroupCall = updates
|
|
172
|
-
.find((v) => Api.is("updateGroupCall", v));
|
|
173
|
-
if (!updateGroupCall) {
|
|
174
|
-
unreachable();
|
|
175
|
-
}
|
|
176
|
-
return constructVideoChat(updateGroupCall.call);
|
|
177
|
-
}, _VideoChatManager_getInputGroupCall = async function _VideoChatManager_getInputGroupCall(id_) {
|
|
178
|
-
const id = BigInt(id_);
|
|
179
|
-
const accessHash = await __classPrivateFieldGet(this, _VideoChatManager_c, "f").messageStorage.getGroupCallAccessHash(id);
|
|
180
|
-
if (accessHash === null) {
|
|
181
|
-
throw new InputError("Video chat not found.");
|
|
182
|
-
}
|
|
183
|
-
return { _: "inputGroupCall", id, access_hash: accessHash };
|
|
184
|
-
}, _VideoChatManager_getCall = async function _VideoChatManager_getCall(id) {
|
|
185
|
-
let groupCall = await __classPrivateFieldGet(this, _VideoChatManager_c, "f").messageStorage.getGroupCall(BigInt(id));
|
|
186
|
-
if (groupCall === null) {
|
|
187
|
-
const call = await __classPrivateFieldGet(this, _VideoChatManager_instances, "m", _VideoChatManager_getInputGroupCall).call(this, id);
|
|
188
|
-
groupCall = (await __classPrivateFieldGet(this, _VideoChatManager_c, "f").invoke({ _: "phone.getGroupCall", call, limit: 1 })).call;
|
|
189
|
-
}
|
|
190
|
-
return groupCall;
|
|
191
|
-
};
|
|
@@ -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 _CallbackQueryManager_instances, _a, _CallbackQueryManager_c, _CallbackQueryManager_isExpired, _CallbackQueryManager_getPasswordCheck;
|
|
32
20
|
import { SECOND } from "../0_deps.js";
|
|
33
21
|
import { encodeText } from "../1_utilities.js";
|
|
34
22
|
import { Api } from "../2_tl.js";
|
|
@@ -40,41 +28,41 @@ const callbackQueryManagerUpdates = [
|
|
|
40
28
|
"updateInlineBotCallbackQuery",
|
|
41
29
|
];
|
|
42
30
|
export class CallbackQueryManager {
|
|
31
|
+
#c;
|
|
43
32
|
constructor(c) {
|
|
44
|
-
|
|
45
|
-
_CallbackQueryManager_c.set(this, void 0);
|
|
46
|
-
__classPrivateFieldSet(this, _CallbackQueryManager_c, c, "f");
|
|
33
|
+
this.#c = c;
|
|
47
34
|
}
|
|
48
35
|
async answerCallbackQuery(id, params) {
|
|
49
|
-
|
|
36
|
+
this.#c.storage.assertBot("answerCallbackQuery");
|
|
50
37
|
checkCallbackQueryId(id);
|
|
51
|
-
await
|
|
38
|
+
await this.#c.invoke({ _: "messages.setBotCallbackAnswer", query_id: BigInt(id), cache_time: params?.cacheTime ?? 0, message: params?.text, alert: params?.isAlert ? true : undefined });
|
|
52
39
|
}
|
|
53
40
|
async sendCallbackQuery(botId, messageId, question) {
|
|
54
|
-
|
|
41
|
+
this.#c.storage.assertUser("sendCallbackQuery");
|
|
55
42
|
checkMessageId(messageId);
|
|
56
43
|
validateCallbackQueryQuestion(question);
|
|
57
|
-
const peer = await
|
|
58
|
-
const maybeAnswer = await
|
|
59
|
-
if (maybeAnswer !== null && !
|
|
44
|
+
const peer = await this.#c.getInputPeer(botId), peerId = await this.#c.getInputPeerChatId(peer), questionKey = JSON.stringify(question);
|
|
45
|
+
const maybeAnswer = await this.#c.messageStorage.getCallbackQueryAnswer(peerId, messageId, questionKey);
|
|
46
|
+
if (maybeAnswer !== null && !CallbackQueryManager.#isExpired(maybeAnswer[1], maybeAnswer[0].cache_time)) {
|
|
60
47
|
return constructCallbackQueryAnswer(maybeAnswer[0]);
|
|
61
48
|
}
|
|
62
|
-
const answer = await
|
|
49
|
+
const answer = await this.#c.invoke({ _: "messages.getBotCallbackAnswer", peer, msg_id: messageId, data: "data" in question ? encodeText(question.data) : undefined, game: question.type === "game" ? true : undefined, password: question.type === "password" ? await this.#getPasswordCheck(question.password) : undefined });
|
|
63
50
|
if (answer.cache_time >= 0) {
|
|
64
|
-
await
|
|
51
|
+
await this.#c.messageStorage.setCallbackQueryAnswer(peerId, messageId, questionKey, answer);
|
|
65
52
|
}
|
|
66
53
|
return constructCallbackQueryAnswer(answer);
|
|
67
54
|
}
|
|
55
|
+
static #isExpired(date, cacheTime) {
|
|
56
|
+
return (Date.now() - date.getTime()) / SECOND > cacheTime;
|
|
57
|
+
}
|
|
58
|
+
async #getPasswordCheck(password) {
|
|
59
|
+
const ap = await this.#c.invoke({ _: "account.getPassword" });
|
|
60
|
+
return await checkPassword(password, ap);
|
|
61
|
+
}
|
|
68
62
|
canHandleUpdate(update) {
|
|
69
63
|
return Api.isOneOf(callbackQueryManagerUpdates, update);
|
|
70
64
|
}
|
|
71
65
|
async handleUpdate(update) {
|
|
72
|
-
return { callbackQuery: await constructCallbackQuery(update,
|
|
66
|
+
return { callbackQuery: await constructCallbackQuery(update, this.#c.getPeer, this.#c.messageManager.getMessageWithReply.bind(this.#c.messageManager)) };
|
|
73
67
|
}
|
|
74
68
|
}
|
|
75
|
-
_a = CallbackQueryManager, _CallbackQueryManager_c = new WeakMap(), _CallbackQueryManager_instances = new WeakSet(), _CallbackQueryManager_isExpired = function _CallbackQueryManager_isExpired(date, cacheTime) {
|
|
76
|
-
return (Date.now() - date.getTime()) / SECOND > cacheTime;
|
|
77
|
-
}, _CallbackQueryManager_getPasswordCheck = async function _CallbackQueryManager_getPasswordCheck(password) {
|
|
78
|
-
const ap = await __classPrivateFieldGet(this, _CallbackQueryManager_c, "f").invoke({ _: "account.getPassword" });
|
|
79
|
-
return await checkPassword(password, ap);
|
|
80
|
-
};
|