@mtkruto/browser 0.119.0 → 0.120.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/esm/0_errors.d.ts.map +1 -1
- package/esm/0_errors.js +9 -31
- package/esm/3_errors.js +2 -12
- package/esm/4_errors.js +2 -12
- package/esm/_dnt.polyfills.d.ts +0 -99
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/_dnt.polyfills.js +1 -127
- package/esm/client/0_abortable_loop.js +26 -39
- package/esm/client/0_storage_operations.js +179 -218
- package/esm/client/1_client_plain.js +4 -22
- package/esm/client/2_account_manager.js +140 -149
- package/esm/client/2_bot_info_manager.js +26 -38
- package/esm/client/2_business_connection_manager.js +10 -23
- package/esm/client/2_client_encrypted.js +198 -215
- package/esm/client/2_file_manager.js +255 -262
- package/esm/client/2_network_statistics_manager.js +31 -44
- package/esm/client/2_payment_manager.js +7 -20
- package/esm/client/2_reaction_manager.js +7 -20
- package/esm/client/2_translations_manager.js +101 -111
- package/esm/client/2_update_manager.js +750 -745
- package/esm/client/3_client_encrypted_pool.js +10 -26
- package/esm/client/3_message_manager.js +503 -508
- package/esm/client/3_video_chat_manager.js +57 -68
- package/esm/client/4_callback_query_manager.js +18 -30
- package/esm/client/4_chat_list_manager.js +140 -146
- package/esm/client/4_chat_manager.js +161 -169
- package/esm/client/4_checklist_manager.js +26 -39
- package/esm/client/4_context.js +244 -259
- package/esm/client/4_forum_manager.js +67 -73
- package/esm/client/4_gift_manager.js +22 -35
- package/esm/client/4_inline_query_manager.js +16 -28
- package/esm/client/4_link_preview_manager.js +6 -19
- package/esm/client/4_poll_manager.js +44 -57
- package/esm/client/4_story_manager.js +41 -53
- package/esm/client/5_composer.js +13 -26
- package/esm/client/6_client.js +866 -896
- package/esm/client/6_client_dispatcher.js +308 -325
- package/esm/client/7_client_worker.js +16 -29
- package/esm/connection/1_connection_tcp.js +55 -82
- package/esm/connection/1_connection_web_socket.js +75 -91
- package/esm/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
- package/esm/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +31 -47
- package/esm/deps/jsr.io/@std/async/1.2.0/tee.js +11 -34
- package/esm/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +30 -47
- package/esm/deps/jsr.io/@std/datetime/0.225.7/_date_time_formatter.js +4 -17
- package/esm/session/0_session_state.js +12 -38
- package/esm/session/1_session.js +49 -72
- package/esm/session/2_session_encrypted.js +422 -420
- package/esm/storage/2_storage_indexed_db.js +26 -44
- package/esm/storage/2_storage_local_storage.js +3 -16
- package/esm/storage/2_storage_memory.js +24 -41
- package/esm/storage/2_storage_session_storage.js +3 -16
- package/esm/tl/1_tl_reader.d.ts +1 -1
- package/esm/tl/1_tl_reader.d.ts.map +1 -1
- package/esm/tl/1_tl_reader.js +95 -103
- package/esm/tl/1_tl_writer.js +169 -178
- package/esm/transport/0_transport.js +1 -8
- package/esm/transport/1_transport_abridged.js +11 -24
- package/esm/transport/1_transport_intermediate.js +10 -23
- package/esm/utilities/0_mutex.js +4 -19
- package/esm/utilities/0_part_stream.js +11 -25
- package/esm/utilities/1_crypto.js +42 -53
- package/esm/utilities/2_queue.js +29 -47
- package/package.json +1 -1
- package/script/0_errors.d.ts.map +1 -1
- package/script/0_errors.js +9 -31
- package/script/3_errors.js +2 -12
- package/script/4_errors.js +2 -12
- package/script/_dnt.polyfills.d.ts +0 -99
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +0 -128
- package/script/client/0_abortable_loop.js +27 -40
- package/script/client/0_storage_operations.js +179 -218
- package/script/client/1_client_plain.js +4 -22
- package/script/client/2_account_manager.js +140 -149
- package/script/client/2_bot_info_manager.js +26 -38
- package/script/client/2_business_connection_manager.js +10 -23
- package/script/client/2_client_encrypted.js +199 -216
- package/script/client/2_file_manager.js +255 -262
- package/script/client/2_network_statistics_manager.js +32 -45
- package/script/client/2_payment_manager.js +7 -20
- package/script/client/2_reaction_manager.js +7 -20
- package/script/client/2_translations_manager.js +102 -112
- package/script/client/2_update_manager.js +750 -745
- package/script/client/3_client_encrypted_pool.js +10 -26
- package/script/client/3_message_manager.js +503 -508
- package/script/client/3_video_chat_manager.js +57 -68
- package/script/client/4_callback_query_manager.js +18 -30
- package/script/client/4_chat_list_manager.js +140 -146
- package/script/client/4_chat_manager.js +161 -169
- package/script/client/4_checklist_manager.js +26 -39
- package/script/client/4_context.js +244 -259
- package/script/client/4_forum_manager.js +67 -73
- package/script/client/4_gift_manager.js +22 -35
- package/script/client/4_inline_query_manager.js +16 -28
- package/script/client/4_link_preview_manager.js +6 -19
- package/script/client/4_poll_manager.js +44 -57
- package/script/client/4_story_manager.js +41 -53
- package/script/client/5_composer.js +13 -26
- package/script/client/6_client.js +866 -896
- package/script/client/6_client_dispatcher.js +308 -325
- package/script/client/7_client_worker.js +16 -29
- package/script/connection/1_connection_tcp.js +55 -82
- package/script/connection/1_connection_web_socket.js +75 -91
- package/script/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
- package/script/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +31 -47
- package/script/deps/jsr.io/@std/async/1.2.0/tee.js +11 -34
- package/script/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +30 -47
- package/script/deps/jsr.io/@std/datetime/0.225.7/_date_time_formatter.js +4 -17
- package/script/session/0_session_state.js +12 -38
- package/script/session/1_session.js +49 -72
- package/script/session/2_session_encrypted.js +423 -421
- package/script/storage/2_storage_indexed_db.js +26 -44
- package/script/storage/2_storage_local_storage.js +3 -16
- package/script/storage/2_storage_memory.js +24 -41
- package/script/storage/2_storage_session_storage.js +3 -16
- package/script/tl/1_tl_reader.d.ts +1 -1
- package/script/tl/1_tl_reader.d.ts.map +1 -1
- package/script/tl/1_tl_reader.js +96 -104
- package/script/tl/1_tl_writer.js +170 -179
- package/script/transport/0_transport.js +1 -8
- package/script/transport/1_transport_abridged.js +11 -24
- package/script/transport/1_transport_intermediate.js +10 -23
- package/script/utilities/0_mutex.js +4 -19
- package/script/utilities/0_part_stream.js +11 -25
- package/script/utilities/1_crypto.js +43 -54
- package/script/utilities/2_queue.js +30 -48
|
@@ -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 _ChatManager_instances, _ChatManager_c, _ChatManager_toggleJoinRequests, _ChatManager_toggleSlowMode, _ChatManager_setIsMemberListVisible, _ChatManager_setIsTopicsEnabled, _ChatManager_setIsAntispamEnabled, _ChatManager_setIsSignaturesEnabled, _ChatManager_setIsSharingEnabled;
|
|
32
20
|
import { unreachable } from "../0_deps.js";
|
|
33
21
|
import { InputError } from "../0_errors.js";
|
|
34
22
|
import { Api } from "../2_tl.js";
|
|
@@ -43,18 +31,17 @@ const chatManagerUpdates = [
|
|
|
43
31
|
"updateBotChatInviteRequester",
|
|
44
32
|
];
|
|
45
33
|
export class ChatManager {
|
|
34
|
+
#c;
|
|
46
35
|
constructor(c) {
|
|
47
|
-
|
|
48
|
-
_ChatManager_c.set(this, void 0);
|
|
49
|
-
__classPrivateFieldSet(this, _ChatManager_c, c, "f");
|
|
36
|
+
this.#c = c;
|
|
50
37
|
}
|
|
51
38
|
canHandleUpdate(update) {
|
|
52
39
|
return Api.isOneOf(chatManagerUpdates, update);
|
|
53
40
|
}
|
|
54
41
|
async handleUpdate(update) {
|
|
55
42
|
if (Api.is("updateChannelParticipant", update) || Api.is("updateChatParticipant", update)) {
|
|
56
|
-
const chatMember = constructChatMemberUpdated(update,
|
|
57
|
-
const selfId = await
|
|
43
|
+
const chatMember = constructChatMemberUpdated(update, this.#c.getPeer);
|
|
44
|
+
const selfId = await this.#c.getSelfId();
|
|
58
45
|
if (chatMember.oldChatMember.member.id === selfId) {
|
|
59
46
|
return { myChatMember: chatMember };
|
|
60
47
|
}
|
|
@@ -63,51 +50,56 @@ export class ChatManager {
|
|
|
63
50
|
}
|
|
64
51
|
}
|
|
65
52
|
if (Api.is("updateBotChatInviteRequester", update)) {
|
|
66
|
-
const joinRequest = constructJoinRequest(update,
|
|
53
|
+
const joinRequest = constructJoinRequest(update, this.#c.getPeer);
|
|
67
54
|
return { joinRequest };
|
|
68
55
|
}
|
|
69
56
|
return null;
|
|
70
57
|
}
|
|
58
|
+
// JOIN REQUESTS //
|
|
59
|
+
async #toggleJoinRequests(chatId, isEnabled) {
|
|
60
|
+
const channel = await this.#c.getInputChannel(chatId);
|
|
61
|
+
await this.#c.invoke({ _: "channels.toggleJoinRequest", channel, enabled: isEnabled });
|
|
62
|
+
}
|
|
71
63
|
async approveJoinRequest(chatId, userId) {
|
|
72
|
-
await
|
|
64
|
+
await this.#c.invoke({
|
|
73
65
|
_: "messages.hideChatJoinRequest",
|
|
74
|
-
peer: await
|
|
75
|
-
user_id: await
|
|
66
|
+
peer: await this.#c.getInputPeer(chatId),
|
|
67
|
+
user_id: await this.#c.getInputUser(userId),
|
|
76
68
|
approved: true,
|
|
77
69
|
});
|
|
78
70
|
}
|
|
79
71
|
async declineJoinRequest(chatId, userId) {
|
|
80
|
-
await
|
|
72
|
+
await this.#c.invoke({
|
|
81
73
|
_: "messages.hideChatJoinRequest",
|
|
82
|
-
peer: await
|
|
83
|
-
user_id: await
|
|
74
|
+
peer: await this.#c.getInputPeer(chatId),
|
|
75
|
+
user_id: await this.#c.getInputUser(userId),
|
|
84
76
|
});
|
|
85
77
|
}
|
|
86
78
|
async approveJoinRequests(chatId, params) {
|
|
87
|
-
|
|
88
|
-
await
|
|
79
|
+
this.#c.storage.assertUser("approveJoinRequests");
|
|
80
|
+
await this.#c.invoke({
|
|
89
81
|
_: "messages.hideAllChatJoinRequests",
|
|
90
|
-
peer: await
|
|
82
|
+
peer: await this.#c.getInputPeer(chatId),
|
|
91
83
|
approved: true,
|
|
92
84
|
link: params?.inviteLink,
|
|
93
85
|
});
|
|
94
86
|
}
|
|
95
87
|
async declineJoinRequests(chatId, params) {
|
|
96
|
-
|
|
97
|
-
await
|
|
88
|
+
this.#c.storage.assertUser("declineJoinRequests");
|
|
89
|
+
await this.#c.invoke({
|
|
98
90
|
_: "messages.hideAllChatJoinRequests",
|
|
99
|
-
peer: await
|
|
91
|
+
peer: await this.#c.getInputPeer(chatId),
|
|
100
92
|
link: params?.inviteLink,
|
|
101
93
|
});
|
|
102
94
|
}
|
|
103
95
|
async getJoinRequests(chatId, params) {
|
|
104
|
-
|
|
96
|
+
this.#c.storage.assertUser("getJoinRequests");
|
|
105
97
|
if (typeof params?.inviteLink === "string" && typeof params?.search === "string") {
|
|
106
98
|
throw new InputError("inviteLink and search cannot be specified together.");
|
|
107
99
|
}
|
|
108
|
-
const peer = await
|
|
109
|
-
const offset_user = params?.fromUserId ? await
|
|
110
|
-
const { importers } = await
|
|
100
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
101
|
+
const offset_user = params?.fromUserId ? await this.#c.getInputUser(params.fromUserId) : { _: "inputUserEmpty" };
|
|
102
|
+
const { importers } = await this.#c.invoke({
|
|
111
103
|
_: "messages.getChatInviteImporters",
|
|
112
104
|
requested: true,
|
|
113
105
|
peer,
|
|
@@ -118,48 +110,48 @@ export class ChatManager {
|
|
|
118
110
|
limit: getLimit(params?.limit),
|
|
119
111
|
});
|
|
120
112
|
const peer_ = inputPeerToPeer(peer);
|
|
121
|
-
return await Promise.all(importers.map((v) => constructJoinRequest2(peer_, v,
|
|
113
|
+
return await Promise.all(importers.map((v) => constructJoinRequest2(peer_, v, this.#c.getPeer)));
|
|
122
114
|
}
|
|
123
115
|
// INVITE LINKS //
|
|
124
116
|
async createInviteLink(chatId, params) {
|
|
125
117
|
if (params?.isApprovalRequired && params?.limit) {
|
|
126
118
|
throw new InputError("isApprovalRequired cannot be true while limit is specified.");
|
|
127
119
|
}
|
|
128
|
-
const result = await
|
|
129
|
-
return constructInviteLink(Api.as("chatInviteExported", result),
|
|
120
|
+
const result = await this.#c.invoke({ _: "messages.exportChatInvite", peer: await this.#c.getInputPeer(chatId), title: params?.title, expire_date: params?.expireAt, request_needed: params?.isApprovalRequired ? true : undefined, usage_limit: params?.limit });
|
|
121
|
+
return constructInviteLink(Api.as("chatInviteExported", result), this.#c.getPeer);
|
|
130
122
|
}
|
|
131
123
|
async getCreatedInviteLinks(chatId, params) {
|
|
132
|
-
|
|
133
|
-
const { invites } = await
|
|
134
|
-
return await Promise.all(invites.map((v) => Api.as("chatInviteExported", v)).map((v) => constructInviteLink(v,
|
|
124
|
+
this.#c.storage.assertUser("getCreatedInviteLinks");
|
|
125
|
+
const { invites } = await this.#c.invoke({ _: "messages.getExportedChatInvites", peer: await this.#c.getInputPeer(chatId), revoked: params?.isRevoked ? true : undefined, admin_id: params?.by ? await this.#c.getInputUser(params.by) : { _: "inputUserEmpty" }, limit: getLimit(params?.limit), offset_date: params?.afterDate, offset_link: params?.afterInviteLink });
|
|
126
|
+
return await Promise.all(invites.map((v) => Api.as("chatInviteExported", v)).map((v) => constructInviteLink(v, this.#c.getPeer)));
|
|
135
127
|
}
|
|
136
128
|
// JOINING AND LEAVING CHATS //
|
|
137
129
|
async joinChat(chatId) {
|
|
138
|
-
|
|
139
|
-
const peer = await
|
|
130
|
+
this.#c.storage.assertUser("joinChat");
|
|
131
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
140
132
|
if (canBeInputUser(peer)) {
|
|
141
133
|
throw new InputError("Cannot join private chats.");
|
|
142
134
|
}
|
|
143
135
|
else if (canBeInputChannel(peer)) {
|
|
144
|
-
await
|
|
136
|
+
await this.#c.invoke({ _: "channels.joinChannel", channel: toInputChannel(peer) });
|
|
145
137
|
}
|
|
146
138
|
else if (Api.is("inputPeerChat", peer)) {
|
|
147
|
-
await
|
|
139
|
+
await this.#c.invoke({ _: "messages.addChatUser", chat_id: peer.chat_id, user_id: { _: "inputUserSelf" }, fwd_limit: 0 }); // TODO: use potential high-level method for adding participants to chats
|
|
148
140
|
}
|
|
149
141
|
else {
|
|
150
142
|
unreachable();
|
|
151
143
|
}
|
|
152
144
|
}
|
|
153
145
|
async leaveChat(chatId) {
|
|
154
|
-
const peer = await
|
|
146
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
155
147
|
if (canBeInputUser(peer)) {
|
|
156
148
|
throw new InputError("Cannot leave private chats.");
|
|
157
149
|
}
|
|
158
150
|
else if (canBeInputChannel(peer)) {
|
|
159
|
-
await
|
|
151
|
+
await this.#c.invoke({ _: "channels.leaveChannel", channel: toInputChannel(peer) });
|
|
160
152
|
}
|
|
161
153
|
else if (Api.is("inputPeerChat", peer)) {
|
|
162
|
-
await
|
|
154
|
+
await this.#c.invoke({ _: "messages.deleteChatUser", chat_id: peer.chat_id, user_id: { _: "inputUserSelf" } }); // TODO: use potential high-level method for adding participants to chats
|
|
163
155
|
}
|
|
164
156
|
else {
|
|
165
157
|
unreachable();
|
|
@@ -167,21 +159,21 @@ export class ChatManager {
|
|
|
167
159
|
}
|
|
168
160
|
// CHAT MEMBERS //
|
|
169
161
|
async banChatMember(chatId, memberId, params) {
|
|
170
|
-
const chat = await
|
|
162
|
+
const chat = await this.#c.getInputPeer(chatId);
|
|
171
163
|
if (!(Api.is("inputPeerChannel", chat)) && !(Api.is("inputPeerChat", chat))) {
|
|
172
164
|
throw new InputError("Expected a channel, supergroup, or group ID.");
|
|
173
165
|
}
|
|
174
|
-
const member = await
|
|
166
|
+
const member = await this.#c.getInputPeer(memberId);
|
|
175
167
|
if (Api.is("inputPeerChannel", chat)) {
|
|
176
168
|
if (params?.deleteMessages) {
|
|
177
169
|
try {
|
|
178
|
-
await
|
|
170
|
+
await this.#c.messageManager.deleteChatMemberMessages(chatId, memberId);
|
|
179
171
|
}
|
|
180
172
|
catch {
|
|
181
173
|
//
|
|
182
174
|
}
|
|
183
175
|
}
|
|
184
|
-
await
|
|
176
|
+
await this.#c.invoke({
|
|
185
177
|
_: "channels.editBanned",
|
|
186
178
|
channel: { ...chat, _: "inputChannel" },
|
|
187
179
|
participant: member,
|
|
@@ -203,25 +195,25 @@ export class ChatManager {
|
|
|
203
195
|
if (!canBeInputUser(member)) {
|
|
204
196
|
throw new InputError(`Invalid user ID: ${memberId}`);
|
|
205
197
|
}
|
|
206
|
-
await
|
|
198
|
+
await this.#c.invoke({ _: "messages.deleteChatUser", chat_id: chat.chat_id, user_id: toInputUser(member), revoke_history: params?.deleteMessages ? true : undefined });
|
|
207
199
|
}
|
|
208
200
|
}
|
|
209
201
|
async unbanChatMember(chatId, memberId) {
|
|
210
|
-
const channel = await
|
|
211
|
-
const member = await
|
|
212
|
-
await
|
|
202
|
+
const channel = await this.#c.getInputChannel(chatId);
|
|
203
|
+
const member = await this.#c.getInputPeer(memberId);
|
|
204
|
+
await this.#c.invoke({ _: "channels.editBanned", channel, participant: member, banned_rights: { _: "chatBannedRights", until_date: 0 } });
|
|
213
205
|
}
|
|
214
206
|
async setChatMemberRights(chatId, memberId, params) {
|
|
215
|
-
const channel = await
|
|
216
|
-
const member = await
|
|
217
|
-
await
|
|
207
|
+
const channel = await this.#c.getInputChannel(chatId);
|
|
208
|
+
const member = await this.#c.getInputPeer(memberId);
|
|
209
|
+
await this.#c.invoke({ _: "channels.editBanned", channel, participant: member, banned_rights: chatMemberRightsToTlObject(params?.rights, params?.until) });
|
|
218
210
|
}
|
|
219
211
|
async promoteChatMember(chatId, userId, params) {
|
|
220
|
-
const channel = await
|
|
221
|
-
const user_id = await
|
|
212
|
+
const channel = await this.#c.getInputChannel(chatId);
|
|
213
|
+
const user_id = await this.#c.getInputUser(userId);
|
|
222
214
|
const admin_rights = chatAdministratorRightsToTlObject(params ?? {});
|
|
223
215
|
const rank = params?.title ?? "";
|
|
224
|
-
await
|
|
216
|
+
await this.#c.invoke({
|
|
225
217
|
_: "channels.editAdmin",
|
|
226
218
|
channel,
|
|
227
219
|
user_id,
|
|
@@ -230,117 +222,138 @@ export class ChatManager {
|
|
|
230
222
|
});
|
|
231
223
|
}
|
|
232
224
|
async setChatMemberTag(chatId, userId, params) {
|
|
233
|
-
const peer = await
|
|
234
|
-
const participant = await
|
|
225
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
226
|
+
const participant = await this.#c.getInputPeer(userId);
|
|
235
227
|
const rank = params?.tag ?? "";
|
|
236
|
-
await
|
|
228
|
+
await this.#c.invoke({ _: "messages.editChatParticipantRank", peer, participant, rank });
|
|
237
229
|
}
|
|
238
230
|
// CHAT SETTINGS //
|
|
239
231
|
async setAvailableReactions(chatId, availableReactions) {
|
|
240
|
-
await
|
|
232
|
+
await this.#c.invoke({ _: "messages.setChatAvailableReactions", peer: await this.#c.getInputPeer(chatId), available_reactions: availableReactions === "none" ? { _: "chatReactionsNone" } : availableReactions === "all" ? { _: "chatReactionsAll" } : Array.isArray(availableReactions) ? ({ _: "chatReactionsSome", reactions: availableReactions.map((v) => reactionToTlObject(v)) }) : unreachable() });
|
|
241
233
|
}
|
|
242
234
|
async setBoostsRequiredToCircumventRestrictions(chatId, boosts) {
|
|
243
|
-
|
|
244
|
-
const channel = await
|
|
245
|
-
await
|
|
235
|
+
this.#c.storage.assertUser("setBoostsRequiredToCircumventRestrictions");
|
|
236
|
+
const channel = await this.#c.getInputChannel(chatId);
|
|
237
|
+
await this.#c.invoke({ _: "channels.setBoostsToUnblockRestrictions", channel, boosts });
|
|
246
238
|
}
|
|
247
239
|
async enableJoinRequests(chatId) {
|
|
248
|
-
|
|
249
|
-
await
|
|
240
|
+
this.#c.storage.assertUser("enableJoinRequests");
|
|
241
|
+
await this.#toggleJoinRequests(chatId, true);
|
|
250
242
|
}
|
|
251
243
|
async disableJoinRequests(chatId) {
|
|
252
|
-
|
|
253
|
-
await
|
|
244
|
+
this.#c.storage.assertUser("disableJoinRequests");
|
|
245
|
+
await this.#toggleJoinRequests(chatId, false);
|
|
254
246
|
}
|
|
255
247
|
async setChatStickerSet(chatId, setName) {
|
|
256
|
-
const channel = await
|
|
257
|
-
await
|
|
248
|
+
const channel = await this.#c.getInputChannel(chatId);
|
|
249
|
+
await this.#c.invoke({ _: "channels.setStickers", channel, stickerset: { _: "inputStickerSetShortName", short_name: setName } });
|
|
258
250
|
}
|
|
259
251
|
async deleteChatStickerSet(chatId) {
|
|
260
|
-
const channel = await
|
|
261
|
-
await
|
|
252
|
+
const channel = await this.#c.getInputChannel(chatId);
|
|
253
|
+
await this.#c.invoke({ _: "channels.setStickers", channel, stickerset: { _: "inputStickerSetEmpty" } });
|
|
254
|
+
}
|
|
255
|
+
async #toggleSlowMode(chatId, seconds) {
|
|
256
|
+
const channel = await this.#c.getInputChannel(chatId);
|
|
257
|
+
await this.#c.invoke({ _: "channels.toggleSlowMode", channel, seconds });
|
|
262
258
|
}
|
|
263
259
|
async disableSlowMode(chatId) {
|
|
264
|
-
|
|
265
|
-
await
|
|
260
|
+
this.#c.storage.assertUser("disableSlowMode");
|
|
261
|
+
await this.#toggleSlowMode(chatId, 0);
|
|
266
262
|
}
|
|
267
263
|
async setSlowMode(chatId, duration) {
|
|
268
|
-
|
|
264
|
+
this.#c.storage.assertUser("setSlowMode");
|
|
269
265
|
const seconds = slowModeDurationToSeconds(duration);
|
|
270
266
|
if (seconds > 1) {
|
|
271
267
|
throw new InputError("Invalid slow mode duration.");
|
|
272
268
|
}
|
|
273
|
-
await
|
|
269
|
+
await this.#toggleSlowMode(chatId, seconds);
|
|
274
270
|
}
|
|
275
271
|
async setChatTitle(chatId, title) {
|
|
276
|
-
const peer = await
|
|
272
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
277
273
|
if (Api.is("inputPeerChat", peer)) {
|
|
278
|
-
await
|
|
274
|
+
await this.#c.invoke({ _: "messages.editChatTitle", chat_id: peer.chat_id, title });
|
|
279
275
|
}
|
|
280
276
|
else if (canBeInputChannel(peer)) {
|
|
281
277
|
const channel = toInputChannel(peer);
|
|
282
|
-
await
|
|
278
|
+
await this.#c.invoke({ _: "channels.editTitle", channel, title });
|
|
283
279
|
}
|
|
284
280
|
else {
|
|
285
281
|
throw new InputError("A chat or channel identifier was expected.");
|
|
286
282
|
}
|
|
287
283
|
}
|
|
288
284
|
async setChatDescription(chatId, description) {
|
|
289
|
-
const peer = await
|
|
285
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
290
286
|
if (canBeInputUser(peer)) {
|
|
291
287
|
throw new InputError("A chat or channel identifier was expected.");
|
|
292
288
|
}
|
|
293
|
-
await
|
|
289
|
+
await this.#c.invoke({ _: "messages.editChatAbout", peer, about: description });
|
|
290
|
+
}
|
|
291
|
+
async #setIsMemberListVisible(chatId, isVisible) {
|
|
292
|
+
const channel = await this.#c.getInputChannel(chatId);
|
|
293
|
+
const enabled = !isVisible;
|
|
294
|
+
await this.#c.invoke({ _: "channels.toggleParticipantsHidden", channel, enabled });
|
|
294
295
|
}
|
|
295
296
|
async hideMemberList(chatId) {
|
|
296
|
-
|
|
297
|
-
await
|
|
297
|
+
this.#c.storage.assertUser("hideMemberList");
|
|
298
|
+
await this.#setIsMemberListVisible(chatId, false);
|
|
298
299
|
}
|
|
299
300
|
async showMemberList(chatId) {
|
|
300
|
-
|
|
301
|
-
await
|
|
301
|
+
this.#c.storage.assertUser("showMemberList");
|
|
302
|
+
await this.#setIsMemberListVisible(chatId, true);
|
|
303
|
+
}
|
|
304
|
+
async #setIsTopicsEnabled(chatId, isEnabled, isShownAsTabs) {
|
|
305
|
+
const channel = await this.#c.getInputChannel(chatId);
|
|
306
|
+
await this.#c.invoke({ _: "channels.toggleForum", channel, enabled: isEnabled, tabs: isShownAsTabs });
|
|
302
307
|
}
|
|
303
308
|
async disableTopics(chatId) {
|
|
304
|
-
|
|
305
|
-
await
|
|
309
|
+
this.#c.storage.assertUser("disableTopics");
|
|
310
|
+
await this.#setIsTopicsEnabled(chatId, false, false);
|
|
306
311
|
}
|
|
307
312
|
async enableTopics(chatId, isShownAsTabs) {
|
|
308
|
-
|
|
309
|
-
await
|
|
313
|
+
this.#c.storage.assertUser("enableTopics");
|
|
314
|
+
await this.#setIsTopicsEnabled(chatId, true, isShownAsTabs);
|
|
315
|
+
}
|
|
316
|
+
async #setIsAntispamEnabled(chatId, isEnabled) {
|
|
317
|
+
const channel = await this.#c.getInputChannel(chatId);
|
|
318
|
+
await this.#c.invoke({ _: "channels.toggleAntiSpam", channel, enabled: isEnabled });
|
|
310
319
|
}
|
|
311
320
|
async enableAntispam(chatId) {
|
|
312
|
-
|
|
313
|
-
await
|
|
321
|
+
this.#c.storage.assertUser("enableAntispam");
|
|
322
|
+
await this.#setIsAntispamEnabled(chatId, true);
|
|
314
323
|
}
|
|
315
324
|
async disableAntispam(chatId) {
|
|
316
|
-
|
|
317
|
-
await
|
|
325
|
+
this.#c.storage.assertUser("disableAntispam");
|
|
326
|
+
await this.#setIsAntispamEnabled(chatId, false);
|
|
327
|
+
}
|
|
328
|
+
async #setIsSignaturesEnabled(chatId, isEnabled, params) {
|
|
329
|
+
const channel = await this.#c.getInputChannel(chatId);
|
|
330
|
+
await this.#c.invoke({ _: "channels.toggleSignatures", channel, signatures_enabled: isEnabled ? true : undefined, profiles_enabled: params?.showAuthorProfile ? true : undefined });
|
|
318
331
|
}
|
|
319
332
|
async enableSignatures(chatId, params) {
|
|
320
|
-
|
|
321
|
-
await
|
|
333
|
+
this.#c.storage.assertUser("enableSignatures");
|
|
334
|
+
await this.#setIsSignaturesEnabled(chatId, true, params);
|
|
322
335
|
}
|
|
323
336
|
async disableSignatures(chatId) {
|
|
324
|
-
|
|
325
|
-
await
|
|
337
|
+
this.#c.storage.assertUser("disableSignatures");
|
|
338
|
+
await this.#setIsSignaturesEnabled(chatId, false);
|
|
326
339
|
}
|
|
327
340
|
async deleteChat(chatId) {
|
|
328
|
-
|
|
329
|
-
const peer = await
|
|
341
|
+
this.#c.storage.assertUser("deleteChat");
|
|
342
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
330
343
|
if (Api.is("inputPeerChat", peer)) {
|
|
331
|
-
await
|
|
344
|
+
await this.#c.invoke({ _: "messages.deleteChat", chat_id: peer.chat_id });
|
|
332
345
|
}
|
|
333
346
|
else if (canBeInputChannel(peer)) {
|
|
334
347
|
const channel = toInputChannel(peer);
|
|
335
|
-
await
|
|
348
|
+
await this.#c.invoke({ _: "channels.deleteChannel", channel });
|
|
336
349
|
}
|
|
337
350
|
else {
|
|
338
351
|
throw new InputError("A chat or channel identifier was expected.");
|
|
339
352
|
}
|
|
340
353
|
}
|
|
341
354
|
async getDiscussionChatSuggestions() {
|
|
342
|
-
|
|
343
|
-
const { chats } = await
|
|
355
|
+
this.#c.storage.assertUser("getDiscussionChatSuggestions");
|
|
356
|
+
const { chats } = await this.#c.invoke({ _: "channels.getGroupsForDiscussion" });
|
|
344
357
|
return chats
|
|
345
358
|
.map((v) => {
|
|
346
359
|
if (!Api.isOneOf(["chat", "channel"], v)) {
|
|
@@ -353,134 +366,113 @@ export class ChatManager {
|
|
|
353
366
|
.filter((v) => v !== null);
|
|
354
367
|
}
|
|
355
368
|
async setDiscussionChat(chatId, discussionChatId) {
|
|
356
|
-
|
|
357
|
-
const [broadcast, group] = await Promise.all([
|
|
358
|
-
await
|
|
369
|
+
this.#c.storage.assertUser("setDiscussionChat");
|
|
370
|
+
const [broadcast, group] = await Promise.all([this.#c.getInputChannel(chatId), this.#c.getInputChannel(discussionChatId)]);
|
|
371
|
+
await this.#c.invoke({ _: "channels.setDiscussionGroup", broadcast, group });
|
|
359
372
|
}
|
|
360
373
|
async transferChatOwnership(chatId, userId, password) {
|
|
361
|
-
|
|
362
|
-
const user_id = await
|
|
374
|
+
this.#c.storage.assertUser("transferChat");
|
|
375
|
+
const user_id = await this.#c.getInputUser(userId);
|
|
363
376
|
const isSelf = Api.is("inputUserSelf", user_id);
|
|
364
|
-
if (isSelf || Api.peerToChatId(user_id) === await
|
|
377
|
+
if (isSelf || Api.peerToChatId(user_id) === await this.#c.getSelfId()) {
|
|
365
378
|
throw new InputError("A user ID except that of the current one was expected.");
|
|
366
379
|
}
|
|
367
|
-
const peer = await
|
|
368
|
-
const ap = await
|
|
380
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
381
|
+
const ap = await this.#c.invoke({ _: "account.getPassword" });
|
|
369
382
|
const password_ = await checkPassword(password, ap);
|
|
370
|
-
await
|
|
383
|
+
await this.#c.invoke({ _: "messages.editChatCreator", peer, user_id, password: password_ });
|
|
384
|
+
}
|
|
385
|
+
async #setIsSharingEnabled(chatId, isSharingEnabled) {
|
|
386
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
387
|
+
await this.#c.invoke({ _: "messages.toggleNoForwards", peer, enabled: !isSharingEnabled });
|
|
371
388
|
}
|
|
372
389
|
async enableSharing(chatId) {
|
|
373
|
-
|
|
374
|
-
await
|
|
390
|
+
this.#c.storage.assertUser("enableSharing");
|
|
391
|
+
await this.#setIsSharingEnabled(chatId, true);
|
|
375
392
|
}
|
|
376
393
|
async disableSharing(chatId) {
|
|
377
|
-
|
|
378
|
-
await
|
|
394
|
+
this.#c.storage.assertUser("disableSharing");
|
|
395
|
+
await this.#setIsSharingEnabled(chatId, false);
|
|
379
396
|
}
|
|
380
397
|
// CHAT PHOTOS //
|
|
381
398
|
async deleteChatPhoto(chatId) {
|
|
382
|
-
const peer = await
|
|
399
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
383
400
|
if (!(canBeInputChannel(peer)) && !(Api.is("inputPeerChat", peer))) {
|
|
384
401
|
unreachable();
|
|
385
402
|
}
|
|
386
403
|
if (canBeInputChannel(peer)) {
|
|
387
|
-
await
|
|
404
|
+
await this.#c.invoke({ _: "channels.editPhoto", channel: toInputChannel(peer), photo: { _: "inputChatPhotoEmpty" } });
|
|
388
405
|
}
|
|
389
406
|
else if (Api.is("inputPeerChat", peer)) {
|
|
390
|
-
await
|
|
407
|
+
await this.#c.invoke({ _: "messages.editChatPhoto", chat_id: peer.chat_id, photo: { _: "inputChatPhotoEmpty" } });
|
|
391
408
|
}
|
|
392
409
|
}
|
|
393
410
|
async setChatPhoto(chatId, photo, params) {
|
|
394
|
-
const peer = await
|
|
411
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
395
412
|
if (!(canBeInputChannel(peer)) && !(Api.is("inputPeerChat", peer))) {
|
|
396
413
|
unreachable();
|
|
397
414
|
}
|
|
398
|
-
const file = await
|
|
415
|
+
const file = await this.#c.fileManager.upload(photo, params);
|
|
399
416
|
const photo_ = { _: "inputChatUploadedPhoto", file };
|
|
400
417
|
if (canBeInputChannel(peer)) {
|
|
401
|
-
await
|
|
418
|
+
await this.#c.invoke({ _: "channels.editPhoto", channel: toInputChannel(peer), photo: photo_ });
|
|
402
419
|
}
|
|
403
420
|
else if (Api.is("inputPeerChat", peer)) {
|
|
404
|
-
await
|
|
421
|
+
await this.#c.invoke({ _: "messages.editChatPhoto", chat_id: peer.chat_id, photo: photo_ });
|
|
405
422
|
}
|
|
406
423
|
}
|
|
407
424
|
// INVITING MEMBERS //
|
|
408
425
|
async addChatMember(chatId, userId, params) {
|
|
409
|
-
|
|
410
|
-
const chat = await
|
|
426
|
+
this.#c.storage.assertUser("addChatMember");
|
|
427
|
+
const chat = await this.#c.getInputPeer(chatId);
|
|
411
428
|
if (Api.isOneOf(["inputPeerEmpty", "inputPeerSelf", "inputPeerUser", "inputPeerUserFromMessage"], chat)) {
|
|
412
429
|
throw new InputError("Cannot add members to private chats");
|
|
413
430
|
}
|
|
414
|
-
const user = await
|
|
431
|
+
const user = await this.#c.getInputUser(userId);
|
|
415
432
|
if (Api.is("inputPeerChat", chat)) {
|
|
416
|
-
const result = await
|
|
433
|
+
const result = await this.#c.invoke({ _: "messages.addChatUser", chat_id: chat.chat_id, user_id: user, fwd_limit: params?.historyLimit ?? 0 });
|
|
417
434
|
return result.missing_invitees.map(constructFailedInvitation);
|
|
418
435
|
}
|
|
419
436
|
else if (Api.is("inputPeerChannel", chat)) {
|
|
420
|
-
const result = await
|
|
437
|
+
const result = await this.#c.invoke({ _: "channels.inviteToChannel", channel: { ...chat, _: "inputChannel" }, users: [user] });
|
|
421
438
|
return result.missing_invitees.map(constructFailedInvitation);
|
|
422
439
|
}
|
|
423
440
|
unreachable();
|
|
424
441
|
}
|
|
425
442
|
async addChatMembers(chatId, userIds) {
|
|
426
|
-
|
|
427
|
-
const chat = await
|
|
443
|
+
this.#c.storage.assertUser("addChatMembers");
|
|
444
|
+
const chat = await this.#c.getInputPeer(chatId);
|
|
428
445
|
if (Api.isOneOf(["inputPeerEmpty", "inputPeerSelf", "inputPeerUser", "inputPeerUserFromMessage"], chat)) {
|
|
429
446
|
throw new InputError("Cannot add members to private chats");
|
|
430
447
|
}
|
|
431
448
|
const users = new Array();
|
|
432
449
|
for (const userId of userIds) {
|
|
433
|
-
users.push(await
|
|
450
|
+
users.push(await this.#c.getInputUser(userId));
|
|
434
451
|
}
|
|
435
452
|
if (Api.is("inputPeerChat", chat)) {
|
|
436
453
|
throw new InputError("addChatMembers cannot be used with basic groups");
|
|
437
454
|
}
|
|
438
455
|
else if (canBeInputChannel(chat)) {
|
|
439
|
-
const result = await
|
|
456
|
+
const result = await this.#c.invoke({ _: "channels.inviteToChannel", channel: toInputChannel(chat), users });
|
|
440
457
|
return result.missing_invitees.map(constructFailedInvitation);
|
|
441
458
|
}
|
|
442
459
|
unreachable();
|
|
443
460
|
}
|
|
444
461
|
async getRecommendedChannels() {
|
|
445
|
-
|
|
446
|
-
const result = await
|
|
462
|
+
this.#c.storage.assertUser("getRecommendedChannels");
|
|
463
|
+
const result = await this.#c.invoke({ _: "channels.getChannelRecommendations" });
|
|
447
464
|
return result.chats.map((v) => constructChatP(v)).filter((v) => v.type === "channel");
|
|
448
465
|
}
|
|
449
466
|
async getSimilarChannels(chatId) {
|
|
450
|
-
|
|
451
|
-
const channel = await
|
|
452
|
-
const result = await
|
|
467
|
+
this.#c.storage.assertUser("getSimilarChannels");
|
|
468
|
+
const channel = await this.#c.getInputChannel(chatId);
|
|
469
|
+
const result = await this.#c.invoke({ _: "channels.getChannelRecommendations", channel });
|
|
453
470
|
return result.chats.map((v) => constructChatP(v)).filter((v) => v.type === "channel");
|
|
454
471
|
}
|
|
455
472
|
async getSimilarBots(chatId) {
|
|
456
|
-
|
|
457
|
-
const bot = await
|
|
458
|
-
const result = await
|
|
473
|
+
this.#c.storage.assertUser("getSimilarBots");
|
|
474
|
+
const bot = await this.#c.getInputUser(chatId);
|
|
475
|
+
const result = await this.#c.invoke({ _: "bots.getBotRecommendations", bot });
|
|
459
476
|
return result.users.map((v) => constructChatP(v)).filter((v) => v.type === "private");
|
|
460
477
|
}
|
|
461
478
|
}
|
|
462
|
-
_ChatManager_c = new WeakMap(), _ChatManager_instances = new WeakSet(), _ChatManager_toggleJoinRequests =
|
|
463
|
-
// JOIN REQUESTS //
|
|
464
|
-
async function _ChatManager_toggleJoinRequests(chatId, isEnabled) {
|
|
465
|
-
const channel = await __classPrivateFieldGet(this, _ChatManager_c, "f").getInputChannel(chatId);
|
|
466
|
-
await __classPrivateFieldGet(this, _ChatManager_c, "f").invoke({ _: "channels.toggleJoinRequest", channel, enabled: isEnabled });
|
|
467
|
-
}, _ChatManager_toggleSlowMode = async function _ChatManager_toggleSlowMode(chatId, seconds) {
|
|
468
|
-
const channel = await __classPrivateFieldGet(this, _ChatManager_c, "f").getInputChannel(chatId);
|
|
469
|
-
await __classPrivateFieldGet(this, _ChatManager_c, "f").invoke({ _: "channels.toggleSlowMode", channel, seconds });
|
|
470
|
-
}, _ChatManager_setIsMemberListVisible = async function _ChatManager_setIsMemberListVisible(chatId, isVisible) {
|
|
471
|
-
const channel = await __classPrivateFieldGet(this, _ChatManager_c, "f").getInputChannel(chatId);
|
|
472
|
-
const enabled = !isVisible;
|
|
473
|
-
await __classPrivateFieldGet(this, _ChatManager_c, "f").invoke({ _: "channels.toggleParticipantsHidden", channel, enabled });
|
|
474
|
-
}, _ChatManager_setIsTopicsEnabled = async function _ChatManager_setIsTopicsEnabled(chatId, isEnabled, isShownAsTabs) {
|
|
475
|
-
const channel = await __classPrivateFieldGet(this, _ChatManager_c, "f").getInputChannel(chatId);
|
|
476
|
-
await __classPrivateFieldGet(this, _ChatManager_c, "f").invoke({ _: "channels.toggleForum", channel, enabled: isEnabled, tabs: isShownAsTabs });
|
|
477
|
-
}, _ChatManager_setIsAntispamEnabled = async function _ChatManager_setIsAntispamEnabled(chatId, isEnabled) {
|
|
478
|
-
const channel = await __classPrivateFieldGet(this, _ChatManager_c, "f").getInputChannel(chatId);
|
|
479
|
-
await __classPrivateFieldGet(this, _ChatManager_c, "f").invoke({ _: "channels.toggleAntiSpam", channel, enabled: isEnabled });
|
|
480
|
-
}, _ChatManager_setIsSignaturesEnabled = async function _ChatManager_setIsSignaturesEnabled(chatId, isEnabled, params) {
|
|
481
|
-
const channel = await __classPrivateFieldGet(this, _ChatManager_c, "f").getInputChannel(chatId);
|
|
482
|
-
await __classPrivateFieldGet(this, _ChatManager_c, "f").invoke({ _: "channels.toggleSignatures", channel, signatures_enabled: isEnabled ? true : undefined, profiles_enabled: params?.showAuthorProfile ? true : undefined });
|
|
483
|
-
}, _ChatManager_setIsSharingEnabled = async function _ChatManager_setIsSharingEnabled(chatId, isSharingEnabled) {
|
|
484
|
-
const peer = await __classPrivateFieldGet(this, _ChatManager_c, "f").getInputPeer(chatId);
|
|
485
|
-
await __classPrivateFieldGet(this, _ChatManager_c, "f").invoke({ _: "messages.toggleNoForwards", peer, enabled: !isSharingEnabled });
|
|
486
|
-
};
|