@mtkruto/node 0.1.600 → 0.1.700
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/4_errors.js +2 -4
- package/esm/5_client.d.ts +1 -1
- package/esm/5_client.js +1 -1
- package/esm/client/0_params.d.ts +5 -1
- package/esm/client/0_storage_operations.d.ts +182 -0
- package/esm/client/0_storage_operations.js +611 -0
- package/esm/client/1_composer.d.ts +2 -0
- package/esm/client/1_composer.js +28 -0
- package/{script/client/0_types.d.ts → esm/client/1_types.d.ts} +3 -3
- package/{script/client/1_account_manager.d.ts → esm/client/2_account_manager.d.ts} +1 -1
- package/{script/client/1_bot_info_manager.d.ts → esm/client/2_bot_info_manager.d.ts} +1 -1
- package/esm/client/{1_business_connection_manager.d.ts → 2_business_connection_manager.d.ts} +1 -1
- package/{script/client/1_file_manager.d.ts → esm/client/2_file_manager.d.ts} +1 -1
- package/esm/client/{1_file_manager.js → 2_file_manager.js} +5 -3
- package/esm/client/{1_network_statistics_manager.d.ts → 2_network_statistics_manager.d.ts} +1 -1
- package/{script/client/1_reaction_manager.d.ts → esm/client/2_reaction_manager.d.ts} +1 -1
- package/{script/client/1_update_manager.d.ts → esm/client/2_update_manager.d.ts} +1 -1
- package/{script/client/2_message_manager.d.ts → esm/client/3_message_manager.d.ts} +2 -2
- package/esm/client/{2_video_chat_manager.d.ts → 3_video_chat_manager.d.ts} +2 -2
- package/{script/client/3_callback_query_manager.d.ts → esm/client/4_callback_query_manager.d.ts} +2 -2
- package/{script/client/3_chat_list_manager.d.ts → esm/client/4_chat_list_manager.d.ts} +3 -3
- package/{script/client/3_inline_query_manager.d.ts → esm/client/4_inline_query_manager.d.ts} +2 -2
- package/esm/client/{3_story_manager.d.ts → 4_story_manager.d.ts} +3 -3
- package/{script/client/4_client.d.ts → esm/client/5_client.d.ts} +39 -29
- package/esm/client/{4_client.js → 5_client.js} +83 -73
- package/esm/connection/0_connection.d.ts +6 -15
- package/esm/connection/0_connection.js +1 -38
- package/esm/connection/1_connection_web_socket.d.ts +3 -2
- package/esm/connection/1_connection_web_socket.js +7 -3
- package/esm/mod.d.ts +1 -1
- package/esm/mod.js +1 -1
- package/esm/storage/0_storage.d.ts +9 -159
- package/esm/storage/0_storage.js +1 -563
- package/esm/storage/2_storage_indexed_db.d.ts +3 -2
- package/esm/storage/2_storage_indexed_db.js +9 -8
- package/esm/storage/2_storage_local_storage.d.ts +3 -2
- package/esm/storage/2_storage_local_storage.js +5 -4
- package/esm/storage/2_storage_memory.d.ts +4 -4
- package/esm/storage/2_storage_memory.js +12 -19
- package/esm/storage/2_storage_session_storage.d.ts +2 -1
- package/esm/storage/2_storage_session_storage.js +5 -4
- package/esm/types/0_id.d.ts +1 -1
- package/package.json +1 -1
- package/script/4_errors.js +2 -4
- package/script/5_client.d.ts +1 -1
- package/script/5_client.js +1 -1
- package/script/client/0_params.d.ts +5 -1
- package/script/client/0_storage_operations.d.ts +182 -0
- package/script/client/0_storage_operations.js +615 -0
- package/script/client/1_composer.d.ts +2 -0
- package/script/client/1_composer.js +28 -0
- package/{esm/client/0_types.d.ts → script/client/1_types.d.ts} +3 -3
- package/{esm/client/1_account_manager.d.ts → script/client/2_account_manager.d.ts} +1 -1
- package/{esm/client/1_bot_info_manager.d.ts → script/client/2_bot_info_manager.d.ts} +1 -1
- package/script/client/{1_business_connection_manager.d.ts → 2_business_connection_manager.d.ts} +1 -1
- package/{esm/client/1_file_manager.d.ts → script/client/2_file_manager.d.ts} +1 -1
- package/script/client/{1_file_manager.js → 2_file_manager.js} +4 -2
- package/script/client/{1_network_statistics_manager.d.ts → 2_network_statistics_manager.d.ts} +1 -1
- package/{esm/client/1_reaction_manager.d.ts → script/client/2_reaction_manager.d.ts} +1 -1
- package/{esm/client/1_update_manager.d.ts → script/client/2_update_manager.d.ts} +1 -1
- package/{esm/client/2_message_manager.d.ts → script/client/3_message_manager.d.ts} +2 -2
- package/script/client/{2_video_chat_manager.d.ts → 3_video_chat_manager.d.ts} +2 -2
- package/{esm/client/3_callback_query_manager.d.ts → script/client/4_callback_query_manager.d.ts} +2 -2
- package/{esm/client/3_chat_list_manager.d.ts → script/client/4_chat_list_manager.d.ts} +3 -3
- package/{esm/client/3_inline_query_manager.d.ts → script/client/4_inline_query_manager.d.ts} +2 -2
- package/script/client/{3_story_manager.d.ts → 4_story_manager.d.ts} +3 -3
- package/{esm/client/4_client.d.ts → script/client/5_client.d.ts} +39 -29
- package/script/client/{4_client.js → 5_client.js} +105 -95
- package/script/connection/0_connection.d.ts +6 -15
- package/script/connection/0_connection.js +0 -41
- package/script/connection/1_connection_web_socket.d.ts +3 -2
- package/script/connection/1_connection_web_socket.js +7 -3
- package/script/mod.d.ts +1 -1
- package/script/mod.js +1 -1
- package/script/storage/0_storage.d.ts +9 -159
- package/script/storage/0_storage.js +0 -565
- package/script/storage/2_storage_indexed_db.d.ts +3 -2
- package/script/storage/2_storage_indexed_db.js +9 -8
- package/script/storage/2_storage_local_storage.d.ts +3 -2
- package/script/storage/2_storage_local_storage.js +5 -4
- package/script/storage/2_storage_memory.d.ts +4 -4
- package/script/storage/2_storage_memory.js +12 -19
- package/script/storage/2_storage_session_storage.d.ts +2 -1
- package/script/storage/2_storage_session_storage.js +5 -4
- package/script/types/0_id.d.ts +1 -1
- /package/esm/{3_storage.d.ts → 2_storage.d.ts} +0 -0
- /package/esm/{3_storage.js → 2_storage.js} +0 -0
- /package/esm/client/{0_types.js → 1_types.js} +0 -0
- /package/esm/client/{1_account_manager.js → 2_account_manager.js} +0 -0
- /package/esm/client/{1_bot_info_manager.js → 2_bot_info_manager.js} +0 -0
- /package/esm/client/{1_business_connection_manager.js → 2_business_connection_manager.js} +0 -0
- /package/esm/client/{1_network_statistics_manager.js → 2_network_statistics_manager.js} +0 -0
- /package/esm/client/{1_reaction_manager.js → 2_reaction_manager.js} +0 -0
- /package/esm/client/{1_update_manager.js → 2_update_manager.js} +0 -0
- /package/esm/client/{2_message_manager.js → 3_message_manager.js} +0 -0
- /package/esm/client/{2_video_chat_manager.js → 3_video_chat_manager.js} +0 -0
- /package/esm/client/{3_callback_query_manager.js → 4_callback_query_manager.js} +0 -0
- /package/esm/client/{3_chat_list_manager.js → 4_chat_list_manager.js} +0 -0
- /package/esm/client/{3_inline_query_manager.js → 4_inline_query_manager.js} +0 -0
- /package/esm/client/{3_story_manager.js → 4_story_manager.js} +0 -0
- /package/script/{3_storage.d.ts → 2_storage.d.ts} +0 -0
- /package/script/{3_storage.js → 2_storage.js} +0 -0
- /package/script/client/{0_types.js → 1_types.js} +0 -0
- /package/script/client/{1_account_manager.js → 2_account_manager.js} +0 -0
- /package/script/client/{1_bot_info_manager.js → 2_bot_info_manager.js} +0 -0
- /package/script/client/{1_business_connection_manager.js → 2_business_connection_manager.js} +0 -0
- /package/script/client/{1_network_statistics_manager.js → 2_network_statistics_manager.js} +0 -0
- /package/script/client/{1_reaction_manager.js → 2_reaction_manager.js} +0 -0
- /package/script/client/{1_update_manager.js → 2_update_manager.js} +0 -0
- /package/script/client/{2_message_manager.js → 3_message_manager.js} +0 -0
- /package/script/client/{2_video_chat_manager.js → 3_video_chat_manager.js} +0 -0
- /package/script/client/{3_callback_query_manager.js → 4_callback_query_manager.js} +0 -0
- /package/script/client/{3_chat_list_manager.js → 4_chat_list_manager.js} +0 -0
- /package/script/client/{3_inline_query_manager.js → 4_inline_query_manager.js} +0 -0
- /package/script/client/{3_story_manager.js → 4_story_manager.js} +0 -0
|
@@ -0,0 +1,611 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MTKruto - Cross-runtime JavaScript library for building Telegram clients
|
|
3
|
+
* Copyright (C) 2023-2024 Roj <https://roj.im/>
|
|
4
|
+
*
|
|
5
|
+
* This file is part of MTKruto.
|
|
6
|
+
*
|
|
7
|
+
* This program is free software: you can redistribute it and/or modify
|
|
8
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
9
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
* (at your option) any later version.
|
|
11
|
+
*
|
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
* GNU Lesser General Public License for more details.
|
|
16
|
+
*
|
|
17
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
18
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
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 _StorageOperations_instances, _StorageOperations_storage, _StorageOperations_supportsFiles, _StorageOperations_mustSerialize, _StorageOperations_authKeyId, _StorageOperations_resetAuthKeyId, _StorageOperations_accountId, _StorageOperations_accountType, _StorageOperations_getUpdateId;
|
|
32
|
+
import { AssertionError, unreachable } from "../0_deps.js";
|
|
33
|
+
import { InputError } from "../0_errors.js";
|
|
34
|
+
import { base64DecodeUrlSafe, base64EncodeUrlSafe, bigIntFromBuffer, rleDecode, rleEncode, sha1, ZERO_CHANNEL_ID } from "../1_utilities.js";
|
|
35
|
+
import { peerToChatId, serialize, TLObject, TLReader, TLWriter, types } from "../2_tl.js";
|
|
36
|
+
// key parts
|
|
37
|
+
export const K = {
|
|
38
|
+
connection: {
|
|
39
|
+
P: (string) => `connection.${string}`,
|
|
40
|
+
apiId: () => [K.connection.P("apiId")],
|
|
41
|
+
},
|
|
42
|
+
session: {
|
|
43
|
+
P: (string) => `session.${string}`,
|
|
44
|
+
serverSalt: () => [K.session.P("serverSalt")],
|
|
45
|
+
},
|
|
46
|
+
auth: {
|
|
47
|
+
P: (string) => `auth.${string}`,
|
|
48
|
+
dc: () => [K.auth.P("dc")],
|
|
49
|
+
key: () => [K.auth.P("key")],
|
|
50
|
+
accountId: () => [K.auth.P("accountId")],
|
|
51
|
+
accountType: () => [K.auth.P("accountType")],
|
|
52
|
+
},
|
|
53
|
+
updates: {
|
|
54
|
+
P: (string) => `updates.${string}`,
|
|
55
|
+
state: () => [K.updates.P("state")],
|
|
56
|
+
all: () => [K.updates.P("updates")],
|
|
57
|
+
updates: (boxId) => [...K.updates.all(), boxId],
|
|
58
|
+
update: (boxId, id) => [...K.updates.updates(boxId), id],
|
|
59
|
+
channelPts: (channelId) => [K.updates.P("channelPts"), channelId],
|
|
60
|
+
},
|
|
61
|
+
cache: {
|
|
62
|
+
P: (string) => `cache.${string}`,
|
|
63
|
+
usernames: () => [K.cache.P("username")],
|
|
64
|
+
username: (v) => [...K.cache.usernames(), v],
|
|
65
|
+
peers: () => [K.cache.P("peer")],
|
|
66
|
+
peer: (id) => [...K.cache.peers(), id],
|
|
67
|
+
stickerSetNames: () => [K.cache.P("stickerSetNames")],
|
|
68
|
+
stickerSetName: (id, accessHash) => [...K.cache.stickerSetNames(), id, accessHash],
|
|
69
|
+
files: () => [K.cache.P("files")],
|
|
70
|
+
file: (fileId) => [...K.cache.files(), fileId],
|
|
71
|
+
fileParts: () => [K.cache.P("fileParts")],
|
|
72
|
+
filePart: (fileId, n) => [...K.cache.fileParts(), fileId, n],
|
|
73
|
+
customEmojiDocuments: () => [K.cache.P("customEmojiDocuments")],
|
|
74
|
+
customEmojiDocument: (id) => [...K.cache.customEmojiDocuments(), id],
|
|
75
|
+
businessConnections: () => [K.cache.P("businessConnections")],
|
|
76
|
+
businessConnection: (id) => [...K.cache.businessConnections(), id],
|
|
77
|
+
inlineQueryAnswers: () => [K.cache.P("inlineQueryResults")],
|
|
78
|
+
inlineQueryAnswer: (userId, chatId, query, offset) => [...K.cache.inlineQueryAnswers(), userId, chatId, query, offset],
|
|
79
|
+
callbackQueryAnswers: () => [K.cache.P("callbackQueryAnswers")],
|
|
80
|
+
callbackQueryAnswer: (chatId, messageId, question) => [...K.cache.callbackQueryAnswers(), chatId, messageId, question],
|
|
81
|
+
fullChats: () => [K.cache.P("fullChats")],
|
|
82
|
+
fullChat: (chatId) => [...K.cache.fullChats(), chatId],
|
|
83
|
+
groupCalls: () => [K.cache.P("groupCalls")],
|
|
84
|
+
groupCall: (id) => [...K.cache.groupCalls(), id],
|
|
85
|
+
groupCallAccessHashes: () => [K.cache.P("groupCallAccessHashes")],
|
|
86
|
+
groupCallAccessHash: (id) => [...K.cache.groupCallAccessHashes(), id],
|
|
87
|
+
},
|
|
88
|
+
messages: {
|
|
89
|
+
P: (string) => `messages.${string}`,
|
|
90
|
+
messages: (chatId) => [K.messages.P("messages"), chatId],
|
|
91
|
+
message: (chatId, messageId) => [...K.messages.messages(chatId), messageId],
|
|
92
|
+
allMessageRefs: () => [K.messages.P("messageRefs")],
|
|
93
|
+
messageRef: (messageId) => [...K.messages.allMessageRefs(), messageId],
|
|
94
|
+
},
|
|
95
|
+
chatlists: {
|
|
96
|
+
P: (string) => `chatlists.${string}`,
|
|
97
|
+
hasAllChats: (listId) => [K.chatlists.P("hasAllChats"), listId],
|
|
98
|
+
chats: (listId) => [K.chatlists.P("chats"), listId],
|
|
99
|
+
chat: (listId, chatId) => [...K.chatlists.chats(listId), chatId],
|
|
100
|
+
pinnedChats: (listId) => [K.chatlists.P("pinnedChats"), listId],
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
export class StorageOperations {
|
|
104
|
+
constructor(storage) {
|
|
105
|
+
_StorageOperations_instances.add(this);
|
|
106
|
+
_StorageOperations_storage.set(this, void 0);
|
|
107
|
+
_StorageOperations_supportsFiles.set(this, void 0);
|
|
108
|
+
_StorageOperations_mustSerialize.set(this, void 0);
|
|
109
|
+
_StorageOperations_authKeyId.set(this, null);
|
|
110
|
+
_StorageOperations_accountId.set(this, null);
|
|
111
|
+
_StorageOperations_accountType.set(this, null);
|
|
112
|
+
__classPrivateFieldSet(this, _StorageOperations_storage, storage, "f");
|
|
113
|
+
__classPrivateFieldSet(this, _StorageOperations_supportsFiles, storage.supportsFiles, "f");
|
|
114
|
+
__classPrivateFieldSet(this, _StorageOperations_mustSerialize, storage.mustSerialize, "f");
|
|
115
|
+
}
|
|
116
|
+
get provider() {
|
|
117
|
+
return __classPrivateFieldGet(this, _StorageOperations_storage, "f");
|
|
118
|
+
}
|
|
119
|
+
get supportsFiles() {
|
|
120
|
+
return __classPrivateFieldGet(this, _StorageOperations_storage, "f").supportsFiles;
|
|
121
|
+
}
|
|
122
|
+
async initialize() {
|
|
123
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").initialize();
|
|
124
|
+
}
|
|
125
|
+
set(...args) {
|
|
126
|
+
return __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(...args);
|
|
127
|
+
}
|
|
128
|
+
incr(...args) {
|
|
129
|
+
return __classPrivateFieldGet(this, _StorageOperations_storage, "f").incr(...args);
|
|
130
|
+
}
|
|
131
|
+
get(...args) {
|
|
132
|
+
return __classPrivateFieldGet(this, _StorageOperations_storage, "f").get(...args);
|
|
133
|
+
}
|
|
134
|
+
getMany(...args) {
|
|
135
|
+
return __classPrivateFieldGet(this, _StorageOperations_storage, "f").getMany(...args);
|
|
136
|
+
}
|
|
137
|
+
async setDc(dc) {
|
|
138
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(K.auth.dc(), dc);
|
|
139
|
+
}
|
|
140
|
+
getDc() {
|
|
141
|
+
return __classPrivateFieldGet(this, _StorageOperations_storage, "f").get(K.auth.dc());
|
|
142
|
+
}
|
|
143
|
+
async getAuthKey() {
|
|
144
|
+
const authKey = await __classPrivateFieldGet(this, _StorageOperations_storage, "f").get(K.auth.key());
|
|
145
|
+
await __classPrivateFieldGet(this, _StorageOperations_instances, "m", _StorageOperations_resetAuthKeyId).call(this, authKey);
|
|
146
|
+
return authKey;
|
|
147
|
+
}
|
|
148
|
+
async setAuthKey(authKey) {
|
|
149
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(K.auth.key(), authKey);
|
|
150
|
+
await __classPrivateFieldGet(this, _StorageOperations_instances, "m", _StorageOperations_resetAuthKeyId).call(this, authKey);
|
|
151
|
+
}
|
|
152
|
+
get authKeyId() {
|
|
153
|
+
return __classPrivateFieldGet(this, _StorageOperations_authKeyId, "f");
|
|
154
|
+
}
|
|
155
|
+
async exportAuthString(apiId_) {
|
|
156
|
+
if (typeof apiId_ === "number") {
|
|
157
|
+
await this.setApiId(apiId_);
|
|
158
|
+
}
|
|
159
|
+
const [dc, authKey, apiId, accountId, accountType] = await Promise.all([this.getDc(), this.getAuthKey(), this.getApiId(), this.getAccountId(), this.getAccountType()]);
|
|
160
|
+
if (dc == null || authKey == null || apiId == null || accountId == null || accountType == null) {
|
|
161
|
+
throw new Error("Not authorized");
|
|
162
|
+
}
|
|
163
|
+
const writer = new TLWriter();
|
|
164
|
+
writer.writeString(dc);
|
|
165
|
+
writer.writeBytes(authKey);
|
|
166
|
+
writer.writeInt32(apiId);
|
|
167
|
+
writer.write(new Uint8Array([accountType == "bot" ? 1 : 0]));
|
|
168
|
+
writer.writeInt64(BigInt(accountId));
|
|
169
|
+
const data = rleEncode(writer.buffer);
|
|
170
|
+
return base64EncodeUrlSafe(data);
|
|
171
|
+
}
|
|
172
|
+
async importAuthString(string) {
|
|
173
|
+
const data = rleDecode(base64DecodeUrlSafe(string));
|
|
174
|
+
const reader = new TLReader(data);
|
|
175
|
+
const dc = reader.readString();
|
|
176
|
+
const authKey = reader.readBytes();
|
|
177
|
+
const apiId = reader.readInt32();
|
|
178
|
+
const isBot = reader.read(1)[0];
|
|
179
|
+
const accountId = Number(reader.readInt64());
|
|
180
|
+
await this.setAccountId(accountId);
|
|
181
|
+
await this.setAccountType(isBot ? "bot" : "user");
|
|
182
|
+
await this.setApiId(apiId);
|
|
183
|
+
await this.setDc(dc);
|
|
184
|
+
await this.setAuthKey(authKey);
|
|
185
|
+
}
|
|
186
|
+
async getChannelAccessHash(id) {
|
|
187
|
+
const channel = await this.getEntity(id);
|
|
188
|
+
if (channel) {
|
|
189
|
+
if (!(channel instanceof types.Channel) && !(channel instanceof types.ChannelForbidden)) {
|
|
190
|
+
unreachable();
|
|
191
|
+
}
|
|
192
|
+
return typeof channel.access_hash === "bigint" ? channel.access_hash : null;
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
async getUserAccessHash(id) {
|
|
199
|
+
const user = await this.getEntity(id);
|
|
200
|
+
if (user) {
|
|
201
|
+
if (!(user instanceof types.User)) {
|
|
202
|
+
unreachable();
|
|
203
|
+
}
|
|
204
|
+
return typeof user.access_hash === "bigint" ? user.access_hash : null;
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
async updateUsernames(id, usernames) {
|
|
211
|
+
for (let username of usernames) {
|
|
212
|
+
username = username.toLowerCase();
|
|
213
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(K.cache.username(username), [id, new Date()]);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
async getUsername(username) {
|
|
217
|
+
username = username.toLowerCase();
|
|
218
|
+
return await __classPrivateFieldGet(this, _StorageOperations_storage, "f").get(K.cache.username(username));
|
|
219
|
+
}
|
|
220
|
+
async setTlObject(key, value) {
|
|
221
|
+
if (value == null) {
|
|
222
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(key, null);
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(key, __classPrivateFieldGet(this, _StorageOperations_mustSerialize, "f") ? rleEncode(value[serialize]()) : value);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
async getTlObject(keyOrBuffer) {
|
|
229
|
+
const buffer = (keyOrBuffer instanceof Uint8Array || keyOrBuffer instanceof TLObject) ? keyOrBuffer : await __classPrivateFieldGet(this, _StorageOperations_storage, "f").get(keyOrBuffer);
|
|
230
|
+
if (buffer != null) {
|
|
231
|
+
if (buffer instanceof Uint8Array) {
|
|
232
|
+
return new TLReader(rleDecode(buffer)).readObject();
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
return buffer;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
async setState(state) {
|
|
243
|
+
await this.setTlObject(K.updates.state(), state);
|
|
244
|
+
}
|
|
245
|
+
async getState() {
|
|
246
|
+
return await this.getTlObject(K.updates.state());
|
|
247
|
+
}
|
|
248
|
+
async setMessage(chatId, messageId, message) {
|
|
249
|
+
if (chatId > ZERO_CHANNEL_ID) {
|
|
250
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(K.messages.messageRef(messageId), message == null ? null : chatId);
|
|
251
|
+
}
|
|
252
|
+
await this.setTlObject(K.messages.message(chatId, messageId), message);
|
|
253
|
+
}
|
|
254
|
+
async deleteMessages() {
|
|
255
|
+
const maybePromises = new Array();
|
|
256
|
+
for await (const [k, o] of await __classPrivateFieldGet(this, _StorageOperations_storage, "f").getMany({ prefix: K.messages.allMessageRefs() })) {
|
|
257
|
+
maybePromises.push(Promise.all([__classPrivateFieldGet(this, _StorageOperations_storage, "f").set(k, null), o == null ? Promise.resolve() : __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(K.messages.message(o, k[1]), null)]).then(() => { }));
|
|
258
|
+
}
|
|
259
|
+
await Promise.all(maybePromises.filter((v) => v instanceof Promise));
|
|
260
|
+
}
|
|
261
|
+
getMessageChat(messageId) {
|
|
262
|
+
return __classPrivateFieldGet(this, _StorageOperations_storage, "f").get(K.messages.messageRef(messageId));
|
|
263
|
+
}
|
|
264
|
+
async getMessage(chatId, messageId) {
|
|
265
|
+
return await this.getTlObject(K.messages.message(chatId, messageId));
|
|
266
|
+
}
|
|
267
|
+
async getLastMessage(chatId) {
|
|
268
|
+
for await (const [_, buffer] of await __classPrivateFieldGet(this, _StorageOperations_storage, "f").getMany({ prefix: K.messages.messages(chatId) }, { limit: 1, reverse: true })) {
|
|
269
|
+
return await this.getTlObject(buffer);
|
|
270
|
+
}
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
async setChannelPts(channelId, pts) {
|
|
274
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(K.updates.channelPts(channelId), pts);
|
|
275
|
+
}
|
|
276
|
+
getChannelPts(channelId) {
|
|
277
|
+
return __classPrivateFieldGet(this, _StorageOperations_storage, "f").get(K.updates.channelPts(channelId));
|
|
278
|
+
}
|
|
279
|
+
async setEntity(entity) {
|
|
280
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(K.cache.peer(peerToChatId(entity)), [__classPrivateFieldGet(this, _StorageOperations_mustSerialize, "f") ? rleEncode(entity[serialize]()) : entity, new Date()]);
|
|
281
|
+
}
|
|
282
|
+
async getEntity(key) {
|
|
283
|
+
const peer_ = await __classPrivateFieldGet(this, _StorageOperations_storage, "f").get(K.cache.peer(key));
|
|
284
|
+
if (peer_ != null) {
|
|
285
|
+
const [obj_] = peer_;
|
|
286
|
+
return await this.getTlObject(obj_);
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
return null;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
async setAccountId(accountId) {
|
|
293
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(K.auth.accountId(), accountId);
|
|
294
|
+
}
|
|
295
|
+
async getAccountId() {
|
|
296
|
+
if (__classPrivateFieldGet(this, _StorageOperations_accountId, "f") != null) {
|
|
297
|
+
return __classPrivateFieldGet(this, _StorageOperations_accountId, "f");
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
return (__classPrivateFieldSet(this, _StorageOperations_accountId, await __classPrivateFieldGet(this, _StorageOperations_storage, "f").get(K.auth.accountId()), "f"));
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
async setAccountType(type) {
|
|
304
|
+
try {
|
|
305
|
+
await this.getAccountType();
|
|
306
|
+
unreachable();
|
|
307
|
+
}
|
|
308
|
+
catch (err) {
|
|
309
|
+
if (!(err instanceof AssertionError)) {
|
|
310
|
+
throw err;
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(K.auth.accountType(), type);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
async getAccountType() {
|
|
318
|
+
if (__classPrivateFieldGet(this, _StorageOperations_accountType, "f") != null) {
|
|
319
|
+
return __classPrivateFieldGet(this, _StorageOperations_accountType, "f");
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
return __classPrivateFieldSet(this, _StorageOperations_accountType, await __classPrivateFieldGet(this, _StorageOperations_storage, "f").get(K.auth.accountType()), "f");
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
async updateStickerSetName(id, accessHash, name) {
|
|
326
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(K.cache.stickerSetName(id, accessHash), [name, new Date()]);
|
|
327
|
+
}
|
|
328
|
+
getStickerSetName(id, accessHash) {
|
|
329
|
+
return __classPrivateFieldGet(this, _StorageOperations_storage, "f").get(K.cache.stickerSetName(id, accessHash));
|
|
330
|
+
}
|
|
331
|
+
async setServerSalt(serverSalt) {
|
|
332
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(K.session.serverSalt(), serverSalt);
|
|
333
|
+
}
|
|
334
|
+
getServerSalt() {
|
|
335
|
+
return __classPrivateFieldGet(this, _StorageOperations_storage, "f").get(K.session.serverSalt());
|
|
336
|
+
}
|
|
337
|
+
async setChat(listId, chatId, pinned, topMessageId, topMessageDate) {
|
|
338
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(K.chatlists.chat(listId, chatId), [pinned, topMessageId, topMessageDate]);
|
|
339
|
+
}
|
|
340
|
+
async getChats(listId) {
|
|
341
|
+
const chats = new Array();
|
|
342
|
+
for await (const [key, value] of await __classPrivateFieldGet(this, _StorageOperations_storage, "f").getMany({ prefix: K.chatlists.chats(listId) })) {
|
|
343
|
+
if (key.length != 3 || typeof key[2] !== "number") {
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
chats.push({ chatId: key[2], pinned: value[0], topMessageId: value[1], topMessageDate: value[2] });
|
|
347
|
+
}
|
|
348
|
+
return chats;
|
|
349
|
+
}
|
|
350
|
+
async removeChats(listId) {
|
|
351
|
+
for await (const [key] of await __classPrivateFieldGet(this, _StorageOperations_storage, "f").getMany({ prefix: K.chatlists.chats(listId) })) {
|
|
352
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(key, null);
|
|
353
|
+
}
|
|
354
|
+
await this.setHasAllChats(listId, false);
|
|
355
|
+
await this.setPinnedChats(listId, null);
|
|
356
|
+
}
|
|
357
|
+
async setHasAllChats(listId, hasAllChats) {
|
|
358
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(K.chatlists.hasAllChats(listId), hasAllChats);
|
|
359
|
+
}
|
|
360
|
+
async hasAllChats(listId) {
|
|
361
|
+
const v = await __classPrivateFieldGet(this, _StorageOperations_storage, "f").get(K.chatlists.hasAllChats(listId));
|
|
362
|
+
return v == true;
|
|
363
|
+
}
|
|
364
|
+
async setPinnedChats(listId, chatIds) {
|
|
365
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(K.chatlists.pinnedChats(listId), chatIds);
|
|
366
|
+
}
|
|
367
|
+
async getPinnedChats(listId) {
|
|
368
|
+
return await __classPrivateFieldGet(this, _StorageOperations_storage, "f").get(K.chatlists.pinnedChats(listId));
|
|
369
|
+
}
|
|
370
|
+
async getHistory(chatId, offsetId, limit) {
|
|
371
|
+
if (offsetId == 0) {
|
|
372
|
+
offsetId = Infinity;
|
|
373
|
+
}
|
|
374
|
+
++limit;
|
|
375
|
+
const messages = new Array();
|
|
376
|
+
for await (const [_, buffer] of await __classPrivateFieldGet(this, _StorageOperations_storage, "f").getMany({ start: K.messages.message(chatId, 0), end: K.messages.message(chatId, offsetId) }, { limit, reverse: true })) {
|
|
377
|
+
const message = await this.getTlObject(buffer);
|
|
378
|
+
if ("id" in message && message.id == offsetId) {
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
messages.push(message);
|
|
382
|
+
}
|
|
383
|
+
return messages;
|
|
384
|
+
}
|
|
385
|
+
async getFile(id) {
|
|
386
|
+
if (!__classPrivateFieldGet(this, _StorageOperations_supportsFiles, "f")) {
|
|
387
|
+
return null;
|
|
388
|
+
}
|
|
389
|
+
return await __classPrivateFieldGet(this, _StorageOperations_storage, "f").get(K.cache.file(id));
|
|
390
|
+
}
|
|
391
|
+
async *iterFileParts(id, partCount, offset) {
|
|
392
|
+
if (!__classPrivateFieldGet(this, _StorageOperations_supportsFiles, "f")) {
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
for (let i = offset; i < partCount; i++) {
|
|
396
|
+
const part = await __classPrivateFieldGet(this, _StorageOperations_storage, "f").get(K.cache.filePart(id, i));
|
|
397
|
+
if (part == null) {
|
|
398
|
+
continue;
|
|
399
|
+
}
|
|
400
|
+
yield part;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
async saveFilePart(id, index, bytes) {
|
|
404
|
+
if (!__classPrivateFieldGet(this, _StorageOperations_supportsFiles, "f")) {
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(K.cache.filePart(id, index), bytes);
|
|
408
|
+
}
|
|
409
|
+
async setFilePartCount(id, partCount, chunkSize) {
|
|
410
|
+
if (!__classPrivateFieldGet(this, _StorageOperations_supportsFiles, "f")) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(K.cache.file(id), [partCount, chunkSize]);
|
|
414
|
+
}
|
|
415
|
+
async setCustomEmojiDocument(id, document) {
|
|
416
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(K.cache.customEmojiDocument(id), [__classPrivateFieldGet(this, _StorageOperations_mustSerialize, "f") ? rleEncode(document[serialize]()) : document, new Date()]);
|
|
417
|
+
}
|
|
418
|
+
async getCustomEmojiDocument(id) {
|
|
419
|
+
const v = await __classPrivateFieldGet(this, _StorageOperations_storage, "f").get(K.cache.customEmojiDocument(id));
|
|
420
|
+
if (v != null) {
|
|
421
|
+
return [await this.getTlObject(v[0]), v[1]];
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
return null;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
async setBusinessConnection(id, connection) {
|
|
428
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(K.cache.businessConnection(id), connection == null ? null : __classPrivateFieldGet(this, _StorageOperations_mustSerialize, "f") ? rleEncode(connection[serialize]()) : connection);
|
|
429
|
+
}
|
|
430
|
+
async getBusinessConnection(id) {
|
|
431
|
+
const v = await __classPrivateFieldGet(this, _StorageOperations_storage, "f").get(K.cache.businessConnection(id));
|
|
432
|
+
if (v != null) {
|
|
433
|
+
return await this.getTlObject(v);
|
|
434
|
+
}
|
|
435
|
+
else {
|
|
436
|
+
return null;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
async setInlineQueryAnswer(userId, chatId, query, offset, results, date) {
|
|
440
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(K.cache.inlineQueryAnswer(userId, chatId, query, offset), [__classPrivateFieldGet(this, _StorageOperations_mustSerialize, "f") ? rleEncode(results[serialize]()) : results, date]);
|
|
441
|
+
}
|
|
442
|
+
async getInlineQueryAnswer(userId, chatId, query, offset) {
|
|
443
|
+
const peer_ = await __classPrivateFieldGet(this, _StorageOperations_storage, "f").get(K.cache.inlineQueryAnswer(userId, chatId, query, offset));
|
|
444
|
+
if (peer_ != null) {
|
|
445
|
+
const [obj_, date] = peer_;
|
|
446
|
+
return [await this.getTlObject(obj_), date];
|
|
447
|
+
}
|
|
448
|
+
else {
|
|
449
|
+
return null;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
async setCallbackQueryAnswer(chatId, messageId, question, answer) {
|
|
453
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(K.cache.callbackQueryAnswer(chatId, messageId, question), [__classPrivateFieldGet(this, _StorageOperations_mustSerialize, "f") ? rleEncode(answer[serialize]()) : answer, new Date()]);
|
|
454
|
+
}
|
|
455
|
+
async getCallbackQueryAnswer(chatId, messageId, question) {
|
|
456
|
+
const peer_ = await __classPrivateFieldGet(this, _StorageOperations_storage, "f").get(K.cache.callbackQueryAnswer(chatId, messageId, question));
|
|
457
|
+
if (peer_ != null) {
|
|
458
|
+
const [obj_, date] = peer_;
|
|
459
|
+
return [await this.getTlObject(obj_), date];
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
return null;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
async setFullChat(chatId, fullChat) {
|
|
466
|
+
await this.setTlObject(K.cache.fullChat(chatId), fullChat);
|
|
467
|
+
}
|
|
468
|
+
async getFullChat(chatId) {
|
|
469
|
+
return await this.getTlObject(K.cache.fullChat(chatId));
|
|
470
|
+
}
|
|
471
|
+
async setGroupCall(id, groupCall) {
|
|
472
|
+
await this.setTlObject(K.cache.groupCall(id), groupCall);
|
|
473
|
+
}
|
|
474
|
+
async getGroupCall(id) {
|
|
475
|
+
return await this.getTlObject(K.cache.groupCall(id));
|
|
476
|
+
}
|
|
477
|
+
async setGroupCallAccessHash(id, accessHash) {
|
|
478
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(K.cache.groupCallAccessHash(id), accessHash);
|
|
479
|
+
}
|
|
480
|
+
async getGroupCallAccessHash(id) {
|
|
481
|
+
return await __classPrivateFieldGet(this, _StorageOperations_storage, "f").get(K.cache.groupCallAccessHash(id));
|
|
482
|
+
}
|
|
483
|
+
async setUpdate(boxId, update) {
|
|
484
|
+
await this.setTlObject(K.updates.update(boxId, __classPrivateFieldGet(this, _StorageOperations_instances, "m", _StorageOperations_getUpdateId).call(this, update)), update);
|
|
485
|
+
}
|
|
486
|
+
async deleteUpdates() {
|
|
487
|
+
const maybePromises = new Array();
|
|
488
|
+
for await (const [k] of await __classPrivateFieldGet(this, _StorageOperations_storage, "f").getMany({ prefix: K.updates.all() })) {
|
|
489
|
+
maybePromises.push(__classPrivateFieldGet(this, _StorageOperations_storage, "f").set(k, null));
|
|
490
|
+
}
|
|
491
|
+
await Promise.all(maybePromises.filter((v) => v instanceof Promise));
|
|
492
|
+
}
|
|
493
|
+
async getFirstUpdate(boxId) {
|
|
494
|
+
for await (const [key, update] of await __classPrivateFieldGet(this, _StorageOperations_storage, "f").getMany({ prefix: K.updates.updates(boxId) }, { limit: 1 })) {
|
|
495
|
+
return [key, await this.getTlObject(update).then((v) => v)];
|
|
496
|
+
}
|
|
497
|
+
return null;
|
|
498
|
+
}
|
|
499
|
+
async assertUser(source) {
|
|
500
|
+
if (await this.getAccountType() != "user") {
|
|
501
|
+
throw new InputError(`${source}: not user a client`);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
async assertBot(source) {
|
|
505
|
+
if (await this.getAccountType() != "bot") {
|
|
506
|
+
throw new InputError(`${source}: not a bot client`);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
async deleteFiles() {
|
|
510
|
+
if (!__classPrivateFieldGet(this, _StorageOperations_supportsFiles, "f")) {
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
for await (const [key] of await __classPrivateFieldGet(this, _StorageOperations_storage, "f").getMany({ prefix: K.cache.fileParts() })) {
|
|
514
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(key, null);
|
|
515
|
+
}
|
|
516
|
+
for await (const [key] of await __classPrivateFieldGet(this, _StorageOperations_storage, "f").getMany({ prefix: K.cache.files() })) {
|
|
517
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(key, null);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
async deleteCustomEmojiDocuments() {
|
|
521
|
+
for await (const [key] of await __classPrivateFieldGet(this, _StorageOperations_storage, "f").getMany({ prefix: K.cache.customEmojiDocuments() })) {
|
|
522
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(key, null);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
async deleteBusinessConnections() {
|
|
526
|
+
for await (const [key] of await __classPrivateFieldGet(this, _StorageOperations_storage, "f").getMany({ prefix: K.cache.businessConnections() })) {
|
|
527
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(key, null);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
async deleteInlineQueryAnswers() {
|
|
531
|
+
for await (const [key] of await __classPrivateFieldGet(this, _StorageOperations_storage, "f").getMany({ prefix: K.cache.inlineQueryAnswers() })) {
|
|
532
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(key, null);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
async deleteCallbackQueryAnswers() {
|
|
536
|
+
for await (const [key] of await __classPrivateFieldGet(this, _StorageOperations_storage, "f").getMany({ prefix: K.cache.callbackQueryAnswers() })) {
|
|
537
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(key, null);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
async deleteFullChats() {
|
|
541
|
+
for await (const [key] of await __classPrivateFieldGet(this, _StorageOperations_storage, "f").getMany({ prefix: K.cache.fullChats() })) {
|
|
542
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(key, null);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
async deleteGroupCalls() {
|
|
546
|
+
for await (const [key] of await __classPrivateFieldGet(this, _StorageOperations_storage, "f").getMany({ prefix: K.cache.groupCalls() })) {
|
|
547
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(key, null);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
async deleteStickerSetNames() {
|
|
551
|
+
for await (const [key] of await __classPrivateFieldGet(this, _StorageOperations_storage, "f").getMany({ prefix: K.cache.stickerSetNames() })) {
|
|
552
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(key, null);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
async deletePeers() {
|
|
556
|
+
for await (const [key] of await __classPrivateFieldGet(this, _StorageOperations_storage, "f").getMany({ prefix: K.cache.peers() })) {
|
|
557
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(key, null);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
async deleteUsernames() {
|
|
561
|
+
for await (const [key] of await __classPrivateFieldGet(this, _StorageOperations_storage, "f").getMany({ prefix: K.cache.usernames() })) {
|
|
562
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(key, null);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
async clear() {
|
|
566
|
+
await Promise.all([
|
|
567
|
+
this.deleteMessages(),
|
|
568
|
+
this.removeChats(0),
|
|
569
|
+
this.removeChats(1),
|
|
570
|
+
this.deleteUpdates(),
|
|
571
|
+
this.deleteFiles(),
|
|
572
|
+
this.deleteCustomEmojiDocuments(),
|
|
573
|
+
this.deleteBusinessConnections(),
|
|
574
|
+
this.deleteInlineQueryAnswers(),
|
|
575
|
+
this.deleteCallbackQueryAnswers(),
|
|
576
|
+
this.deleteFullChats(),
|
|
577
|
+
this.deleteGroupCalls(),
|
|
578
|
+
this.deleteStickerSetNames(),
|
|
579
|
+
this.deletePeers(),
|
|
580
|
+
this.deleteUsernames(),
|
|
581
|
+
]);
|
|
582
|
+
}
|
|
583
|
+
async setApiId(apiId) {
|
|
584
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(K.connection.apiId(), apiId);
|
|
585
|
+
}
|
|
586
|
+
async getApiId() {
|
|
587
|
+
return await __classPrivateFieldGet(this, _StorageOperations_storage, "f").get(K.connection.apiId());
|
|
588
|
+
}
|
|
589
|
+
async reset() {
|
|
590
|
+
for await (const [key] of await __classPrivateFieldGet(this, _StorageOperations_storage, "f").getMany({ prefix: [] })) {
|
|
591
|
+
await __classPrivateFieldGet(this, _StorageOperations_storage, "f").set(key, null);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
_StorageOperations_storage = new WeakMap(), _StorageOperations_supportsFiles = new WeakMap(), _StorageOperations_mustSerialize = new WeakMap(), _StorageOperations_authKeyId = new WeakMap(), _StorageOperations_accountId = new WeakMap(), _StorageOperations_accountType = new WeakMap(), _StorageOperations_instances = new WeakSet(), _StorageOperations_resetAuthKeyId = async function _StorageOperations_resetAuthKeyId(authKey) {
|
|
596
|
+
if (authKey != null) {
|
|
597
|
+
__classPrivateFieldSet(this, _StorageOperations_authKeyId, await sha1(authKey).then((hash) => bigIntFromBuffer(hash.subarray(-8), true, false)), "f");
|
|
598
|
+
}
|
|
599
|
+
else {
|
|
600
|
+
__classPrivateFieldSet(this, _StorageOperations_authKeyId, null, "f");
|
|
601
|
+
}
|
|
602
|
+
}, _StorageOperations_getUpdateId = function _StorageOperations_getUpdateId(update) {
|
|
603
|
+
let id = BigInt(Date.now()) << 32n;
|
|
604
|
+
if ("pts" in update && update.pts) {
|
|
605
|
+
id |= BigInt(update.pts);
|
|
606
|
+
}
|
|
607
|
+
else {
|
|
608
|
+
id |= BigInt(0xffffffffn);
|
|
609
|
+
}
|
|
610
|
+
return id;
|
|
611
|
+
};
|
|
@@ -45,4 +45,6 @@ export declare class Composer<C extends {
|
|
|
45
45
|
names: string | RegExp | (string | RegExp)[];
|
|
46
46
|
prefixes: string | string[];
|
|
47
47
|
}, ...middleware: Middleware<WithFilter<C, "message:text">>[]): Composer<WithFilter<C, "message:text">>;
|
|
48
|
+
callbackQuery(data: string | RegExp | (string | RegExp)[]): Composer<WithFilter<C, "callbackQuery:data">>;
|
|
49
|
+
inlineQuery(queries: string | RegExp | (string | RegExp)[]): Composer<WithFilter<C, "inlineQuery">>;
|
|
48
50
|
}
|
package/esm/client/1_composer.js
CHANGED
|
@@ -136,5 +136,33 @@ export class Composer {
|
|
|
136
136
|
return false;
|
|
137
137
|
}, ...middleware);
|
|
138
138
|
}
|
|
139
|
+
callbackQuery(data) {
|
|
140
|
+
const data_ = Array.isArray(data) ? data : [data];
|
|
141
|
+
return this.on("callbackQuery:data").filter((ctx) => {
|
|
142
|
+
for (const data of data_) {
|
|
143
|
+
if (typeof data === "string" && data == ctx.callbackQuery.data) {
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
else if (data instanceof RegExp && data.test(ctx.callbackQuery.data)) {
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return false;
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
inlineQuery(queries) {
|
|
154
|
+
const queries_ = Array.isArray(queries) ? queries : [queries];
|
|
155
|
+
return this.on("inlineQuery").filter((ctx) => {
|
|
156
|
+
for (const query of queries_) {
|
|
157
|
+
if (typeof query === "string" && query == ctx.inlineQuery.query) {
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
else if (query instanceof RegExp && query.test(ctx.inlineQuery.query)) {
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return false;
|
|
165
|
+
});
|
|
166
|
+
}
|
|
139
167
|
}
|
|
140
168
|
_Composer_handle = new WeakMap(), _Composer_prefixes = new WeakMap();
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
20
|
import { enums, functions, types } from "../2_tl.js";
|
|
21
|
-
import {
|
|
21
|
+
import { StorageOperations } from "./0_storage_operations.js";
|
|
22
22
|
import { ConnectionState, EntityGetter, ID, ParseMode, Update } from "../3_types.js";
|
|
23
23
|
type Functions = typeof functions;
|
|
24
24
|
type Keys = keyof Functions;
|
|
@@ -53,8 +53,8 @@ interface GetCdnConnectionPool {
|
|
|
53
53
|
export interface C {
|
|
54
54
|
id: number;
|
|
55
55
|
api: Api;
|
|
56
|
-
storage:
|
|
57
|
-
messageStorage:
|
|
56
|
+
storage: StorageOperations;
|
|
57
|
+
messageStorage: StorageOperations;
|
|
58
58
|
guaranteeUpdateDelivery: boolean;
|
|
59
59
|
setConnectionState: (connectionState: ConnectionState) => void;
|
|
60
60
|
resetConnectionState: () => void;
|