@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 _StoryManager_instances, _StoryManager_c, _StoryManager_updatesToStory, _StoryManager_togglePinned;
|
|
32
20
|
import { contentType, unreachable } from "../0_deps.js";
|
|
33
21
|
import { InputError } from "../0_errors.js";
|
|
34
22
|
import { getRandomId } from "../1_utilities.js";
|
|
@@ -39,17 +27,25 @@ const storyManagerUpdates = [
|
|
|
39
27
|
"updateStory",
|
|
40
28
|
];
|
|
41
29
|
export class StoryManager {
|
|
30
|
+
#c;
|
|
42
31
|
constructor(c) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
32
|
+
this.#c = c;
|
|
33
|
+
}
|
|
34
|
+
#updatesToStory(updates) {
|
|
35
|
+
if (Api.is("updates", updates)) {
|
|
36
|
+
const updateStory = updates.updates.find((v) => Api.is("updateStory", v));
|
|
37
|
+
if (updateStory && Api.is("storyItem", updateStory.story)) {
|
|
38
|
+
return constructStory(updateStory.story, updateStory.peer, this.#c.getPeer);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
unreachable();
|
|
46
42
|
}
|
|
47
43
|
async createStory(chatId, content, params) {
|
|
48
|
-
|
|
44
|
+
this.#c.storage.assertUser("createStory");
|
|
49
45
|
let media = null;
|
|
50
46
|
const source = "video" in content ? content.video : "photo" in content ? content.photo : unreachable();
|
|
51
47
|
if (typeof source === "string") {
|
|
52
|
-
const fileId =
|
|
48
|
+
const fileId = this.#c.messageManager.resolveFileId(source, FileType.Photo);
|
|
53
49
|
if (fileId !== null) {
|
|
54
50
|
media = { _: "inputMediaPhoto", id: { ...fileId, _: "inputPhoto" } };
|
|
55
51
|
}
|
|
@@ -59,7 +55,7 @@ export class StoryManager {
|
|
|
59
55
|
throw new InputError("URL not supported.");
|
|
60
56
|
}
|
|
61
57
|
else {
|
|
62
|
-
const file = await
|
|
58
|
+
const file = await this.#c.fileManager.upload(source, params, null, "video" in content);
|
|
63
59
|
if (Api.is("inputFileStoryDocument", file)) {
|
|
64
60
|
unreachable();
|
|
65
61
|
}
|
|
@@ -73,59 +69,64 @@ export class StoryManager {
|
|
|
73
69
|
}
|
|
74
70
|
}
|
|
75
71
|
const caption_ = params?.caption;
|
|
76
|
-
const parseResult = caption_ !== undefined ? await
|
|
72
|
+
const parseResult = caption_ !== undefined ? await this.#c.messageManager.parseText(caption_, { parseMode: params?.parseMode, entities: params?.captionEntities }) : undefined;
|
|
77
73
|
const caption = parseResult === undefined ? undefined : parseResult[0];
|
|
78
74
|
const entities = parseResult === undefined ? undefined : parseResult[1];
|
|
79
|
-
const peer = await
|
|
75
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
80
76
|
const randomId = getRandomId();
|
|
81
|
-
const privacyRules = await storyPrivacyToTlObject(params?.privacy ?? { everyoneExcept: [] },
|
|
77
|
+
const privacyRules = await storyPrivacyToTlObject(params?.privacy ?? { everyoneExcept: [] }, this.#c.getPeer);
|
|
82
78
|
const mediaAreas = new Array();
|
|
83
79
|
if (params?.interactiveAreas?.length) {
|
|
84
80
|
for (const area of params.interactiveAreas) {
|
|
85
|
-
mediaAreas.push(await storyInteractiveAreaToTlObject(area,
|
|
81
|
+
mediaAreas.push(await storyInteractiveAreaToTlObject(area, this.#c.getPeer));
|
|
86
82
|
}
|
|
87
83
|
}
|
|
88
|
-
const updates = await
|
|
89
|
-
return await
|
|
84
|
+
const updates = await this.#c.invoke({ _: "stories.sendStory", peer, random_id: randomId, media, privacy_rules: privacyRules, caption, entities, noforwards: params?.isContentProtected ? true : undefined, period: params?.activeFor, pinned: params?.highlight ? true : undefined, media_areas: mediaAreas });
|
|
85
|
+
return await this.#updatesToStory(updates);
|
|
90
86
|
}
|
|
91
87
|
async getStories(chatId, storyIds) {
|
|
92
|
-
|
|
88
|
+
this.#c.storage.assertUser("getStories");
|
|
93
89
|
checkArray(storyIds, checkStoryId);
|
|
94
|
-
const peer = await
|
|
95
|
-
const stories_ = await
|
|
90
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
91
|
+
const stories_ = await this.#c.invoke({ _: "stories.getStoriesByID", peer, id: storyIds });
|
|
96
92
|
const stories = new Array();
|
|
97
93
|
for (const story of stories_.stories) {
|
|
98
|
-
stories.push(constructStory(Api.as("storyItem", story), Api.inputPeerToPeer(peer),
|
|
94
|
+
stories.push(constructStory(Api.as("storyItem", story), Api.inputPeerToPeer(peer), this.#c.getPeer));
|
|
99
95
|
}
|
|
100
96
|
return stories;
|
|
101
97
|
}
|
|
102
98
|
async getStory(chatId, storyId) {
|
|
103
|
-
|
|
99
|
+
this.#c.storage.assertUser("getStory");
|
|
104
100
|
return (await this.getStories(chatId, [storyId]))[0] ?? null;
|
|
105
101
|
}
|
|
106
102
|
async deleteStories(chatId, storyIds) {
|
|
107
|
-
|
|
108
|
-
const peer = await
|
|
109
|
-
await
|
|
103
|
+
this.#c.storage.assertUser("deleteStories");
|
|
104
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
105
|
+
await this.#c.invoke({ _: "stories.deleteStories", peer, id: storyIds });
|
|
110
106
|
}
|
|
111
107
|
async deleteStory(chatId, storyId) {
|
|
112
|
-
|
|
108
|
+
this.#c.storage.assertUser("deleteStory");
|
|
113
109
|
await this.deleteStories(chatId, [storyId]);
|
|
114
110
|
}
|
|
111
|
+
async #togglePinned(chatId, storyIds, pinned) {
|
|
112
|
+
checkArray(storyIds, checkStoryId);
|
|
113
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
114
|
+
await this.#c.invoke({ _: "stories.togglePinned", peer, id: storyIds, pinned });
|
|
115
|
+
}
|
|
115
116
|
async addStoriesToHighlights(chatId, storyIds) {
|
|
116
|
-
|
|
117
|
-
await
|
|
117
|
+
this.#c.storage.assertUser("addStoriesToHighlights");
|
|
118
|
+
await this.#togglePinned(chatId, storyIds, true);
|
|
118
119
|
}
|
|
119
120
|
async addStoryToHighlights(chatId, storyId) {
|
|
120
|
-
|
|
121
|
+
this.#c.storage.assertUser("addStoryToHighlights");
|
|
121
122
|
await this.addStoriesToHighlights(chatId, [storyId]);
|
|
122
123
|
}
|
|
123
124
|
async removeStoriesFromHighlights(chatId, storyIds) {
|
|
124
|
-
|
|
125
|
-
await
|
|
125
|
+
this.#c.storage.assertUser("removeStoriesFromHighlights");
|
|
126
|
+
await this.#togglePinned(chatId, storyIds, false);
|
|
126
127
|
}
|
|
127
128
|
async removeStoryFromHighlights(chatId, storyId) {
|
|
128
|
-
|
|
129
|
+
this.#c.storage.assertUser("removeStoryFromHighlights");
|
|
129
130
|
await this.removeStoriesFromHighlights(chatId, [storyId]);
|
|
130
131
|
}
|
|
131
132
|
canHandleUpdate(update) {
|
|
@@ -138,7 +139,7 @@ export class StoryManager {
|
|
|
138
139
|
return { deletedStory: { chatId, storyId } };
|
|
139
140
|
}
|
|
140
141
|
else if (Api.is("storyItem", update.story)) {
|
|
141
|
-
const story = constructStory(update.story, update.peer,
|
|
142
|
+
const story = constructStory(update.story, update.peer, this.#c.getPeer);
|
|
142
143
|
return { story };
|
|
143
144
|
}
|
|
144
145
|
else {
|
|
@@ -146,16 +147,3 @@ export class StoryManager {
|
|
|
146
147
|
}
|
|
147
148
|
}
|
|
148
149
|
}
|
|
149
|
-
_StoryManager_c = new WeakMap(), _StoryManager_instances = new WeakSet(), _StoryManager_updatesToStory = function _StoryManager_updatesToStory(updates) {
|
|
150
|
-
if (Api.is("updates", updates)) {
|
|
151
|
-
const updateStory = updates.updates.find((v) => Api.is("updateStory", v));
|
|
152
|
-
if (updateStory && Api.is("storyItem", updateStory.story)) {
|
|
153
|
-
return constructStory(updateStory.story, updateStory.peer, __classPrivateFieldGet(this, _StoryManager_c, "f").getPeer);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
unreachable();
|
|
157
|
-
}, _StoryManager_togglePinned = async function _StoryManager_togglePinned(chatId, storyIds, pinned) {
|
|
158
|
-
checkArray(storyIds, checkStoryId);
|
|
159
|
-
const peer = await __classPrivateFieldGet(this, _StoryManager_c, "f").getInputPeer(chatId);
|
|
160
|
-
await __classPrivateFieldGet(this, _StoryManager_c, "f").invoke({ _: "stories.togglePinned", peer, id: storyIds, pinned });
|
|
161
|
-
};
|
package/esm/client/5_composer.js
CHANGED
|
@@ -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 __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
21
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
22
|
-
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");
|
|
23
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
24
|
-
};
|
|
25
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
26
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
27
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
28
|
-
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");
|
|
29
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
30
|
-
};
|
|
31
|
-
var _Composer_handle, _Composer_prefixes, _Composer_lastGetMe;
|
|
32
20
|
import { InputError } from "../0_errors.js";
|
|
33
21
|
import { Context } from "./4_context.js";
|
|
34
22
|
export function flatten(mw) {
|
|
@@ -52,32 +40,32 @@ export function skip(_ctx, next) {
|
|
|
52
40
|
return next();
|
|
53
41
|
}
|
|
54
42
|
export class Composer {
|
|
43
|
+
#handle;
|
|
44
|
+
#prefixes;
|
|
55
45
|
set prefixes(value) {
|
|
56
|
-
if (
|
|
46
|
+
if (this.#prefixes !== undefined) {
|
|
57
47
|
throw new InputError("Prefixes already set");
|
|
58
48
|
}
|
|
59
|
-
|
|
49
|
+
this.#prefixes = value;
|
|
60
50
|
}
|
|
61
51
|
constructor(...middleware) {
|
|
62
|
-
|
|
63
|
-
_Composer_prefixes.set(this, void 0);
|
|
64
|
-
_Composer_lastGetMe.set(this, void 0);
|
|
65
|
-
__classPrivateFieldSet(this, _Composer_handle, middleware.length === 0 ? skip : middleware.map(flatten).reduce(concat), "f");
|
|
52
|
+
this.#handle = middleware.length === 0 ? skip : middleware.map(flatten).reduce(concat);
|
|
66
53
|
}
|
|
54
|
+
#lastGetMe;
|
|
67
55
|
async handleUpdate(client, update) {
|
|
68
|
-
if (!
|
|
69
|
-
|
|
56
|
+
if (!this.#lastGetMe && !("connectionState" in update) && (!("authorizationState" in update) || ("authorizationState" in update && update.authorizationState.isAuthorized))) {
|
|
57
|
+
this.#lastGetMe = await client.getMe();
|
|
70
58
|
}
|
|
71
|
-
const ctx = new Context(client,
|
|
59
|
+
const ctx = new Context(client, this.#lastGetMe, update);
|
|
72
60
|
const next = () => Promise.resolve();
|
|
73
|
-
await
|
|
61
|
+
await this.#handle(ctx, next);
|
|
74
62
|
}
|
|
75
63
|
middleware() {
|
|
76
|
-
return
|
|
64
|
+
return this.#handle;
|
|
77
65
|
}
|
|
78
66
|
use(...middleware) {
|
|
79
67
|
const composer = new Composer(...middleware);
|
|
80
|
-
|
|
68
|
+
this.#handle = concat(this.#handle, flatten(composer));
|
|
81
69
|
return composer;
|
|
82
70
|
}
|
|
83
71
|
branch(predicate, trueHandler_, falseHandler_) {
|
|
@@ -101,7 +89,7 @@ export class Composer {
|
|
|
101
89
|
return this.filter((ctx) => ctx.hasFilterQuery(filter), ...middleware);
|
|
102
90
|
}
|
|
103
91
|
command(commands, ...middleware) {
|
|
104
|
-
return this.filter(Context.has.command(commands,
|
|
92
|
+
return this.filter(Context.has.command(commands, this.#prefixes), ...middleware);
|
|
105
93
|
}
|
|
106
94
|
callbackQuery(data, ...middleware) {
|
|
107
95
|
return this.filter(Context.has.callbackQuery(data), ...middleware);
|
|
@@ -116,4 +104,3 @@ export class Composer {
|
|
|
116
104
|
return this.filter(Context.has.chatType(chatType), ...middleware);
|
|
117
105
|
}
|
|
118
106
|
}
|
|
119
|
-
_Composer_handle = new WeakMap(), _Composer_prefixes = new WeakMap(), _Composer_lastGetMe = new WeakMap();
|