@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 _ClientPlain_publicKeys;
|
|
32
20
|
import { assert, assertEquals, concat, ige256Decrypt, ige256Encrypt, unreachable } from "../0_deps.js";
|
|
33
21
|
import { factorize, getLogger, getRandomInt, intFromBytes, intToBytes, modExp, rsaPad, sha1 } from "../1_utilities.js";
|
|
34
22
|
import { Mtproto } from "../2_tl.js";
|
|
@@ -42,16 +30,11 @@ const LcreateAuthKey = L.branch("createAuthKey");
|
|
|
42
30
|
* An MTProto client for making plain connections. Most users won't need to interact with this. Used internally for creating authorization keys.
|
|
43
31
|
*/
|
|
44
32
|
export class ClientPlain extends ClientAbstract {
|
|
33
|
+
#publicKeys;
|
|
34
|
+
session;
|
|
45
35
|
constructor(dc, params) {
|
|
46
36
|
super();
|
|
47
|
-
|
|
48
|
-
Object.defineProperty(this, "session", {
|
|
49
|
-
enumerable: true,
|
|
50
|
-
configurable: true,
|
|
51
|
-
writable: true,
|
|
52
|
-
value: void 0
|
|
53
|
-
});
|
|
54
|
-
__classPrivateFieldSet(this, _ClientPlain_publicKeys, params?.publicKeys ?? PUBLIC_KEYS, "f");
|
|
37
|
+
this.#publicKeys = params?.publicKeys ?? PUBLIC_KEYS;
|
|
55
38
|
this.session = new SessionPlain(dc, params);
|
|
56
39
|
}
|
|
57
40
|
async invoke(function_) {
|
|
@@ -89,7 +72,7 @@ export class ClientPlain extends ClientAbstract {
|
|
|
89
72
|
let publicKeyFingerprint;
|
|
90
73
|
let publicKey;
|
|
91
74
|
for (const fingerprint of resPq.server_public_key_fingerprints) {
|
|
92
|
-
const maybePublicKey =
|
|
75
|
+
const maybePublicKey = this.#publicKeys.find(([k]) => (k === fingerprint));
|
|
93
76
|
if (maybePublicKey) {
|
|
94
77
|
publicKeyFingerprint = fingerprint;
|
|
95
78
|
publicKey = maybePublicKey[1];
|
|
@@ -163,4 +146,3 @@ export class ClientPlain extends ClientAbstract {
|
|
|
163
146
|
return [authKey, intFromBytes(salt)];
|
|
164
147
|
}
|
|
165
148
|
}
|
|
166
|
-
_ClientPlain_publicKeys = new WeakMap();
|
|
@@ -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 _AccountManager_instances, _AccountManager_c, _AccountManager_toggleUsername, _AccountManager_getUserFull, _AccountManager_phoneNumber, _AccountManager_sentCode, _AccountManager_getAccountPassword, _AccountManager_ap, _AccountManager_setIsSponsoredMessagesEnabled, _AccountManager_setIsBusinessBotConnectionPaused;
|
|
32
20
|
import { unreachable } from "../0_deps.js";
|
|
33
21
|
import { InputError } from "../0_errors.js";
|
|
34
22
|
import { Api } from "../2_tl.js";
|
|
@@ -40,80 +28,91 @@ const accountManagerUpdates = [
|
|
|
40
28
|
"updateUserEmojiStatus",
|
|
41
29
|
];
|
|
42
30
|
export class AccountManager {
|
|
31
|
+
#c;
|
|
43
32
|
constructor(c) {
|
|
44
|
-
|
|
45
|
-
_AccountManager_c.set(this, void 0);
|
|
46
|
-
_AccountManager_phoneNumber.set(this, void 0);
|
|
47
|
-
_AccountManager_sentCode.set(this, void 0);
|
|
48
|
-
_AccountManager_ap.set(this, void 0);
|
|
49
|
-
__classPrivateFieldSet(this, _AccountManager_c, c, "f");
|
|
33
|
+
this.#c = c;
|
|
50
34
|
}
|
|
51
35
|
canHandleUpdate(update) {
|
|
52
36
|
return Api.isOneOf(accountManagerUpdates, update);
|
|
53
37
|
}
|
|
38
|
+
async #toggleUsername(id, username, active) {
|
|
39
|
+
const peer = await this.#c.getInputPeer(id);
|
|
40
|
+
if (Api.is("inputPeerSelf", peer)) {
|
|
41
|
+
await this.#c.invoke({ _: "account.toggleUsername", username, active });
|
|
42
|
+
}
|
|
43
|
+
else if (canBeInputUser(peer)) {
|
|
44
|
+
await this.#c.invoke({ _: "bots.toggleUsername", bot: toInputUser(peer), username, active });
|
|
45
|
+
}
|
|
46
|
+
else if (canBeInputChannel(peer)) {
|
|
47
|
+
await this.#c.invoke({ _: "channels.toggleUsername", channel: toInputChannel(peer), username, active });
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
unreachable();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
54
53
|
async showUsername(id, username) {
|
|
55
|
-
|
|
56
|
-
await
|
|
54
|
+
this.#c.storage.assertUser("showUsername");
|
|
55
|
+
await this.#toggleUsername(id, username, true);
|
|
57
56
|
}
|
|
58
57
|
async hideUsername(id, username) {
|
|
59
|
-
|
|
60
|
-
await
|
|
58
|
+
this.#c.storage.assertUser("hideUsername");
|
|
59
|
+
await this.#toggleUsername(id, username, false);
|
|
61
60
|
}
|
|
62
61
|
async checkUsername(username, params) {
|
|
63
|
-
|
|
64
|
-
const channel = params?.chatId ? await
|
|
62
|
+
this.#c.storage.assertUser("checkUsername");
|
|
63
|
+
const channel = params?.chatId ? await this.#c.getInputChannel(params.chatId) : undefined;
|
|
65
64
|
if (channel) {
|
|
66
|
-
return await
|
|
65
|
+
return await this.#c.invoke({ _: "channels.checkUsername", channel, username });
|
|
67
66
|
}
|
|
68
67
|
else {
|
|
69
|
-
return await
|
|
68
|
+
return await this.#c.invoke({ _: "account.checkUsername", username });
|
|
70
69
|
}
|
|
71
70
|
}
|
|
72
71
|
async setUsername(username) {
|
|
73
|
-
|
|
74
|
-
await
|
|
72
|
+
this.#c.storage.assertUser("setUsername");
|
|
73
|
+
await this.#c.invoke({ _: "account.updateUsername", username });
|
|
75
74
|
}
|
|
76
75
|
async removeUsername() {
|
|
77
|
-
|
|
78
|
-
await
|
|
76
|
+
this.#c.storage.assertUser("removeUsername");
|
|
77
|
+
await this.#c.invoke({ _: "account.updateUsername", username: "" });
|
|
79
78
|
}
|
|
80
79
|
async reorderUsernames(id, order) {
|
|
81
|
-
|
|
82
|
-
const peer = await
|
|
80
|
+
this.#c.storage.assertUser("reorderUsernames");
|
|
81
|
+
const peer = await this.#c.getInputPeer(id);
|
|
83
82
|
if (Api.is("inputPeerSelf", peer)) {
|
|
84
|
-
return await
|
|
83
|
+
return await this.#c.invoke({ _: "account.reorderUsernames", order });
|
|
85
84
|
}
|
|
86
85
|
else if (canBeInputUser(peer)) {
|
|
87
|
-
return await
|
|
86
|
+
return await this.#c.invoke({ _: "bots.reorderUsernames", bot: toInputUser(peer), order });
|
|
88
87
|
}
|
|
89
88
|
else if (canBeInputChannel(peer)) {
|
|
90
|
-
return await
|
|
89
|
+
return await this.#c.invoke({ _: "channels.reorderUsernames", channel: toInputChannel(peer), order });
|
|
91
90
|
}
|
|
92
91
|
else {
|
|
93
92
|
unreachable();
|
|
94
93
|
}
|
|
95
94
|
}
|
|
96
95
|
async hideUsernames(id) {
|
|
97
|
-
|
|
98
|
-
const peer = await
|
|
96
|
+
this.#c.storage.assertUser("hideUsernames");
|
|
97
|
+
const peer = await this.#c.getInputPeer(id);
|
|
99
98
|
if (canBeInputChannel(peer)) {
|
|
100
|
-
return await
|
|
99
|
+
return await this.#c.invoke({ _: "channels.deactivateAllUsernames", channel: toInputChannel(peer) });
|
|
101
100
|
}
|
|
102
101
|
else {
|
|
103
102
|
unreachable();
|
|
104
103
|
}
|
|
105
104
|
}
|
|
106
105
|
async getInactiveChats() {
|
|
107
|
-
|
|
108
|
-
const { chats, dates } = await
|
|
106
|
+
this.#c.storage.assertUser("getInactiveChats");
|
|
107
|
+
const { chats, dates } = await this.#c.invoke({ _: "channels.getInactiveChannels" });
|
|
109
108
|
return chats.map((v, i) => constructInactiveChat(v, dates[i]));
|
|
110
109
|
}
|
|
111
110
|
async setIsOnline(isOnline) {
|
|
112
|
-
|
|
113
|
-
await
|
|
111
|
+
this.#c.storage.assertUser("setOnline");
|
|
112
|
+
await this.#c.invoke({ _: "account.updateStatus", offline: !isOnline });
|
|
114
113
|
}
|
|
115
114
|
async setEmojiStatus(emojiStatus, params) {
|
|
116
|
-
|
|
115
|
+
this.#c.storage.assertUser("setEmojiStatus");
|
|
117
116
|
let emoji_status;
|
|
118
117
|
const until = params?.until;
|
|
119
118
|
if (emojiStatus.type === "customEmoji") {
|
|
@@ -123,15 +122,15 @@ export class AccountManager {
|
|
|
123
122
|
else {
|
|
124
123
|
emoji_status = { _: "inputEmojiStatusCollectible", collectible_id: BigInt(emojiStatus.giftId), until };
|
|
125
124
|
}
|
|
126
|
-
await
|
|
125
|
+
await this.#c.invoke({ _: "account.updateEmojiStatus", emoji_status });
|
|
127
126
|
}
|
|
128
127
|
async removeEmojiStatus() {
|
|
129
|
-
|
|
130
|
-
await
|
|
128
|
+
this.#c.storage.assertUser("removeEmojiStatus");
|
|
129
|
+
await this.#c.invoke({ _: "account.updateEmojiStatus", emoji_status: { _: "emojiStatusEmpty" } });
|
|
131
130
|
}
|
|
132
131
|
async setChannelEmojiStatus(chatId, emojiStatus, params) {
|
|
133
|
-
|
|
134
|
-
const channel = await
|
|
132
|
+
this.#c.storage.assertUser("setChannelEmojiStatus");
|
|
133
|
+
const channel = await this.#c.getInputChannel(chatId);
|
|
135
134
|
const until = params?.until;
|
|
136
135
|
let emoji_status;
|
|
137
136
|
if (emojiStatus.type === "customEmoji") {
|
|
@@ -141,16 +140,16 @@ export class AccountManager {
|
|
|
141
140
|
else {
|
|
142
141
|
emoji_status = { _: "inputEmojiStatusCollectible", collectible_id: BigInt(emojiStatus.giftId), until };
|
|
143
142
|
}
|
|
144
|
-
await
|
|
143
|
+
await this.#c.invoke({ _: "channels.updateEmojiStatus", channel, emoji_status });
|
|
145
144
|
}
|
|
146
145
|
async removeChannelEmojiStatus(chatId) {
|
|
147
|
-
|
|
148
|
-
const channel = await
|
|
149
|
-
await
|
|
146
|
+
this.#c.storage.assertUser("removeChannelEmojiStatus");
|
|
147
|
+
const channel = await this.#c.getInputChannel(chatId);
|
|
148
|
+
await this.#c.invoke({ _: "channels.updateEmojiStatus", channel, emoji_status: { _: "emojiStatusEmpty" } });
|
|
150
149
|
}
|
|
151
150
|
async setUserEmojiStatus(userId, emojiStatus, params) {
|
|
152
|
-
|
|
153
|
-
const user_id = await
|
|
151
|
+
this.#c.storage.assertBot("setUserEmojiStatus");
|
|
152
|
+
const user_id = await this.#c.getInputUser(userId);
|
|
154
153
|
const until = params?.until;
|
|
155
154
|
let emoji_status;
|
|
156
155
|
if (emojiStatus.type === "customEmoji") {
|
|
@@ -160,43 +159,43 @@ export class AccountManager {
|
|
|
160
159
|
else {
|
|
161
160
|
emoji_status = { _: "inputEmojiStatusCollectible", collectible_id: BigInt(emojiStatus.giftId), until };
|
|
162
161
|
}
|
|
163
|
-
await
|
|
162
|
+
await this.#c.invoke({ _: "bots.updateUserEmojiStatus", user_id, emoji_status });
|
|
164
163
|
}
|
|
165
164
|
async removeUserEmojiStatus(userId) {
|
|
166
|
-
|
|
167
|
-
const user_id = await
|
|
168
|
-
await
|
|
165
|
+
this.#c.storage.assertBot("removeUserEmojiStatus");
|
|
166
|
+
const user_id = await this.#c.getInputUser(userId);
|
|
167
|
+
await this.#c.invoke({ _: "bots.updateUserEmojiStatus", user_id, emoji_status: { _: "emojiStatusEmpty" } });
|
|
169
168
|
}
|
|
170
169
|
async setBotCanSetEmojiStatus(botId, canSetEmojiStatus) {
|
|
171
|
-
|
|
172
|
-
const bot = await
|
|
170
|
+
this.#c.storage.assertUser("setBotCanSetEmojiStatus");
|
|
171
|
+
const bot = await this.#c.getInputUser(botId);
|
|
173
172
|
const enabled = canSetEmojiStatus;
|
|
174
|
-
await
|
|
173
|
+
await this.#c.invoke({ _: "bots.toggleUserEmojiStatusPermission", bot, enabled });
|
|
175
174
|
}
|
|
176
175
|
async getContacts() {
|
|
177
|
-
|
|
178
|
-
const result = await
|
|
176
|
+
this.#c.storage.assertUser("getContacts");
|
|
177
|
+
const result = await this.#c.invoke({ _: "contacts.getContacts", hash: 0n });
|
|
179
178
|
if (!Api.is("contacts.contacts", result)) {
|
|
180
179
|
unreachable();
|
|
181
180
|
}
|
|
182
181
|
return result.users.map((v) => Api.is("user", v) ? constructUser(v) : null).filter((v) => v !== null);
|
|
183
182
|
}
|
|
184
183
|
async deleteContacts(userIds) {
|
|
185
|
-
|
|
186
|
-
const id = await Promise.all(userIds.map((v) =>
|
|
187
|
-
await
|
|
184
|
+
this.#c.storage.assertUser("deleteContacts");
|
|
185
|
+
const id = await Promise.all(userIds.map((v) => this.#c.getInputUser(v)));
|
|
186
|
+
await this.#c.invoke({ _: "contacts.deleteContacts", id });
|
|
188
187
|
}
|
|
189
188
|
async deleteContact(userId) {
|
|
190
|
-
|
|
189
|
+
this.#c.storage.assertUser("deleteContact");
|
|
191
190
|
await this.deleteContacts([userId]);
|
|
192
191
|
}
|
|
193
192
|
async addContact(userId, params) {
|
|
194
|
-
|
|
195
|
-
const id = await
|
|
193
|
+
this.#c.storage.assertUser("addContact");
|
|
194
|
+
const id = await this.#c.getInputUser(userId);
|
|
196
195
|
if (!Api.is("inputPeerUser", id)) {
|
|
197
196
|
unreachable();
|
|
198
197
|
}
|
|
199
|
-
const peer =
|
|
198
|
+
const peer = this.#c.getPeer(Api.inputPeerToPeer(id));
|
|
200
199
|
if (!peer || peer[0].type !== "private") {
|
|
201
200
|
unreachable();
|
|
202
201
|
}
|
|
@@ -204,13 +203,31 @@ export class AccountManager {
|
|
|
204
203
|
const last_name = params?.lastName ?? peer[0].lastName ?? "";
|
|
205
204
|
const phone = "";
|
|
206
205
|
const add_phone_privacy_exception = params?.sharePhoneNumber ? true : undefined;
|
|
207
|
-
await
|
|
206
|
+
await this.#c.invoke({ _: "contacts.addContact", add_phone_privacy_exception, id, first_name, last_name, phone });
|
|
207
|
+
}
|
|
208
|
+
async #getUserFull(chatId) {
|
|
209
|
+
const inputPeer = await this.#c.getInputPeer(chatId);
|
|
210
|
+
const chatId_ = await this.#c.getInputPeerChatId(inputPeer);
|
|
211
|
+
let fullChat = await this.#c.messageStorage.getFullChat(chatId_);
|
|
212
|
+
if (fullChat !== null) {
|
|
213
|
+
if (!Api.is("userFull", fullChat)) {
|
|
214
|
+
unreachable();
|
|
215
|
+
}
|
|
216
|
+
return fullChat;
|
|
217
|
+
}
|
|
218
|
+
if (canBeInputUser(inputPeer)) {
|
|
219
|
+
fullChat = (await this.#c.invoke({ _: "users.getFullUser", id: toInputUser(inputPeer) })).full_user;
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
unreachable();
|
|
223
|
+
}
|
|
224
|
+
return fullChat;
|
|
208
225
|
}
|
|
209
226
|
async updateProfile(params) {
|
|
210
|
-
|
|
211
|
-
const selfId = await
|
|
212
|
-
const userFull = await
|
|
213
|
-
const peer =
|
|
227
|
+
this.#c.storage.assertUser("updateProfile");
|
|
228
|
+
const selfId = await this.#c.getSelfId();
|
|
229
|
+
const userFull = await this.#getUserFull(selfId);
|
|
230
|
+
const peer = this.#c.getPeer(Api.chatIdToPeer(selfId));
|
|
214
231
|
if (!peer || peer[0].type !== "private") {
|
|
215
232
|
unreachable();
|
|
216
233
|
}
|
|
@@ -236,33 +253,33 @@ export class AccountManager {
|
|
|
236
253
|
if (!params?.firstName && !params?.lastName && !params?.bio) {
|
|
237
254
|
throw new InputError("At least one parameter must be specified.");
|
|
238
255
|
}
|
|
239
|
-
await
|
|
256
|
+
await this.#c.invoke({ _: "account.updateProfile", first_name: params.firstName, last_name: params.lastName, about: params.bio });
|
|
240
257
|
}
|
|
241
258
|
async setBirthday(params) {
|
|
242
|
-
|
|
259
|
+
this.#c.storage.assertUser("setBirthday");
|
|
243
260
|
const birthday = params?.birthday ? birthdayToTlObject(params.birthday) : undefined;
|
|
244
|
-
await
|
|
261
|
+
await this.#c.invoke({ _: "account.updateBirthday", birthday });
|
|
245
262
|
}
|
|
246
263
|
async setPersonalChannel(params) {
|
|
247
|
-
|
|
264
|
+
this.#c.storage.assertUser("setPersonalChannel");
|
|
248
265
|
let channel = { _: "inputChannelEmpty" };
|
|
249
266
|
if (params?.chatId) {
|
|
250
|
-
channel = await
|
|
267
|
+
channel = await this.#c.getInputChannel(params.chatId);
|
|
251
268
|
}
|
|
252
|
-
await
|
|
269
|
+
await this.#c.invoke({ _: "account.updatePersonalChannel", channel });
|
|
253
270
|
}
|
|
254
271
|
async setNameColor(color, params) {
|
|
255
|
-
|
|
272
|
+
this.#c.storage.assertUser("setNameColor");
|
|
256
273
|
const background_emoji_id = params?.customEmojiId ? BigInt(params.customEmojiId) : undefined;
|
|
257
|
-
await
|
|
274
|
+
await this.#c.invoke({ _: "account.updateColor", color: { _: "peerColor", color, background_emoji_id } });
|
|
258
275
|
}
|
|
259
276
|
async setProfileColor(color, params) {
|
|
260
|
-
|
|
277
|
+
this.#c.storage.assertUser("setProfileColor");
|
|
261
278
|
const background_emoji_id = params?.customEmojiId ? BigInt(params.customEmojiId) : undefined;
|
|
262
|
-
await
|
|
279
|
+
await this.#c.invoke({ _: "account.updateColor", for_profile: true, color: { _: "peerColor", color, background_emoji_id } });
|
|
263
280
|
}
|
|
264
281
|
async setLocation(params) {
|
|
265
|
-
|
|
282
|
+
this.#c.storage.assertUser("setLocation");
|
|
266
283
|
let address = params?.address;
|
|
267
284
|
if (typeof address === "string") {
|
|
268
285
|
address = address.trim();
|
|
@@ -277,36 +294,38 @@ export class AccountManager {
|
|
|
277
294
|
if (params?.latitude && params.longitude) {
|
|
278
295
|
geo_point = { _: "inputGeoPoint", lat: params.latitude, long: params.longitude };
|
|
279
296
|
}
|
|
280
|
-
await
|
|
297
|
+
await this.#c.invoke({ _: "account.updateBusinessLocation", address, geo_point });
|
|
281
298
|
}
|
|
282
299
|
async setWorkingHours(params) {
|
|
283
|
-
|
|
300
|
+
this.#c.storage.assertUser("setWorkingHours");
|
|
284
301
|
let business_work_hours;
|
|
285
302
|
if (params?.workingHours) {
|
|
286
303
|
business_work_hours = workingHoursToTlObject(params.workingHours);
|
|
287
304
|
}
|
|
288
|
-
await
|
|
305
|
+
await this.#c.invoke({ _: "account.updateBusinessWorkHours", business_work_hours });
|
|
289
306
|
}
|
|
307
|
+
#phoneNumber;
|
|
308
|
+
#sentCode;
|
|
290
309
|
async sendCode(phoneNumber, apiId, apiHash) {
|
|
291
|
-
|
|
292
|
-
|
|
310
|
+
this.#phoneNumber = phoneNumber;
|
|
311
|
+
this.#sentCode = await this.#c.invoke({
|
|
293
312
|
_: "auth.sendCode",
|
|
294
313
|
phone_number: phoneNumber,
|
|
295
314
|
api_id: apiId,
|
|
296
315
|
api_hash: apiHash,
|
|
297
316
|
settings: { _: "codeSettings" },
|
|
298
|
-
}).then((v) => Api.as("auth.sentCode", v))
|
|
317
|
+
}).then((v) => Api.as("auth.sentCode", v));
|
|
299
318
|
}
|
|
300
319
|
async checkCode(code) {
|
|
301
|
-
if (!
|
|
320
|
+
if (!this.#phoneNumber || !this.#sentCode) {
|
|
302
321
|
throw new InputError("Invalid sent code identifier.");
|
|
303
322
|
}
|
|
304
323
|
try {
|
|
305
|
-
const auth = await
|
|
324
|
+
const auth = await this.#c.invoke({
|
|
306
325
|
_: "auth.signIn",
|
|
307
|
-
phone_number:
|
|
326
|
+
phone_number: this.#phoneNumber,
|
|
308
327
|
phone_code: code,
|
|
309
|
-
phone_code_hash:
|
|
328
|
+
phone_code_hash: this.#sentCode.phone_code_hash,
|
|
310
329
|
});
|
|
311
330
|
return {
|
|
312
331
|
type: "signedIn",
|
|
@@ -327,17 +346,21 @@ export class AccountManager {
|
|
|
327
346
|
}
|
|
328
347
|
}
|
|
329
348
|
}
|
|
349
|
+
async #getAccountPassword() {
|
|
350
|
+
return await this.#c.invoke({ _: "account.getPassword" });
|
|
351
|
+
}
|
|
352
|
+
#ap;
|
|
330
353
|
async getPasswordHint() {
|
|
331
|
-
if (!
|
|
332
|
-
|
|
354
|
+
if (!this.#ap) {
|
|
355
|
+
this.#ap = await this.#getAccountPassword();
|
|
333
356
|
}
|
|
334
|
-
return
|
|
357
|
+
return this.#ap.hint ?? "";
|
|
335
358
|
}
|
|
336
359
|
async checkPassword(password) {
|
|
337
|
-
const ap =
|
|
360
|
+
const ap = this.#ap = await this.#getAccountPassword();
|
|
338
361
|
try {
|
|
339
362
|
const input = await checkPassword(password, ap);
|
|
340
|
-
const auth = await
|
|
363
|
+
const auth = await this.#c.invoke({ _: "auth.checkPassword", password: input });
|
|
341
364
|
return {
|
|
342
365
|
type: "signedIn",
|
|
343
366
|
userId: Number(Api.as("auth.authorization", auth).user.id),
|
|
@@ -355,27 +378,34 @@ export class AccountManager {
|
|
|
355
378
|
}
|
|
356
379
|
}
|
|
357
380
|
async checkBotToken(botToken, apiId, apiHash) {
|
|
358
|
-
const auth = await
|
|
381
|
+
const auth = await this.#c.invoke({ _: "auth.importBotAuthorization", api_id: apiId, api_hash: apiHash, bot_auth_token: botToken, flags: 0 });
|
|
359
382
|
return {
|
|
360
383
|
type: "signedIn",
|
|
361
384
|
userId: Number(Api.as("auth.authorization", auth).user.id),
|
|
362
385
|
};
|
|
363
386
|
}
|
|
387
|
+
async #setIsSponsoredMessagesEnabled(isEnabled) {
|
|
388
|
+
await this.#c.invoke({ _: "account.toggleSponsoredMessages", enabled: isEnabled });
|
|
389
|
+
}
|
|
364
390
|
async enableSponsoredMessages() {
|
|
365
|
-
|
|
366
|
-
await
|
|
391
|
+
this.#c.storage.assertUser("enableSponsoredMessages");
|
|
392
|
+
await this.#setIsSponsoredMessagesEnabled(true);
|
|
367
393
|
}
|
|
368
394
|
async disableSponsoredMessages() {
|
|
369
|
-
|
|
370
|
-
await
|
|
395
|
+
this.#c.storage.assertUser("disableSponsoredMessages");
|
|
396
|
+
await this.#setIsSponsoredMessagesEnabled(false);
|
|
397
|
+
}
|
|
398
|
+
async #setIsBusinessBotConnectionPaused(chatId, isPaused) {
|
|
399
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
400
|
+
await this.#c.invoke({ _: "account.toggleConnectedBotPaused", peer, paused: isPaused });
|
|
371
401
|
}
|
|
372
402
|
async pauseBusinessBotConnection(chatId) {
|
|
373
|
-
|
|
374
|
-
await
|
|
403
|
+
this.#c.storage.assertUser("pauseBusinessBotConnection");
|
|
404
|
+
await this.#setIsBusinessBotConnectionPaused(chatId, true);
|
|
375
405
|
}
|
|
376
406
|
async resumeBusinessBotConnection(chatId) {
|
|
377
|
-
|
|
378
|
-
await
|
|
407
|
+
this.#c.storage.assertUser("resumeBusinessBotConnection");
|
|
408
|
+
await this.#setIsBusinessBotConnectionPaused(chatId, false);
|
|
379
409
|
}
|
|
380
410
|
handleUpdate(update) {
|
|
381
411
|
const userId = Number(update.user_id);
|
|
@@ -388,42 +418,3 @@ export class AccountManager {
|
|
|
388
418
|
}
|
|
389
419
|
}
|
|
390
420
|
}
|
|
391
|
-
_AccountManager_c = new WeakMap(), _AccountManager_phoneNumber = new WeakMap(), _AccountManager_sentCode = new WeakMap(), _AccountManager_ap = new WeakMap(), _AccountManager_instances = new WeakSet(), _AccountManager_toggleUsername = async function _AccountManager_toggleUsername(id, username, active) {
|
|
392
|
-
const peer = await __classPrivateFieldGet(this, _AccountManager_c, "f").getInputPeer(id);
|
|
393
|
-
if (Api.is("inputPeerSelf", peer)) {
|
|
394
|
-
await __classPrivateFieldGet(this, _AccountManager_c, "f").invoke({ _: "account.toggleUsername", username, active });
|
|
395
|
-
}
|
|
396
|
-
else if (canBeInputUser(peer)) {
|
|
397
|
-
await __classPrivateFieldGet(this, _AccountManager_c, "f").invoke({ _: "bots.toggleUsername", bot: toInputUser(peer), username, active });
|
|
398
|
-
}
|
|
399
|
-
else if (canBeInputChannel(peer)) {
|
|
400
|
-
await __classPrivateFieldGet(this, _AccountManager_c, "f").invoke({ _: "channels.toggleUsername", channel: toInputChannel(peer), username, active });
|
|
401
|
-
}
|
|
402
|
-
else {
|
|
403
|
-
unreachable();
|
|
404
|
-
}
|
|
405
|
-
}, _AccountManager_getUserFull = async function _AccountManager_getUserFull(chatId) {
|
|
406
|
-
const inputPeer = await __classPrivateFieldGet(this, _AccountManager_c, "f").getInputPeer(chatId);
|
|
407
|
-
const chatId_ = await __classPrivateFieldGet(this, _AccountManager_c, "f").getInputPeerChatId(inputPeer);
|
|
408
|
-
let fullChat = await __classPrivateFieldGet(this, _AccountManager_c, "f").messageStorage.getFullChat(chatId_);
|
|
409
|
-
if (fullChat !== null) {
|
|
410
|
-
if (!Api.is("userFull", fullChat)) {
|
|
411
|
-
unreachable();
|
|
412
|
-
}
|
|
413
|
-
return fullChat;
|
|
414
|
-
}
|
|
415
|
-
if (canBeInputUser(inputPeer)) {
|
|
416
|
-
fullChat = (await __classPrivateFieldGet(this, _AccountManager_c, "f").invoke({ _: "users.getFullUser", id: toInputUser(inputPeer) })).full_user;
|
|
417
|
-
}
|
|
418
|
-
else {
|
|
419
|
-
unreachable();
|
|
420
|
-
}
|
|
421
|
-
return fullChat;
|
|
422
|
-
}, _AccountManager_getAccountPassword = async function _AccountManager_getAccountPassword() {
|
|
423
|
-
return await __classPrivateFieldGet(this, _AccountManager_c, "f").invoke({ _: "account.getPassword" });
|
|
424
|
-
}, _AccountManager_setIsSponsoredMessagesEnabled = async function _AccountManager_setIsSponsoredMessagesEnabled(isEnabled) {
|
|
425
|
-
await __classPrivateFieldGet(this, _AccountManager_c, "f").invoke({ _: "account.toggleSponsoredMessages", enabled: isEnabled });
|
|
426
|
-
}, _AccountManager_setIsBusinessBotConnectionPaused = async function _AccountManager_setIsBusinessBotConnectionPaused(chatId, isPaused) {
|
|
427
|
-
const peer = await __classPrivateFieldGet(this, _AccountManager_c, "f").getInputPeer(chatId);
|
|
428
|
-
await __classPrivateFieldGet(this, _AccountManager_c, "f").invoke({ _: "account.toggleConnectedBotPaused", peer, paused: isPaused });
|
|
429
|
-
};
|