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