@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
|
@@ -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 _ChatListManager_instances, _ChatListManager_c, _ChatListManager_handleUpdateChannel, _ChatListManager_handleUpdateChat, _ChatListManager_handleUpdateUser, _ChatListManager_getFullChat, _ChatListManager_checkChatTitle, _ChatListManager_createChannel, _ChatListManager_moveChatsToFolder, _ChatListManager_toggleBusinessBotsPaused;
|
|
33
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
22
|
exports.ChatListManager = void 0;
|
|
35
23
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
@@ -44,35 +32,49 @@ const chatListManagerUpdates = [
|
|
|
44
32
|
"updateUserName",
|
|
45
33
|
];
|
|
46
34
|
class ChatListManager {
|
|
35
|
+
#c;
|
|
47
36
|
constructor(c) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
37
|
+
this.#c = c;
|
|
38
|
+
}
|
|
39
|
+
async #handleUpdateChannel(update) {
|
|
40
|
+
const peer = { ...update, _: "peerChannel" };
|
|
41
|
+
const chatId = _2_tl_js_1.Api.peerToChatId(peer);
|
|
42
|
+
await this.#c.messageStorage.setFullChat(chatId, null);
|
|
43
|
+
}
|
|
44
|
+
async #handleUpdateChat(update) {
|
|
45
|
+
const peer = { ...update, _: "peerChat" };
|
|
46
|
+
const chatId = _2_tl_js_1.Api.peerToChatId(peer);
|
|
47
|
+
await this.#c.messageStorage.setFullChat(chatId, null);
|
|
48
|
+
}
|
|
49
|
+
async #handleUpdateUser(update) {
|
|
50
|
+
const peer = { ...update, _: "peerUser" };
|
|
51
|
+
const chatId = _2_tl_js_1.Api.peerToChatId(peer);
|
|
52
|
+
await this.#c.messageStorage.setFullChat(chatId, null);
|
|
51
53
|
}
|
|
52
54
|
async getChats(from = "main", after, limit = 100) {
|
|
53
|
-
|
|
55
|
+
this.#c.storage.assertUser("getChats");
|
|
54
56
|
if (limit <= 0 || limit > 100) {
|
|
55
57
|
limit = 100;
|
|
56
58
|
}
|
|
57
59
|
const listId = (0, _0_utilities_js_1.getChatListId)(from);
|
|
58
|
-
const dialogs = await
|
|
60
|
+
const dialogs = await this.#c.invoke({ _: "messages.getDialogs", limit, offset_id: after?.lastMessage?.id ?? 0, offset_date: after?.lastMessage?.date ?? 0, offset_peer: after ? await this.#c.getInputPeer(after.chat.id) : { _: "inputPeerEmpty" }, hash: 0n, folder_id: listId });
|
|
59
61
|
if (!(_2_tl_js_1.Api.is("messages.dialogs", dialogs)) && !(_2_tl_js_1.Api.is("messages.dialogsSlice", dialogs))) {
|
|
60
62
|
(0, _0_deps_js_1.unreachable)();
|
|
61
63
|
}
|
|
62
64
|
const chats = new Array();
|
|
63
65
|
for (const dialog of dialogs.dialogs) {
|
|
64
|
-
const chat = await (0, _3_types_js_1.constructChatListItem)(dialog, dialogs,
|
|
66
|
+
const chat = await (0, _3_types_js_1.constructChatListItem)(dialog, dialogs, this.#c.getPeer, this.#c.messageManager.getMessage.bind(this.#c.messageManager), this.#c.fileManager.getStickerSetName.bind(this.#c.fileManager));
|
|
65
67
|
chats.push(chat);
|
|
66
68
|
}
|
|
67
69
|
return chats;
|
|
68
70
|
}
|
|
69
71
|
async getPinnedChats(from = "main") {
|
|
70
|
-
|
|
72
|
+
this.#c.storage.assertUser("getPinnedChats");
|
|
71
73
|
const listId = (0, _0_utilities_js_1.getChatListId)(from);
|
|
72
|
-
const dialogs = await
|
|
74
|
+
const dialogs = await this.#c.invoke({ _: "messages.getPinnedDialogs", folder_id: listId });
|
|
73
75
|
const chats = new Array();
|
|
74
76
|
for (const dialog of dialogs.dialogs) {
|
|
75
|
-
const chat = await (0, _3_types_js_1.constructChatListItem)(dialog, dialogs,
|
|
77
|
+
const chat = await (0, _3_types_js_1.constructChatListItem)(dialog, dialogs, this.#c.getPeer, this.#c.messageManager.getMessage.bind(this.#c.messageManager), this.#c.fileManager.getStickerSetName.bind(this.#c.fileManager));
|
|
76
78
|
chats.push(chat);
|
|
77
79
|
}
|
|
78
80
|
return chats;
|
|
@@ -82,56 +84,78 @@ class ChatListManager {
|
|
|
82
84
|
}
|
|
83
85
|
async handleUpdate(update) {
|
|
84
86
|
if (_2_tl_js_1.Api.is("updateChannel", update)) {
|
|
85
|
-
await
|
|
87
|
+
await this.#handleUpdateChannel(update);
|
|
86
88
|
}
|
|
87
89
|
else if (_2_tl_js_1.Api.is("updateChat", update)) {
|
|
88
|
-
await
|
|
90
|
+
await this.#handleUpdateChat(update);
|
|
89
91
|
}
|
|
90
92
|
else if (_2_tl_js_1.Api.is("updateUser", update) || _2_tl_js_1.Api.is("updateUserName", update)) {
|
|
91
|
-
await
|
|
93
|
+
await this.#handleUpdateUser(update);
|
|
92
94
|
}
|
|
93
95
|
else {
|
|
94
96
|
(0, _0_deps_js_1.unreachable)();
|
|
95
97
|
}
|
|
96
98
|
return null;
|
|
97
99
|
}
|
|
100
|
+
async #getFullChat(chatId) {
|
|
101
|
+
const inputPeer = await this.#c.getInputPeer(chatId);
|
|
102
|
+
const chatId_ = await this.#c.getInputPeerChatId(inputPeer);
|
|
103
|
+
let fullChat = await this.#c.messageStorage.getFullChat(chatId_);
|
|
104
|
+
if (fullChat !== null) {
|
|
105
|
+
return fullChat;
|
|
106
|
+
}
|
|
107
|
+
if ((0, _0_utilities_js_1.canBeInputUser)(inputPeer)) {
|
|
108
|
+
fullChat = (await this.#c.invoke({ _: "users.getFullUser", id: (0, _0_utilities_js_1.toInputUser)(inputPeer) })).full_user;
|
|
109
|
+
}
|
|
110
|
+
else if (_2_tl_js_1.Api.is("inputPeerChat", inputPeer)) {
|
|
111
|
+
fullChat = (await this.#c.invoke({ ...inputPeer, _: "messages.getFullChat" })).full_chat;
|
|
112
|
+
}
|
|
113
|
+
else if ((0, _0_utilities_js_1.canBeInputChannel)(inputPeer)) {
|
|
114
|
+
fullChat = (await this.#c.invoke({ _: "channels.getFullChannel", channel: (0, _0_utilities_js_1.toInputChannel)(inputPeer) })).full_chat;
|
|
115
|
+
}
|
|
116
|
+
await this.#c.messageStorage.setFullChat(chatId_, fullChat);
|
|
117
|
+
if (fullChat !== null && "call" in fullChat && _2_tl_js_1.Api.is("inputGroupCall", fullChat.call)) {
|
|
118
|
+
await this.#c.messageStorage.setGroupCallAccessHash(fullChat.call.id, fullChat.call.access_hash);
|
|
119
|
+
}
|
|
120
|
+
return fullChat;
|
|
121
|
+
}
|
|
98
122
|
async getChat(chatId) {
|
|
99
|
-
const fullChat = await
|
|
123
|
+
const fullChat = await this.#getFullChat(chatId);
|
|
100
124
|
if (fullChat === null) {
|
|
101
125
|
throw new _0_errors_js_1.InputError("Chat not found.");
|
|
102
126
|
}
|
|
103
|
-
return (0, _3_types_js_1.constructChat)(fullChat,
|
|
127
|
+
return (0, _3_types_js_1.constructChat)(fullChat, this.#c.getPeer);
|
|
104
128
|
}
|
|
105
129
|
async getChatAdministrators(chatId) {
|
|
106
|
-
const peer = await
|
|
130
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
107
131
|
if ((0, _0_utilities_js_1.canBeInputChannel)(peer)) {
|
|
108
132
|
const channel = (0, _0_utilities_js_1.toInputChannel)(peer);
|
|
109
|
-
const participants = await
|
|
133
|
+
const participants = await this.#c.invoke({ _: "channels.getParticipants", channel, filter: { _: "channelParticipantsAdmins" }, offset: 0, limit: 100, hash: 0n });
|
|
110
134
|
if (_2_tl_js_1.Api.is("channels.channelParticipantsNotModified", participants)) {
|
|
111
135
|
(0, _0_deps_js_1.unreachable)();
|
|
112
136
|
}
|
|
113
137
|
const chatMembers = new Array();
|
|
114
138
|
for (const p of participants.participants) {
|
|
115
|
-
const peer =
|
|
139
|
+
const peer = this.#c.getPeer("peer" in p ? p.peer : { _: "peerUser", user_id: p.user_id });
|
|
116
140
|
if (!peer) {
|
|
117
141
|
(0, _0_deps_js_1.unreachable)();
|
|
118
142
|
}
|
|
119
|
-
chatMembers.push((0, _3_types_js_1.constructChatMember)(peer[0], p,
|
|
143
|
+
chatMembers.push((0, _3_types_js_1.constructChatMember)(peer[0], p, this.#c.getPeer));
|
|
120
144
|
}
|
|
121
145
|
return chatMembers;
|
|
122
146
|
}
|
|
123
147
|
else if (_2_tl_js_1.Api.is("inputPeerChat", peer)) {
|
|
124
|
-
const fullChat = await
|
|
148
|
+
const fullChat = await this.#getFullChat(chatId);
|
|
125
149
|
if (!fullChat || !("participants" in fullChat) || !_2_tl_js_1.Api.is("chatParticipants", fullChat.participants)) {
|
|
126
150
|
(0, _0_deps_js_1.unreachable)();
|
|
127
151
|
}
|
|
128
152
|
const chatMembers = new Array();
|
|
129
153
|
for (const p of fullChat.participants.participants) {
|
|
130
|
-
const peer =
|
|
154
|
+
const peer = this.#c.getPeer({ _: "peerUser", user_id: p.user_id });
|
|
131
155
|
if (!peer) {
|
|
132
156
|
(0, _0_deps_js_1.unreachable)();
|
|
133
157
|
}
|
|
134
|
-
chatMembers.push((0, _3_types_js_1.constructChatMember)(peer[0], p,
|
|
158
|
+
chatMembers.push((0, _3_types_js_1.constructChatMember)(peer[0], p, this.#c.getPeer));
|
|
135
159
|
}
|
|
136
160
|
return chatMembers;
|
|
137
161
|
}
|
|
@@ -140,60 +164,60 @@ class ChatListManager {
|
|
|
140
164
|
}
|
|
141
165
|
}
|
|
142
166
|
async getChatMember(chatId, userId) {
|
|
143
|
-
const peer = await
|
|
167
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
144
168
|
if ((0, _0_utilities_js_1.canBeInputChannel)(peer)) {
|
|
145
|
-
const { participant } = await
|
|
146
|
-
const memberPeer =
|
|
169
|
+
const { participant } = await this.#c.invoke({ _: "channels.getParticipant", channel: (0, _0_utilities_js_1.toInputChannel)(peer), participant: await this.#c.getInputPeer(userId) });
|
|
170
|
+
const memberPeer = this.#c.getPeer("peer" in participant ? participant.peer : { _: "peerUser", user_id: participant.user_id });
|
|
147
171
|
if (!memberPeer) {
|
|
148
172
|
(0, _0_deps_js_1.unreachable)();
|
|
149
173
|
}
|
|
150
|
-
return (0, _3_types_js_1.constructChatMember)(memberPeer[0], participant,
|
|
174
|
+
return (0, _3_types_js_1.constructChatMember)(memberPeer[0], participant, this.#c.getPeer);
|
|
151
175
|
}
|
|
152
176
|
else if (_2_tl_js_1.Api.is("inputPeerChat", peer)) {
|
|
153
|
-
const user = await
|
|
154
|
-
const userId_ = BigInt(await
|
|
155
|
-
const fullChat = await
|
|
177
|
+
const user = await this.#c.getInputUser(userId);
|
|
178
|
+
const userId_ = BigInt(await this.#c.getInputPeerChatId(user));
|
|
179
|
+
const fullChat = await this.#c.invoke({ ...peer, _: "messages.getFullChat" }).then((v) => _2_tl_js_1.Api.as("chatFull", v.full_chat));
|
|
156
180
|
const participant = _2_tl_js_1.Api.as("chatParticipants", fullChat.participants).participants.find((v) => v.user_id === userId_);
|
|
157
|
-
const memberPeer =
|
|
181
|
+
const memberPeer = this.#c.getPeer({ _: "peerUser", user_id: participant.user_id });
|
|
158
182
|
if (!memberPeer) {
|
|
159
183
|
(0, _0_deps_js_1.unreachable)();
|
|
160
184
|
}
|
|
161
|
-
return (0, _3_types_js_1.constructChatMember)(memberPeer[0], participant,
|
|
185
|
+
return (0, _3_types_js_1.constructChatMember)(memberPeer[0], participant, this.#c.getPeer);
|
|
162
186
|
}
|
|
163
187
|
else {
|
|
164
188
|
throw new _0_errors_js_1.InputError("Expected a channel, supergroup, or group ID. Got a user ID instead.");
|
|
165
189
|
}
|
|
166
190
|
}
|
|
167
191
|
async getChatMembers(chatId, params) {
|
|
168
|
-
const peer = await
|
|
192
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
169
193
|
if ((0, _0_utilities_js_1.canBeInputChannel)(peer)) {
|
|
170
194
|
const channel = (0, _0_utilities_js_1.toInputChannel)(peer);
|
|
171
|
-
const participants = await
|
|
195
|
+
const participants = await this.#c.invoke({ _: "channels.getParticipants", channel, filter: { _: "channelParticipantsRecent" }, offset: params?.offset ?? 0, limit: (0, _0_utilities_js_1.getLimit)(params?.limit), hash: 0n });
|
|
172
196
|
if (_2_tl_js_1.Api.is("channels.channelParticipantsNotModified", participants)) {
|
|
173
197
|
(0, _0_deps_js_1.unreachable)();
|
|
174
198
|
}
|
|
175
199
|
const chatMembers = new Array();
|
|
176
200
|
for (const p of participants.participants) {
|
|
177
|
-
const peer =
|
|
201
|
+
const peer = this.#c.getPeer("peer" in p ? p.peer : { _: "peerUser", user_id: p.user_id });
|
|
178
202
|
if (!peer) {
|
|
179
203
|
(0, _0_deps_js_1.unreachable)();
|
|
180
204
|
}
|
|
181
|
-
chatMembers.push((0, _3_types_js_1.constructChatMember)(peer[0], p,
|
|
205
|
+
chatMembers.push((0, _3_types_js_1.constructChatMember)(peer[0], p, this.#c.getPeer));
|
|
182
206
|
}
|
|
183
207
|
return chatMembers;
|
|
184
208
|
}
|
|
185
209
|
else if (_2_tl_js_1.Api.is("inputPeerChat", peer)) {
|
|
186
|
-
const fullChat = await
|
|
210
|
+
const fullChat = await this.#getFullChat(chatId);
|
|
187
211
|
if (!fullChat || !("participants" in fullChat) || !_2_tl_js_1.Api.is("chatParticipants", fullChat.participants)) {
|
|
188
212
|
(0, _0_deps_js_1.unreachable)();
|
|
189
213
|
}
|
|
190
214
|
const chatMembers = new Array();
|
|
191
215
|
for (const p of fullChat.participants.participants) {
|
|
192
|
-
const peer =
|
|
216
|
+
const peer = this.#c.getPeer({ _: "peerUser", user_id: p.user_id });
|
|
193
217
|
if (!peer) {
|
|
194
218
|
(0, _0_deps_js_1.unreachable)();
|
|
195
219
|
}
|
|
196
|
-
chatMembers.push((0, _3_types_js_1.constructChatMember)(peer[0], p,
|
|
220
|
+
chatMembers.push((0, _3_types_js_1.constructChatMember)(peer[0], p, this.#c.getPeer));
|
|
197
221
|
}
|
|
198
222
|
return chatMembers;
|
|
199
223
|
}
|
|
@@ -201,13 +225,20 @@ class ChatListManager {
|
|
|
201
225
|
(0, _0_deps_js_1.unreachable)();
|
|
202
226
|
}
|
|
203
227
|
}
|
|
228
|
+
#checkChatTitle(title) {
|
|
229
|
+
title = title.trim();
|
|
230
|
+
if (!title) {
|
|
231
|
+
throw new _0_errors_js_1.InputError("Title cannot be empty.");
|
|
232
|
+
}
|
|
233
|
+
return title;
|
|
234
|
+
}
|
|
204
235
|
async createGroup(title, params) {
|
|
205
|
-
|
|
206
|
-
title =
|
|
207
|
-
const { updates } = await
|
|
236
|
+
this.#c.storage.assertUser("createGroup");
|
|
237
|
+
title = this.#checkChatTitle(title);
|
|
238
|
+
const { updates } = await this.#c.invoke({
|
|
208
239
|
_: "messages.createChat",
|
|
209
240
|
title,
|
|
210
|
-
users: await Promise.all((params?.users ?? []).map((v) =>
|
|
241
|
+
users: await Promise.all((params?.users ?? []).map((v) => this.#c.getInputUser(v))),
|
|
211
242
|
ttl_period: params?.messageTtl || undefined,
|
|
212
243
|
});
|
|
213
244
|
if (!("chats" in updates) || updates.chats.length < 1) {
|
|
@@ -219,45 +250,70 @@ class ChatListManager {
|
|
|
219
250
|
}
|
|
220
251
|
return (0, _3_types_js_1.constructChatP)(chat);
|
|
221
252
|
}
|
|
253
|
+
async #createChannel(type, title, params) {
|
|
254
|
+
title = this.#checkChatTitle(title);
|
|
255
|
+
const updates = await this.#c.invoke({
|
|
256
|
+
_: "channels.createChannel",
|
|
257
|
+
broadcast: type === "channel" ? true : undefined,
|
|
258
|
+
megagroup: type === "supergroup" ? true : undefined,
|
|
259
|
+
forum: params && ("isForum" in params) && params.isForum ? true : undefined,
|
|
260
|
+
title,
|
|
261
|
+
about: params?.description || "",
|
|
262
|
+
ttl_period: params?.messageTtl || undefined,
|
|
263
|
+
});
|
|
264
|
+
if (!("chats" in updates) || updates.chats.length < 1) {
|
|
265
|
+
(0, _0_deps_js_1.unreachable)();
|
|
266
|
+
}
|
|
267
|
+
const chat = updates.chats[0];
|
|
268
|
+
if (chat._ !== "channel") {
|
|
269
|
+
(0, _0_deps_js_1.unreachable)();
|
|
270
|
+
}
|
|
271
|
+
return (0, _3_types_js_1.constructChatP)(chat);
|
|
272
|
+
}
|
|
222
273
|
async createSupergroup(title, params) {
|
|
223
|
-
|
|
224
|
-
return (await
|
|
274
|
+
this.#c.storage.assertUser("createSupergroup");
|
|
275
|
+
return (await this.#createChannel("supergroup", title, params));
|
|
225
276
|
}
|
|
226
277
|
async createChannel(title, params) {
|
|
227
|
-
|
|
228
|
-
return (await
|
|
278
|
+
this.#c.storage.assertUser("createChannel");
|
|
279
|
+
return (await this.#createChannel("channel", title, params));
|
|
229
280
|
}
|
|
230
281
|
async setMessageTtl(chatId, messageTtl) {
|
|
231
|
-
|
|
232
|
-
const peer = await
|
|
282
|
+
this.#c.storage.assertUser("setMessageTtl");
|
|
283
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
233
284
|
const period = messageTtl;
|
|
234
|
-
await
|
|
285
|
+
await this.#c.invoke({ _: "messages.setHistoryTTL", peer, period });
|
|
286
|
+
}
|
|
287
|
+
async #moveChatsToFolder(chatIds, folderId) {
|
|
288
|
+
const peers = await Promise.all(chatIds.map((v) => this.#c.getInputPeer(v)));
|
|
289
|
+
const inputFolderPeers = peers.map((v) => ({ _: "inputFolderPeer", peer: v, folder_id: folderId }));
|
|
290
|
+
await this.#c.invoke({ _: "folders.editPeerFolders", folder_peers: inputFolderPeers });
|
|
235
291
|
}
|
|
236
292
|
async archiveChats(chatIds) {
|
|
237
|
-
|
|
238
|
-
await
|
|
293
|
+
this.#c.storage.assertUser("archiveChats");
|
|
294
|
+
await this.#moveChatsToFolder(chatIds, 1);
|
|
239
295
|
}
|
|
240
296
|
async archiveChat(chatId) {
|
|
241
|
-
|
|
297
|
+
this.#c.storage.assertUser("archiveChat");
|
|
242
298
|
await this.archiveChats([chatId]);
|
|
243
299
|
}
|
|
244
300
|
async unarchiveChats(chatIds) {
|
|
245
|
-
|
|
246
|
-
await
|
|
301
|
+
this.#c.storage.assertUser("unarchiveChats");
|
|
302
|
+
await this.#moveChatsToFolder(chatIds, 0);
|
|
247
303
|
}
|
|
248
304
|
async unarchiveChat(chatId) {
|
|
249
|
-
|
|
305
|
+
this.#c.storage.assertUser("unarchiveChat");
|
|
250
306
|
await this.unarchiveChats([chatId]);
|
|
251
307
|
}
|
|
252
308
|
async getCommonChats(userId, params) {
|
|
253
|
-
|
|
254
|
-
const max_id = params?.fromChatId ? await
|
|
309
|
+
this.#c.storage.assertUser("getCommonChats");
|
|
310
|
+
const max_id = params?.fromChatId ? await this.#c.getInputPeerChatId(await this.#c.getInputPeer(params.fromChatId)) : 0;
|
|
255
311
|
if (max_id < 0) {
|
|
256
312
|
throw new _0_errors_js_1.InputError("fromChatId must be a chat identifier.");
|
|
257
313
|
}
|
|
258
|
-
const user_id = await
|
|
314
|
+
const user_id = await this.#c.getInputUser(userId);
|
|
259
315
|
const limit = (0, _0_utilities_js_1.getLimit)(params?.limit);
|
|
260
|
-
const result = await
|
|
316
|
+
const result = await this.#c.invoke({ _: "messages.getCommonChats", user_id, max_id: _2_tl_js_1.Api.chatIdToPeerId(max_id), limit });
|
|
261
317
|
const chats = new Array();
|
|
262
318
|
for (const chat of result.chats) {
|
|
263
319
|
if (!_2_tl_js_1.Api.is("chatEmpty", chat)) {
|
|
@@ -267,87 +323,25 @@ class ChatListManager {
|
|
|
267
323
|
return chats;
|
|
268
324
|
}
|
|
269
325
|
async getChatSettings(chatId) {
|
|
270
|
-
|
|
271
|
-
const peer = await
|
|
272
|
-
const settings = await
|
|
326
|
+
this.#c.storage.assertUser("getChatSettings");
|
|
327
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
328
|
+
const settings = await this.#c.invoke({ _: "messages.getPeerSettings", peer });
|
|
273
329
|
return (0, _3_types_js_1.constructChatSettings)(settings);
|
|
274
330
|
}
|
|
331
|
+
async #toggleBusinessBotsPaused(chatId, paused) {
|
|
332
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
333
|
+
if (!(0, _0_utilities_js_1.canBeInputUser)(peer)) {
|
|
334
|
+
throw new _0_errors_js_1.InputError("A private chat was expected.");
|
|
335
|
+
}
|
|
336
|
+
await this.#c.invoke({ _: "account.toggleConnectedBotPaused", peer, paused });
|
|
337
|
+
}
|
|
275
338
|
async disableBusinessBots(chatId) {
|
|
276
|
-
|
|
277
|
-
await
|
|
339
|
+
this.#c.storage.assertUser("disableBusinessBots");
|
|
340
|
+
await this.#toggleBusinessBotsPaused(chatId, true);
|
|
278
341
|
}
|
|
279
342
|
async enableBusinessBots(chatId) {
|
|
280
|
-
|
|
281
|
-
await
|
|
343
|
+
this.#c.storage.assertUser("enableBusinessBots");
|
|
344
|
+
await this.#toggleBusinessBotsPaused(chatId, false);
|
|
282
345
|
}
|
|
283
346
|
}
|
|
284
347
|
exports.ChatListManager = ChatListManager;
|
|
285
|
-
_ChatListManager_c = new WeakMap(), _ChatListManager_instances = new WeakSet(), _ChatListManager_handleUpdateChannel = async function _ChatListManager_handleUpdateChannel(update) {
|
|
286
|
-
const peer = { ...update, _: "peerChannel" };
|
|
287
|
-
const chatId = _2_tl_js_1.Api.peerToChatId(peer);
|
|
288
|
-
await __classPrivateFieldGet(this, _ChatListManager_c, "f").messageStorage.setFullChat(chatId, null);
|
|
289
|
-
}, _ChatListManager_handleUpdateChat = async function _ChatListManager_handleUpdateChat(update) {
|
|
290
|
-
const peer = { ...update, _: "peerChat" };
|
|
291
|
-
const chatId = _2_tl_js_1.Api.peerToChatId(peer);
|
|
292
|
-
await __classPrivateFieldGet(this, _ChatListManager_c, "f").messageStorage.setFullChat(chatId, null);
|
|
293
|
-
}, _ChatListManager_handleUpdateUser = async function _ChatListManager_handleUpdateUser(update) {
|
|
294
|
-
const peer = { ...update, _: "peerUser" };
|
|
295
|
-
const chatId = _2_tl_js_1.Api.peerToChatId(peer);
|
|
296
|
-
await __classPrivateFieldGet(this, _ChatListManager_c, "f").messageStorage.setFullChat(chatId, null);
|
|
297
|
-
}, _ChatListManager_getFullChat = async function _ChatListManager_getFullChat(chatId) {
|
|
298
|
-
const inputPeer = await __classPrivateFieldGet(this, _ChatListManager_c, "f").getInputPeer(chatId);
|
|
299
|
-
const chatId_ = await __classPrivateFieldGet(this, _ChatListManager_c, "f").getInputPeerChatId(inputPeer);
|
|
300
|
-
let fullChat = await __classPrivateFieldGet(this, _ChatListManager_c, "f").messageStorage.getFullChat(chatId_);
|
|
301
|
-
if (fullChat !== null) {
|
|
302
|
-
return fullChat;
|
|
303
|
-
}
|
|
304
|
-
if ((0, _0_utilities_js_1.canBeInputUser)(inputPeer)) {
|
|
305
|
-
fullChat = (await __classPrivateFieldGet(this, _ChatListManager_c, "f").invoke({ _: "users.getFullUser", id: (0, _0_utilities_js_1.toInputUser)(inputPeer) })).full_user;
|
|
306
|
-
}
|
|
307
|
-
else if (_2_tl_js_1.Api.is("inputPeerChat", inputPeer)) {
|
|
308
|
-
fullChat = (await __classPrivateFieldGet(this, _ChatListManager_c, "f").invoke({ ...inputPeer, _: "messages.getFullChat" })).full_chat;
|
|
309
|
-
}
|
|
310
|
-
else if ((0, _0_utilities_js_1.canBeInputChannel)(inputPeer)) {
|
|
311
|
-
fullChat = (await __classPrivateFieldGet(this, _ChatListManager_c, "f").invoke({ _: "channels.getFullChannel", channel: (0, _0_utilities_js_1.toInputChannel)(inputPeer) })).full_chat;
|
|
312
|
-
}
|
|
313
|
-
await __classPrivateFieldGet(this, _ChatListManager_c, "f").messageStorage.setFullChat(chatId_, fullChat);
|
|
314
|
-
if (fullChat !== null && "call" in fullChat && _2_tl_js_1.Api.is("inputGroupCall", fullChat.call)) {
|
|
315
|
-
await __classPrivateFieldGet(this, _ChatListManager_c, "f").messageStorage.setGroupCallAccessHash(fullChat.call.id, fullChat.call.access_hash);
|
|
316
|
-
}
|
|
317
|
-
return fullChat;
|
|
318
|
-
}, _ChatListManager_checkChatTitle = function _ChatListManager_checkChatTitle(title) {
|
|
319
|
-
title = title.trim();
|
|
320
|
-
if (!title) {
|
|
321
|
-
throw new _0_errors_js_1.InputError("Title cannot be empty.");
|
|
322
|
-
}
|
|
323
|
-
return title;
|
|
324
|
-
}, _ChatListManager_createChannel = async function _ChatListManager_createChannel(type, title, params) {
|
|
325
|
-
title = __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_checkChatTitle).call(this, title);
|
|
326
|
-
const updates = await __classPrivateFieldGet(this, _ChatListManager_c, "f").invoke({
|
|
327
|
-
_: "channels.createChannel",
|
|
328
|
-
broadcast: type === "channel" ? true : undefined,
|
|
329
|
-
megagroup: type === "supergroup" ? true : undefined,
|
|
330
|
-
forum: params && ("isForum" in params) && params.isForum ? true : undefined,
|
|
331
|
-
title,
|
|
332
|
-
about: params?.description || "",
|
|
333
|
-
ttl_period: params?.messageTtl || undefined,
|
|
334
|
-
});
|
|
335
|
-
if (!("chats" in updates) || updates.chats.length < 1) {
|
|
336
|
-
(0, _0_deps_js_1.unreachable)();
|
|
337
|
-
}
|
|
338
|
-
const chat = updates.chats[0];
|
|
339
|
-
if (chat._ !== "channel") {
|
|
340
|
-
(0, _0_deps_js_1.unreachable)();
|
|
341
|
-
}
|
|
342
|
-
return (0, _3_types_js_1.constructChatP)(chat);
|
|
343
|
-
}, _ChatListManager_moveChatsToFolder = async function _ChatListManager_moveChatsToFolder(chatIds, folderId) {
|
|
344
|
-
const peers = await Promise.all(chatIds.map((v) => __classPrivateFieldGet(this, _ChatListManager_c, "f").getInputPeer(v)));
|
|
345
|
-
const inputFolderPeers = peers.map((v) => ({ _: "inputFolderPeer", peer: v, folder_id: folderId }));
|
|
346
|
-
await __classPrivateFieldGet(this, _ChatListManager_c, "f").invoke({ _: "folders.editPeerFolders", folder_peers: inputFolderPeers });
|
|
347
|
-
}, _ChatListManager_toggleBusinessBotsPaused = async function _ChatListManager_toggleBusinessBotsPaused(chatId, paused) {
|
|
348
|
-
const peer = await __classPrivateFieldGet(this, _ChatListManager_c, "f").getInputPeer(chatId);
|
|
349
|
-
if (!(0, _0_utilities_js_1.canBeInputUser)(peer)) {
|
|
350
|
-
throw new _0_errors_js_1.InputError("A private chat was expected.");
|
|
351
|
-
}
|
|
352
|
-
await __classPrivateFieldGet(this, _ChatListManager_c, "f").invoke({ _: "account.toggleConnectedBotPaused", peer, paused });
|
|
353
|
-
};
|