@mtkruto/browser 0.119.0 → 0.119.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/0_errors.d.ts.map +1 -1
- package/esm/0_errors.js +9 -31
- package/esm/3_errors.js +2 -12
- package/esm/4_errors.js +2 -12
- package/esm/_dnt.polyfills.d.ts +0 -99
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/_dnt.polyfills.js +1 -127
- package/esm/client/0_abortable_loop.js +26 -39
- package/esm/client/0_storage_operations.js +179 -218
- package/esm/client/1_client_plain.js +4 -22
- package/esm/client/2_account_manager.js +140 -149
- package/esm/client/2_bot_info_manager.js +26 -38
- package/esm/client/2_business_connection_manager.js +10 -23
- package/esm/client/2_client_encrypted.js +198 -215
- package/esm/client/2_file_manager.js +255 -262
- package/esm/client/2_network_statistics_manager.js +31 -44
- package/esm/client/2_payment_manager.js +7 -20
- package/esm/client/2_reaction_manager.js +7 -20
- package/esm/client/2_translations_manager.js +101 -111
- package/esm/client/2_update_manager.js +750 -745
- package/esm/client/3_client_encrypted_pool.js +10 -26
- package/esm/client/3_message_manager.js +503 -508
- package/esm/client/3_video_chat_manager.js +57 -68
- package/esm/client/4_callback_query_manager.js +18 -30
- package/esm/client/4_chat_list_manager.js +140 -146
- package/esm/client/4_chat_manager.js +161 -169
- package/esm/client/4_checklist_manager.js +26 -39
- package/esm/client/4_context.js +244 -259
- package/esm/client/4_forum_manager.js +67 -73
- package/esm/client/4_gift_manager.js +22 -35
- package/esm/client/4_inline_query_manager.js +16 -28
- package/esm/client/4_link_preview_manager.js +6 -19
- package/esm/client/4_poll_manager.js +44 -57
- package/esm/client/4_story_manager.js +41 -53
- package/esm/client/5_composer.js +13 -26
- package/esm/client/6_client.js +866 -896
- package/esm/client/6_client_dispatcher.js +308 -325
- package/esm/client/7_client_worker.js +16 -29
- package/esm/connection/1_connection_tcp.js +55 -82
- package/esm/connection/1_connection_web_socket.js +75 -91
- package/esm/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
- package/esm/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +31 -47
- package/esm/deps/jsr.io/@std/async/1.2.0/tee.js +11 -34
- package/esm/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +30 -47
- package/esm/deps/jsr.io/@std/datetime/0.225.7/_date_time_formatter.js +4 -17
- package/esm/session/0_session_state.js +12 -38
- package/esm/session/1_session.js +49 -72
- package/esm/session/2_session_encrypted.js +422 -420
- package/esm/storage/2_storage_indexed_db.js +26 -44
- package/esm/storage/2_storage_local_storage.js +3 -16
- package/esm/storage/2_storage_memory.js +24 -41
- package/esm/storage/2_storage_session_storage.js +3 -16
- package/esm/tl/1_tl_reader.d.ts +1 -1
- package/esm/tl/1_tl_reader.d.ts.map +1 -1
- package/esm/tl/1_tl_reader.js +95 -103
- package/esm/tl/1_tl_writer.js +169 -178
- package/esm/transport/0_transport.js +1 -8
- package/esm/transport/1_transport_abridged.js +11 -24
- package/esm/transport/1_transport_intermediate.js +10 -23
- package/esm/utilities/0_mutex.js +4 -19
- package/esm/utilities/0_part_stream.js +11 -25
- package/esm/utilities/1_crypto.js +42 -53
- package/esm/utilities/2_queue.js +29 -47
- package/package.json +1 -1
- package/script/0_errors.d.ts.map +1 -1
- package/script/0_errors.js +9 -31
- package/script/3_errors.js +2 -12
- package/script/4_errors.js +2 -12
- package/script/_dnt.polyfills.d.ts +0 -99
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +0 -128
- package/script/client/0_abortable_loop.js +27 -40
- package/script/client/0_storage_operations.js +179 -218
- package/script/client/1_client_plain.js +4 -22
- package/script/client/2_account_manager.js +140 -149
- package/script/client/2_bot_info_manager.js +26 -38
- package/script/client/2_business_connection_manager.js +10 -23
- package/script/client/2_client_encrypted.js +199 -216
- package/script/client/2_file_manager.js +255 -262
- package/script/client/2_network_statistics_manager.js +32 -45
- package/script/client/2_payment_manager.js +7 -20
- package/script/client/2_reaction_manager.js +7 -20
- package/script/client/2_translations_manager.js +102 -112
- package/script/client/2_update_manager.js +750 -745
- package/script/client/3_client_encrypted_pool.js +10 -26
- package/script/client/3_message_manager.js +503 -508
- package/script/client/3_video_chat_manager.js +57 -68
- package/script/client/4_callback_query_manager.js +18 -30
- package/script/client/4_chat_list_manager.js +140 -146
- package/script/client/4_chat_manager.js +161 -169
- package/script/client/4_checklist_manager.js +26 -39
- package/script/client/4_context.js +244 -259
- package/script/client/4_forum_manager.js +67 -73
- package/script/client/4_gift_manager.js +22 -35
- package/script/client/4_inline_query_manager.js +16 -28
- package/script/client/4_link_preview_manager.js +6 -19
- package/script/client/4_poll_manager.js +44 -57
- package/script/client/4_story_manager.js +41 -53
- package/script/client/5_composer.js +13 -26
- package/script/client/6_client.js +866 -896
- package/script/client/6_client_dispatcher.js +308 -325
- package/script/client/7_client_worker.js +16 -29
- package/script/connection/1_connection_tcp.js +55 -82
- package/script/connection/1_connection_web_socket.js +75 -91
- package/script/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
- package/script/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +31 -47
- package/script/deps/jsr.io/@std/async/1.2.0/tee.js +11 -34
- package/script/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +30 -47
- package/script/deps/jsr.io/@std/datetime/0.225.7/_date_time_formatter.js +4 -17
- package/script/session/0_session_state.js +12 -38
- package/script/session/1_session.js +49 -72
- package/script/session/2_session_encrypted.js +423 -421
- package/script/storage/2_storage_indexed_db.js +26 -44
- package/script/storage/2_storage_local_storage.js +3 -16
- package/script/storage/2_storage_memory.js +24 -41
- package/script/storage/2_storage_session_storage.js +3 -16
- package/script/tl/1_tl_reader.d.ts +1 -1
- package/script/tl/1_tl_reader.d.ts.map +1 -1
- package/script/tl/1_tl_reader.js +96 -104
- package/script/tl/1_tl_writer.js +170 -179
- package/script/transport/0_transport.js +1 -8
- package/script/transport/1_transport_abridged.js +11 -24
- package/script/transport/1_transport_intermediate.js +10 -23
- package/script/utilities/0_mutex.js +4 -19
- package/script/utilities/0_part_stream.js +11 -25
- package/script/utilities/1_crypto.js +43 -54
- package/script/utilities/2_queue.js +30 -48
|
@@ -18,18 +18,6 @@
|
|
|
18
18
|
* You should have received a copy of the GNU Lesser General Public License
|
|
19
19
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
20
|
*/
|
|
21
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
22
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
23
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
24
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
25
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
26
|
-
};
|
|
27
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
28
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
29
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
30
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
31
|
-
};
|
|
32
|
-
var _ClientPlain_publicKeys;
|
|
33
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
22
|
exports.ClientPlain = void 0;
|
|
35
23
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
@@ -45,16 +33,11 @@ const LcreateAuthKey = L.branch("createAuthKey");
|
|
|
45
33
|
* An MTProto client for making plain connections. Most users won't need to interact with this. Used internally for creating authorization keys.
|
|
46
34
|
*/
|
|
47
35
|
class ClientPlain extends _0_client_abstract_js_1.ClientAbstract {
|
|
36
|
+
#publicKeys;
|
|
37
|
+
session;
|
|
48
38
|
constructor(dc, params) {
|
|
49
39
|
super();
|
|
50
|
-
|
|
51
|
-
Object.defineProperty(this, "session", {
|
|
52
|
-
enumerable: true,
|
|
53
|
-
configurable: true,
|
|
54
|
-
writable: true,
|
|
55
|
-
value: void 0
|
|
56
|
-
});
|
|
57
|
-
__classPrivateFieldSet(this, _ClientPlain_publicKeys, params?.publicKeys ?? _4_constants_js_1.PUBLIC_KEYS, "f");
|
|
40
|
+
this.#publicKeys = params?.publicKeys ?? _4_constants_js_1.PUBLIC_KEYS;
|
|
58
41
|
this.session = new _4_session_js_1.SessionPlain(dc, params);
|
|
59
42
|
}
|
|
60
43
|
async invoke(function_) {
|
|
@@ -92,7 +75,7 @@ class ClientPlain extends _0_client_abstract_js_1.ClientAbstract {
|
|
|
92
75
|
let publicKeyFingerprint;
|
|
93
76
|
let publicKey;
|
|
94
77
|
for (const fingerprint of resPq.server_public_key_fingerprints) {
|
|
95
|
-
const maybePublicKey =
|
|
78
|
+
const maybePublicKey = this.#publicKeys.find(([k]) => (k === fingerprint));
|
|
96
79
|
if (maybePublicKey) {
|
|
97
80
|
publicKeyFingerprint = fingerprint;
|
|
98
81
|
publicKey = maybePublicKey[1];
|
|
@@ -167,4 +150,3 @@ class ClientPlain extends _0_client_abstract_js_1.ClientAbstract {
|
|
|
167
150
|
}
|
|
168
151
|
}
|
|
169
152
|
exports.ClientPlain = ClientPlain;
|
|
170
|
-
_ClientPlain_publicKeys = new WeakMap();
|
|
@@ -18,18 +18,6 @@
|
|
|
18
18
|
* You should have received a copy of the GNU Lesser General Public License
|
|
19
19
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
20
|
*/
|
|
21
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
22
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
23
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
24
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
25
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
26
|
-
};
|
|
27
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
28
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
29
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
30
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
31
|
-
};
|
|
32
|
-
var _AccountManager_instances, _AccountManager_c, _AccountManager_toggleUsername, _AccountManager_getUserFull, _AccountManager_phoneNumber, _AccountManager_sentCode, _AccountManager_getAccountPassword, _AccountManager_ap, _AccountManager_setIsSponsoredMessagesEnabled, _AccountManager_setIsBusinessBotConnectionPaused;
|
|
33
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
22
|
exports.AccountManager = void 0;
|
|
35
23
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
@@ -43,80 +31,91 @@ const accountManagerUpdates = [
|
|
|
43
31
|
"updateUserEmojiStatus",
|
|
44
32
|
];
|
|
45
33
|
class AccountManager {
|
|
34
|
+
#c;
|
|
46
35
|
constructor(c) {
|
|
47
|
-
|
|
48
|
-
_AccountManager_c.set(this, void 0);
|
|
49
|
-
_AccountManager_phoneNumber.set(this, void 0);
|
|
50
|
-
_AccountManager_sentCode.set(this, void 0);
|
|
51
|
-
_AccountManager_ap.set(this, void 0);
|
|
52
|
-
__classPrivateFieldSet(this, _AccountManager_c, c, "f");
|
|
36
|
+
this.#c = c;
|
|
53
37
|
}
|
|
54
38
|
canHandleUpdate(update) {
|
|
55
39
|
return _2_tl_js_1.Api.isOneOf(accountManagerUpdates, update);
|
|
56
40
|
}
|
|
41
|
+
async #toggleUsername(id, username, active) {
|
|
42
|
+
const peer = await this.#c.getInputPeer(id);
|
|
43
|
+
if (_2_tl_js_1.Api.is("inputPeerSelf", peer)) {
|
|
44
|
+
await this.#c.invoke({ _: "account.toggleUsername", username, active });
|
|
45
|
+
}
|
|
46
|
+
else if ((0, _0_utilities_js_1.canBeInputUser)(peer)) {
|
|
47
|
+
await this.#c.invoke({ _: "bots.toggleUsername", bot: (0, _0_utilities_js_1.toInputUser)(peer), username, active });
|
|
48
|
+
}
|
|
49
|
+
else if ((0, _0_utilities_js_1.canBeInputChannel)(peer)) {
|
|
50
|
+
await this.#c.invoke({ _: "channels.toggleUsername", channel: (0, _0_utilities_js_1.toInputChannel)(peer), username, active });
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
(0, _0_deps_js_1.unreachable)();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
57
56
|
async showUsername(id, username) {
|
|
58
|
-
|
|
59
|
-
await
|
|
57
|
+
this.#c.storage.assertUser("showUsername");
|
|
58
|
+
await this.#toggleUsername(id, username, true);
|
|
60
59
|
}
|
|
61
60
|
async hideUsername(id, username) {
|
|
62
|
-
|
|
63
|
-
await
|
|
61
|
+
this.#c.storage.assertUser("hideUsername");
|
|
62
|
+
await this.#toggleUsername(id, username, false);
|
|
64
63
|
}
|
|
65
64
|
async checkUsername(username, params) {
|
|
66
|
-
|
|
67
|
-
const channel = params?.chatId ? await
|
|
65
|
+
this.#c.storage.assertUser("checkUsername");
|
|
66
|
+
const channel = params?.chatId ? await this.#c.getInputChannel(params.chatId) : undefined;
|
|
68
67
|
if (channel) {
|
|
69
|
-
return await
|
|
68
|
+
return await this.#c.invoke({ _: "channels.checkUsername", channel, username });
|
|
70
69
|
}
|
|
71
70
|
else {
|
|
72
|
-
return await
|
|
71
|
+
return await this.#c.invoke({ _: "account.checkUsername", username });
|
|
73
72
|
}
|
|
74
73
|
}
|
|
75
74
|
async setUsername(username) {
|
|
76
|
-
|
|
77
|
-
await
|
|
75
|
+
this.#c.storage.assertUser("setUsername");
|
|
76
|
+
await this.#c.invoke({ _: "account.updateUsername", username });
|
|
78
77
|
}
|
|
79
78
|
async removeUsername() {
|
|
80
|
-
|
|
81
|
-
await
|
|
79
|
+
this.#c.storage.assertUser("removeUsername");
|
|
80
|
+
await this.#c.invoke({ _: "account.updateUsername", username: "" });
|
|
82
81
|
}
|
|
83
82
|
async reorderUsernames(id, order) {
|
|
84
|
-
|
|
85
|
-
const peer = await
|
|
83
|
+
this.#c.storage.assertUser("reorderUsernames");
|
|
84
|
+
const peer = await this.#c.getInputPeer(id);
|
|
86
85
|
if (_2_tl_js_1.Api.is("inputPeerSelf", peer)) {
|
|
87
|
-
return await
|
|
86
|
+
return await this.#c.invoke({ _: "account.reorderUsernames", order });
|
|
88
87
|
}
|
|
89
88
|
else if ((0, _0_utilities_js_1.canBeInputUser)(peer)) {
|
|
90
|
-
return await
|
|
89
|
+
return await this.#c.invoke({ _: "bots.reorderUsernames", bot: (0, _0_utilities_js_1.toInputUser)(peer), order });
|
|
91
90
|
}
|
|
92
91
|
else if ((0, _0_utilities_js_1.canBeInputChannel)(peer)) {
|
|
93
|
-
return await
|
|
92
|
+
return await this.#c.invoke({ _: "channels.reorderUsernames", channel: (0, _0_utilities_js_1.toInputChannel)(peer), order });
|
|
94
93
|
}
|
|
95
94
|
else {
|
|
96
95
|
(0, _0_deps_js_1.unreachable)();
|
|
97
96
|
}
|
|
98
97
|
}
|
|
99
98
|
async hideUsernames(id) {
|
|
100
|
-
|
|
101
|
-
const peer = await
|
|
99
|
+
this.#c.storage.assertUser("hideUsernames");
|
|
100
|
+
const peer = await this.#c.getInputPeer(id);
|
|
102
101
|
if ((0, _0_utilities_js_1.canBeInputChannel)(peer)) {
|
|
103
|
-
return await
|
|
102
|
+
return await this.#c.invoke({ _: "channels.deactivateAllUsernames", channel: (0, _0_utilities_js_1.toInputChannel)(peer) });
|
|
104
103
|
}
|
|
105
104
|
else {
|
|
106
105
|
(0, _0_deps_js_1.unreachable)();
|
|
107
106
|
}
|
|
108
107
|
}
|
|
109
108
|
async getInactiveChats() {
|
|
110
|
-
|
|
111
|
-
const { chats, dates } = await
|
|
109
|
+
this.#c.storage.assertUser("getInactiveChats");
|
|
110
|
+
const { chats, dates } = await this.#c.invoke({ _: "channels.getInactiveChannels" });
|
|
112
111
|
return chats.map((v, i) => (0, _3_types_js_1.constructInactiveChat)(v, dates[i]));
|
|
113
112
|
}
|
|
114
113
|
async setIsOnline(isOnline) {
|
|
115
|
-
|
|
116
|
-
await
|
|
114
|
+
this.#c.storage.assertUser("setOnline");
|
|
115
|
+
await this.#c.invoke({ _: "account.updateStatus", offline: !isOnline });
|
|
117
116
|
}
|
|
118
117
|
async setEmojiStatus(emojiStatus, params) {
|
|
119
|
-
|
|
118
|
+
this.#c.storage.assertUser("setEmojiStatus");
|
|
120
119
|
let emoji_status;
|
|
121
120
|
const until = params?.until;
|
|
122
121
|
if (emojiStatus.type === "customEmoji") {
|
|
@@ -126,15 +125,15 @@ class AccountManager {
|
|
|
126
125
|
else {
|
|
127
126
|
emoji_status = { _: "inputEmojiStatusCollectible", collectible_id: BigInt(emojiStatus.giftId), until };
|
|
128
127
|
}
|
|
129
|
-
await
|
|
128
|
+
await this.#c.invoke({ _: "account.updateEmojiStatus", emoji_status });
|
|
130
129
|
}
|
|
131
130
|
async removeEmojiStatus() {
|
|
132
|
-
|
|
133
|
-
await
|
|
131
|
+
this.#c.storage.assertUser("removeEmojiStatus");
|
|
132
|
+
await this.#c.invoke({ _: "account.updateEmojiStatus", emoji_status: { _: "emojiStatusEmpty" } });
|
|
134
133
|
}
|
|
135
134
|
async setChannelEmojiStatus(chatId, emojiStatus, params) {
|
|
136
|
-
|
|
137
|
-
const channel = await
|
|
135
|
+
this.#c.storage.assertUser("setChannelEmojiStatus");
|
|
136
|
+
const channel = await this.#c.getInputChannel(chatId);
|
|
138
137
|
const until = params?.until;
|
|
139
138
|
let emoji_status;
|
|
140
139
|
if (emojiStatus.type === "customEmoji") {
|
|
@@ -144,16 +143,16 @@ class AccountManager {
|
|
|
144
143
|
else {
|
|
145
144
|
emoji_status = { _: "inputEmojiStatusCollectible", collectible_id: BigInt(emojiStatus.giftId), until };
|
|
146
145
|
}
|
|
147
|
-
await
|
|
146
|
+
await this.#c.invoke({ _: "channels.updateEmojiStatus", channel, emoji_status });
|
|
148
147
|
}
|
|
149
148
|
async removeChannelEmojiStatus(chatId) {
|
|
150
|
-
|
|
151
|
-
const channel = await
|
|
152
|
-
await
|
|
149
|
+
this.#c.storage.assertUser("removeChannelEmojiStatus");
|
|
150
|
+
const channel = await this.#c.getInputChannel(chatId);
|
|
151
|
+
await this.#c.invoke({ _: "channels.updateEmojiStatus", channel, emoji_status: { _: "emojiStatusEmpty" } });
|
|
153
152
|
}
|
|
154
153
|
async setUserEmojiStatus(userId, emojiStatus, params) {
|
|
155
|
-
|
|
156
|
-
const user_id = await
|
|
154
|
+
this.#c.storage.assertBot("setUserEmojiStatus");
|
|
155
|
+
const user_id = await this.#c.getInputUser(userId);
|
|
157
156
|
const until = params?.until;
|
|
158
157
|
let emoji_status;
|
|
159
158
|
if (emojiStatus.type === "customEmoji") {
|
|
@@ -163,43 +162,43 @@ class AccountManager {
|
|
|
163
162
|
else {
|
|
164
163
|
emoji_status = { _: "inputEmojiStatusCollectible", collectible_id: BigInt(emojiStatus.giftId), until };
|
|
165
164
|
}
|
|
166
|
-
await
|
|
165
|
+
await this.#c.invoke({ _: "bots.updateUserEmojiStatus", user_id, emoji_status });
|
|
167
166
|
}
|
|
168
167
|
async removeUserEmojiStatus(userId) {
|
|
169
|
-
|
|
170
|
-
const user_id = await
|
|
171
|
-
await
|
|
168
|
+
this.#c.storage.assertBot("removeUserEmojiStatus");
|
|
169
|
+
const user_id = await this.#c.getInputUser(userId);
|
|
170
|
+
await this.#c.invoke({ _: "bots.updateUserEmojiStatus", user_id, emoji_status: { _: "emojiStatusEmpty" } });
|
|
172
171
|
}
|
|
173
172
|
async setBotCanSetEmojiStatus(botId, canSetEmojiStatus) {
|
|
174
|
-
|
|
175
|
-
const bot = await
|
|
173
|
+
this.#c.storage.assertUser("setBotCanSetEmojiStatus");
|
|
174
|
+
const bot = await this.#c.getInputUser(botId);
|
|
176
175
|
const enabled = canSetEmojiStatus;
|
|
177
|
-
await
|
|
176
|
+
await this.#c.invoke({ _: "bots.toggleUserEmojiStatusPermission", bot, enabled });
|
|
178
177
|
}
|
|
179
178
|
async getContacts() {
|
|
180
|
-
|
|
181
|
-
const result = await
|
|
179
|
+
this.#c.storage.assertUser("getContacts");
|
|
180
|
+
const result = await this.#c.invoke({ _: "contacts.getContacts", hash: 0n });
|
|
182
181
|
if (!_2_tl_js_1.Api.is("contacts.contacts", result)) {
|
|
183
182
|
(0, _0_deps_js_1.unreachable)();
|
|
184
183
|
}
|
|
185
184
|
return result.users.map((v) => _2_tl_js_1.Api.is("user", v) ? (0, _3_types_js_1.constructUser)(v) : null).filter((v) => v !== null);
|
|
186
185
|
}
|
|
187
186
|
async deleteContacts(userIds) {
|
|
188
|
-
|
|
189
|
-
const id = await Promise.all(userIds.map((v) =>
|
|
190
|
-
await
|
|
187
|
+
this.#c.storage.assertUser("deleteContacts");
|
|
188
|
+
const id = await Promise.all(userIds.map((v) => this.#c.getInputUser(v)));
|
|
189
|
+
await this.#c.invoke({ _: "contacts.deleteContacts", id });
|
|
191
190
|
}
|
|
192
191
|
async deleteContact(userId) {
|
|
193
|
-
|
|
192
|
+
this.#c.storage.assertUser("deleteContact");
|
|
194
193
|
await this.deleteContacts([userId]);
|
|
195
194
|
}
|
|
196
195
|
async addContact(userId, params) {
|
|
197
|
-
|
|
198
|
-
const id = await
|
|
196
|
+
this.#c.storage.assertUser("addContact");
|
|
197
|
+
const id = await this.#c.getInputUser(userId);
|
|
199
198
|
if (!_2_tl_js_1.Api.is("inputPeerUser", id)) {
|
|
200
199
|
(0, _0_deps_js_1.unreachable)();
|
|
201
200
|
}
|
|
202
|
-
const peer =
|
|
201
|
+
const peer = this.#c.getPeer(_2_tl_js_1.Api.inputPeerToPeer(id));
|
|
203
202
|
if (!peer || peer[0].type !== "private") {
|
|
204
203
|
(0, _0_deps_js_1.unreachable)();
|
|
205
204
|
}
|
|
@@ -207,13 +206,31 @@ class AccountManager {
|
|
|
207
206
|
const last_name = params?.lastName ?? peer[0].lastName ?? "";
|
|
208
207
|
const phone = "";
|
|
209
208
|
const add_phone_privacy_exception = params?.sharePhoneNumber ? true : undefined;
|
|
210
|
-
await
|
|
209
|
+
await this.#c.invoke({ _: "contacts.addContact", add_phone_privacy_exception, id, first_name, last_name, phone });
|
|
210
|
+
}
|
|
211
|
+
async #getUserFull(chatId) {
|
|
212
|
+
const inputPeer = await this.#c.getInputPeer(chatId);
|
|
213
|
+
const chatId_ = await this.#c.getInputPeerChatId(inputPeer);
|
|
214
|
+
let fullChat = await this.#c.messageStorage.getFullChat(chatId_);
|
|
215
|
+
if (fullChat !== null) {
|
|
216
|
+
if (!_2_tl_js_1.Api.is("userFull", fullChat)) {
|
|
217
|
+
(0, _0_deps_js_1.unreachable)();
|
|
218
|
+
}
|
|
219
|
+
return fullChat;
|
|
220
|
+
}
|
|
221
|
+
if ((0, _0_utilities_js_1.canBeInputUser)(inputPeer)) {
|
|
222
|
+
fullChat = (await this.#c.invoke({ _: "users.getFullUser", id: (0, _0_utilities_js_1.toInputUser)(inputPeer) })).full_user;
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
(0, _0_deps_js_1.unreachable)();
|
|
226
|
+
}
|
|
227
|
+
return fullChat;
|
|
211
228
|
}
|
|
212
229
|
async updateProfile(params) {
|
|
213
|
-
|
|
214
|
-
const selfId = await
|
|
215
|
-
const userFull = await
|
|
216
|
-
const peer =
|
|
230
|
+
this.#c.storage.assertUser("updateProfile");
|
|
231
|
+
const selfId = await this.#c.getSelfId();
|
|
232
|
+
const userFull = await this.#getUserFull(selfId);
|
|
233
|
+
const peer = this.#c.getPeer(_2_tl_js_1.Api.chatIdToPeer(selfId));
|
|
217
234
|
if (!peer || peer[0].type !== "private") {
|
|
218
235
|
(0, _0_deps_js_1.unreachable)();
|
|
219
236
|
}
|
|
@@ -239,33 +256,33 @@ class AccountManager {
|
|
|
239
256
|
if (!params?.firstName && !params?.lastName && !params?.bio) {
|
|
240
257
|
throw new _0_errors_js_1.InputError("At least one parameter must be specified.");
|
|
241
258
|
}
|
|
242
|
-
await
|
|
259
|
+
await this.#c.invoke({ _: "account.updateProfile", first_name: params.firstName, last_name: params.lastName, about: params.bio });
|
|
243
260
|
}
|
|
244
261
|
async setBirthday(params) {
|
|
245
|
-
|
|
262
|
+
this.#c.storage.assertUser("setBirthday");
|
|
246
263
|
const birthday = params?.birthday ? (0, _3_types_js_1.birthdayToTlObject)(params.birthday) : undefined;
|
|
247
|
-
await
|
|
264
|
+
await this.#c.invoke({ _: "account.updateBirthday", birthday });
|
|
248
265
|
}
|
|
249
266
|
async setPersonalChannel(params) {
|
|
250
|
-
|
|
267
|
+
this.#c.storage.assertUser("setPersonalChannel");
|
|
251
268
|
let channel = { _: "inputChannelEmpty" };
|
|
252
269
|
if (params?.chatId) {
|
|
253
|
-
channel = await
|
|
270
|
+
channel = await this.#c.getInputChannel(params.chatId);
|
|
254
271
|
}
|
|
255
|
-
await
|
|
272
|
+
await this.#c.invoke({ _: "account.updatePersonalChannel", channel });
|
|
256
273
|
}
|
|
257
274
|
async setNameColor(color, params) {
|
|
258
|
-
|
|
275
|
+
this.#c.storage.assertUser("setNameColor");
|
|
259
276
|
const background_emoji_id = params?.customEmojiId ? BigInt(params.customEmojiId) : undefined;
|
|
260
|
-
await
|
|
277
|
+
await this.#c.invoke({ _: "account.updateColor", color: { _: "peerColor", color, background_emoji_id } });
|
|
261
278
|
}
|
|
262
279
|
async setProfileColor(color, params) {
|
|
263
|
-
|
|
280
|
+
this.#c.storage.assertUser("setProfileColor");
|
|
264
281
|
const background_emoji_id = params?.customEmojiId ? BigInt(params.customEmojiId) : undefined;
|
|
265
|
-
await
|
|
282
|
+
await this.#c.invoke({ _: "account.updateColor", for_profile: true, color: { _: "peerColor", color, background_emoji_id } });
|
|
266
283
|
}
|
|
267
284
|
async setLocation(params) {
|
|
268
|
-
|
|
285
|
+
this.#c.storage.assertUser("setLocation");
|
|
269
286
|
let address = params?.address;
|
|
270
287
|
if (typeof address === "string") {
|
|
271
288
|
address = address.trim();
|
|
@@ -280,36 +297,38 @@ class AccountManager {
|
|
|
280
297
|
if (params?.latitude && params.longitude) {
|
|
281
298
|
geo_point = { _: "inputGeoPoint", lat: params.latitude, long: params.longitude };
|
|
282
299
|
}
|
|
283
|
-
await
|
|
300
|
+
await this.#c.invoke({ _: "account.updateBusinessLocation", address, geo_point });
|
|
284
301
|
}
|
|
285
302
|
async setWorkingHours(params) {
|
|
286
|
-
|
|
303
|
+
this.#c.storage.assertUser("setWorkingHours");
|
|
287
304
|
let business_work_hours;
|
|
288
305
|
if (params?.workingHours) {
|
|
289
306
|
business_work_hours = (0, _3_types_js_1.workingHoursToTlObject)(params.workingHours);
|
|
290
307
|
}
|
|
291
|
-
await
|
|
308
|
+
await this.#c.invoke({ _: "account.updateBusinessWorkHours", business_work_hours });
|
|
292
309
|
}
|
|
310
|
+
#phoneNumber;
|
|
311
|
+
#sentCode;
|
|
293
312
|
async sendCode(phoneNumber, apiId, apiHash) {
|
|
294
|
-
|
|
295
|
-
|
|
313
|
+
this.#phoneNumber = phoneNumber;
|
|
314
|
+
this.#sentCode = await this.#c.invoke({
|
|
296
315
|
_: "auth.sendCode",
|
|
297
316
|
phone_number: phoneNumber,
|
|
298
317
|
api_id: apiId,
|
|
299
318
|
api_hash: apiHash,
|
|
300
319
|
settings: { _: "codeSettings" },
|
|
301
|
-
}).then((v) => _2_tl_js_1.Api.as("auth.sentCode", v))
|
|
320
|
+
}).then((v) => _2_tl_js_1.Api.as("auth.sentCode", v));
|
|
302
321
|
}
|
|
303
322
|
async checkCode(code) {
|
|
304
|
-
if (!
|
|
323
|
+
if (!this.#phoneNumber || !this.#sentCode) {
|
|
305
324
|
throw new _0_errors_js_1.InputError("Invalid sent code identifier.");
|
|
306
325
|
}
|
|
307
326
|
try {
|
|
308
|
-
const auth = await
|
|
327
|
+
const auth = await this.#c.invoke({
|
|
309
328
|
_: "auth.signIn",
|
|
310
|
-
phone_number:
|
|
329
|
+
phone_number: this.#phoneNumber,
|
|
311
330
|
phone_code: code,
|
|
312
|
-
phone_code_hash:
|
|
331
|
+
phone_code_hash: this.#sentCode.phone_code_hash,
|
|
313
332
|
});
|
|
314
333
|
return {
|
|
315
334
|
type: "signedIn",
|
|
@@ -330,17 +349,21 @@ class AccountManager {
|
|
|
330
349
|
}
|
|
331
350
|
}
|
|
332
351
|
}
|
|
352
|
+
async #getAccountPassword() {
|
|
353
|
+
return await this.#c.invoke({ _: "account.getPassword" });
|
|
354
|
+
}
|
|
355
|
+
#ap;
|
|
333
356
|
async getPasswordHint() {
|
|
334
|
-
if (!
|
|
335
|
-
|
|
357
|
+
if (!this.#ap) {
|
|
358
|
+
this.#ap = await this.#getAccountPassword();
|
|
336
359
|
}
|
|
337
|
-
return
|
|
360
|
+
return this.#ap.hint ?? "";
|
|
338
361
|
}
|
|
339
362
|
async checkPassword(password) {
|
|
340
|
-
const ap =
|
|
363
|
+
const ap = this.#ap = await this.#getAccountPassword();
|
|
341
364
|
try {
|
|
342
365
|
const input = await (0, _0_password_js_1.checkPassword)(password, ap);
|
|
343
|
-
const auth = await
|
|
366
|
+
const auth = await this.#c.invoke({ _: "auth.checkPassword", password: input });
|
|
344
367
|
return {
|
|
345
368
|
type: "signedIn",
|
|
346
369
|
userId: Number(_2_tl_js_1.Api.as("auth.authorization", auth).user.id),
|
|
@@ -358,27 +381,34 @@ class AccountManager {
|
|
|
358
381
|
}
|
|
359
382
|
}
|
|
360
383
|
async checkBotToken(botToken, apiId, apiHash) {
|
|
361
|
-
const auth = await
|
|
384
|
+
const auth = await this.#c.invoke({ _: "auth.importBotAuthorization", api_id: apiId, api_hash: apiHash, bot_auth_token: botToken, flags: 0 });
|
|
362
385
|
return {
|
|
363
386
|
type: "signedIn",
|
|
364
387
|
userId: Number(_2_tl_js_1.Api.as("auth.authorization", auth).user.id),
|
|
365
388
|
};
|
|
366
389
|
}
|
|
390
|
+
async #setIsSponsoredMessagesEnabled(isEnabled) {
|
|
391
|
+
await this.#c.invoke({ _: "account.toggleSponsoredMessages", enabled: isEnabled });
|
|
392
|
+
}
|
|
367
393
|
async enableSponsoredMessages() {
|
|
368
|
-
|
|
369
|
-
await
|
|
394
|
+
this.#c.storage.assertUser("enableSponsoredMessages");
|
|
395
|
+
await this.#setIsSponsoredMessagesEnabled(true);
|
|
370
396
|
}
|
|
371
397
|
async disableSponsoredMessages() {
|
|
372
|
-
|
|
373
|
-
await
|
|
398
|
+
this.#c.storage.assertUser("disableSponsoredMessages");
|
|
399
|
+
await this.#setIsSponsoredMessagesEnabled(false);
|
|
400
|
+
}
|
|
401
|
+
async #setIsBusinessBotConnectionPaused(chatId, isPaused) {
|
|
402
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
403
|
+
await this.#c.invoke({ _: "account.toggleConnectedBotPaused", peer, paused: isPaused });
|
|
374
404
|
}
|
|
375
405
|
async pauseBusinessBotConnection(chatId) {
|
|
376
|
-
|
|
377
|
-
await
|
|
406
|
+
this.#c.storage.assertUser("pauseBusinessBotConnection");
|
|
407
|
+
await this.#setIsBusinessBotConnectionPaused(chatId, true);
|
|
378
408
|
}
|
|
379
409
|
async resumeBusinessBotConnection(chatId) {
|
|
380
|
-
|
|
381
|
-
await
|
|
410
|
+
this.#c.storage.assertUser("resumeBusinessBotConnection");
|
|
411
|
+
await this.#setIsBusinessBotConnectionPaused(chatId, false);
|
|
382
412
|
}
|
|
383
413
|
handleUpdate(update) {
|
|
384
414
|
const userId = Number(update.user_id);
|
|
@@ -392,42 +422,3 @@ class AccountManager {
|
|
|
392
422
|
}
|
|
393
423
|
}
|
|
394
424
|
exports.AccountManager = AccountManager;
|
|
395
|
-
_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) {
|
|
396
|
-
const peer = await __classPrivateFieldGet(this, _AccountManager_c, "f").getInputPeer(id);
|
|
397
|
-
if (_2_tl_js_1.Api.is("inputPeerSelf", peer)) {
|
|
398
|
-
await __classPrivateFieldGet(this, _AccountManager_c, "f").invoke({ _: "account.toggleUsername", username, active });
|
|
399
|
-
}
|
|
400
|
-
else if ((0, _0_utilities_js_1.canBeInputUser)(peer)) {
|
|
401
|
-
await __classPrivateFieldGet(this, _AccountManager_c, "f").invoke({ _: "bots.toggleUsername", bot: (0, _0_utilities_js_1.toInputUser)(peer), username, active });
|
|
402
|
-
}
|
|
403
|
-
else if ((0, _0_utilities_js_1.canBeInputChannel)(peer)) {
|
|
404
|
-
await __classPrivateFieldGet(this, _AccountManager_c, "f").invoke({ _: "channels.toggleUsername", channel: (0, _0_utilities_js_1.toInputChannel)(peer), username, active });
|
|
405
|
-
}
|
|
406
|
-
else {
|
|
407
|
-
(0, _0_deps_js_1.unreachable)();
|
|
408
|
-
}
|
|
409
|
-
}, _AccountManager_getUserFull = async function _AccountManager_getUserFull(chatId) {
|
|
410
|
-
const inputPeer = await __classPrivateFieldGet(this, _AccountManager_c, "f").getInputPeer(chatId);
|
|
411
|
-
const chatId_ = await __classPrivateFieldGet(this, _AccountManager_c, "f").getInputPeerChatId(inputPeer);
|
|
412
|
-
let fullChat = await __classPrivateFieldGet(this, _AccountManager_c, "f").messageStorage.getFullChat(chatId_);
|
|
413
|
-
if (fullChat !== null) {
|
|
414
|
-
if (!_2_tl_js_1.Api.is("userFull", fullChat)) {
|
|
415
|
-
(0, _0_deps_js_1.unreachable)();
|
|
416
|
-
}
|
|
417
|
-
return fullChat;
|
|
418
|
-
}
|
|
419
|
-
if ((0, _0_utilities_js_1.canBeInputUser)(inputPeer)) {
|
|
420
|
-
fullChat = (await __classPrivateFieldGet(this, _AccountManager_c, "f").invoke({ _: "users.getFullUser", id: (0, _0_utilities_js_1.toInputUser)(inputPeer) })).full_user;
|
|
421
|
-
}
|
|
422
|
-
else {
|
|
423
|
-
(0, _0_deps_js_1.unreachable)();
|
|
424
|
-
}
|
|
425
|
-
return fullChat;
|
|
426
|
-
}, _AccountManager_getAccountPassword = async function _AccountManager_getAccountPassword() {
|
|
427
|
-
return await __classPrivateFieldGet(this, _AccountManager_c, "f").invoke({ _: "account.getPassword" });
|
|
428
|
-
}, _AccountManager_setIsSponsoredMessagesEnabled = async function _AccountManager_setIsSponsoredMessagesEnabled(isEnabled) {
|
|
429
|
-
await __classPrivateFieldGet(this, _AccountManager_c, "f").invoke({ _: "account.toggleSponsoredMessages", enabled: isEnabled });
|
|
430
|
-
}, _AccountManager_setIsBusinessBotConnectionPaused = async function _AccountManager_setIsBusinessBotConnectionPaused(chatId, isPaused) {
|
|
431
|
-
const peer = await __classPrivateFieldGet(this, _AccountManager_c, "f").getInputPeer(chatId);
|
|
432
|
-
await __classPrivateFieldGet(this, _AccountManager_c, "f").invoke({ _: "account.toggleConnectedBotPaused", peer, paused: isPaused });
|
|
433
|
-
};
|