@mtkruto/node 0.67.2 → 0.68.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/esm/0_errors.js +2 -6
- package/esm/3_errors.js +2 -12
- package/esm/3_types.d.ts +1 -0
- package/esm/3_types.d.ts.map +1 -1
- package/esm/3_types.js +1 -0
- package/esm/4_errors.js +2 -12
- package/esm/_dnt.polyfills.d.ts +99 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/_dnt.polyfills.js +127 -1
- package/esm/_dnt.test_polyfills.d.ts.map +1 -0
- package/esm/client/0_filters_test.d.ts.map +1 -1
- package/esm/client/0_markdown_test.d.ts.map +1 -1
- package/esm/client/0_params.d.ts +2 -0
- package/esm/client/0_params.d.ts.map +1 -1
- package/esm/client/0_password.d.ts +5 -5
- package/esm/client/0_password.d.ts.map +1 -1
- package/esm/client/0_password_test.d.ts.map +1 -1
- package/esm/client/0_storage_operations.js +143 -155
- package/esm/client/0_storage_operations_test.d.ts.map +1 -1
- package/esm/client/0_utilities.d.ts +1 -1
- package/esm/client/0_utilities_test.d.ts.map +1 -1
- package/esm/client/1_client_plain.js +4 -22
- package/esm/client/1_composer.js +8 -21
- package/esm/client/2_account_manager.js +85 -97
- 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 +194 -211
- package/esm/client/2_file_manager.d.ts +4 -3
- package/esm/client/2_file_manager.d.ts.map +1 -1
- package/esm/client/2_file_manager.js +268 -224
- package/esm/client/2_file_manager_test.d.ts.map +1 -1
- package/esm/client/2_network_statistics_manager.js +8 -21
- 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 +97 -107
- package/esm/client/2_update_manager.js +764 -759
- package/esm/client/3_client_encrypted_pool.js +10 -26
- package/esm/client/3_client_encrypted_pool_test.d.ts.map +1 -1
- package/esm/client/3_message_manager.d.ts +1 -1
- package/esm/client/3_message_manager.js +441 -448
- package/esm/client/3_message_manager_test.d.ts.map +1 -1
- package/esm/client/3_video_chat_manager.d.ts +1 -1
- 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 +322 -318
- package/esm/client/4_chat_manager.js +118 -131
- package/esm/client/4_forum_manager.js +67 -73
- package/esm/client/4_gift_manager.js +16 -29
- 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_client.d.ts +7 -0
- package/esm/client/5_client.d.ts.map +1 -1
- package/esm/client/5_client.js +1269 -1288
- package/esm/connection/1_connection_tcp.node.js +48 -65
- 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.0.13/mux_async_iterator.js +31 -47
- package/esm/deps/jsr.io/@std/async/1.0.13/tee.js +11 -34
- package/esm/deps/jsr.io/@std/datetime/0.225.5/_date_time_formatter.js +4 -17
- package/esm/mod.js +2 -12
- package/esm/session/0_session_state.js +12 -38
- package/esm/session/1_session.js +49 -72
- package/esm/session/2_session_encrypted.js +324 -320
- package/esm/storage/1_utilities_test.d.ts.map +1 -1
- package/esm/storage/2_storage_indexed_db.js +26 -44
- package/esm/storage/2_storage_local_storage.node.js +12 -25
- package/esm/storage/2_storage_memory.js +24 -41
- package/esm/storage/2_storage_session_storage.js +3 -16
- package/esm/tl/0_utilities_test.d.ts.map +1 -1
- package/esm/tl/1_tl_reader.js +80 -88
- package/esm/tl/1_tl_reader_test.d.ts.map +1 -1
- package/esm/tl/1_tl_writer.js +155 -164
- package/esm/tl/1_tl_writer_test.d.ts.map +1 -1
- 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/transport/2_transport_provider_web_socket.d.ts.map +1 -1
- package/esm/types/0_upload_progress.d.ts +29 -0
- package/esm/types/0_upload_progress.d.ts.map +1 -0
- package/esm/types/0_upload_progress.js +20 -0
- package/esm/types/1_sticker.d.ts +1 -1
- package/esm/types/1_sticker.d.ts.map +1 -1
- package/esm/types/2_poll_answer.d.ts +19 -0
- package/esm/types/2_poll_answer.d.ts.map +1 -1
- package/esm/types/2_poll_answer.js +19 -0
- package/esm/types/7_update.d.ts +21 -2
- package/esm/types/7_update.d.ts.map +1 -1
- package/esm/utilities/0_bigint_test.d.ts.map +1 -1
- package/esm/utilities/0_buffer.d.ts +1 -1
- package/esm/utilities/0_buffer.d.ts.map +1 -1
- package/esm/utilities/0_buffer_test.d.ts.map +1 -1
- package/esm/utilities/0_hash.d.ts +2 -2
- package/esm/utilities/0_hash.d.ts.map +1 -1
- package/esm/utilities/0_mutex.js +4 -19
- package/esm/utilities/0_part_stream.js +11 -25
- package/esm/utilities/0_part_stream_test.d.ts.map +1 -1
- package/esm/utilities/0_rle.d.ts +2 -2
- package/esm/utilities/0_rle.d.ts.map +1 -1
- package/esm/utilities/0_rle_test.d.ts.map +1 -1
- package/esm/utilities/0_text.d.ts +20 -1
- package/esm/utilities/0_text.d.ts.map +1 -1
- package/esm/utilities/0_text.js +19 -0
- package/esm/utilities/1_auth.d.ts +1 -1
- package/esm/utilities/1_auth.d.ts.map +1 -1
- package/esm/utilities/1_base64.d.ts +1 -1
- package/esm/utilities/1_base64.d.ts.map +1 -1
- package/esm/utilities/1_base64_test.d.ts.map +1 -1
- package/esm/utilities/1_crypto.js +42 -53
- package/esm/utilities/1_crypto_test.d.ts.map +1 -1
- package/esm/utilities/1_logger.d.ts +2 -2
- package/esm/utilities/1_math_test.d.ts.map +1 -1
- package/esm/utilities/2_queue.js +29 -47
- package/package.json +1 -1
- package/script/0_errors.js +2 -6
- package/script/2_tl.js +17 -7
- package/script/3_errors.js +2 -12
- package/script/3_types.d.ts +1 -0
- package/script/3_types.d.ts.map +1 -1
- package/script/3_types.js +1 -0
- package/script/4_constants.js +17 -7
- package/script/4_errors.js +2 -12
- package/script/_dnt.polyfills.d.ts +99 -0
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +128 -0
- package/script/_dnt.test_polyfills.d.ts.map +1 -0
- package/script/client/0_filters_test.d.ts.map +1 -1
- package/script/client/0_markdown_test.d.ts.map +1 -1
- package/script/client/0_params.d.ts +2 -0
- package/script/client/0_params.d.ts.map +1 -1
- package/script/client/0_password.d.ts +5 -5
- package/script/client/0_password.d.ts.map +1 -1
- package/script/client/0_password.js +17 -7
- package/script/client/0_password_test.d.ts.map +1 -1
- package/script/client/0_storage_operations.js +143 -155
- package/script/client/0_storage_operations_test.d.ts.map +1 -1
- package/script/client/0_utilities.d.ts +1 -1
- package/script/client/0_utilities_test.d.ts.map +1 -1
- package/script/client/1_client_plain.js +4 -22
- package/script/client/1_composer.js +8 -21
- package/script/client/2_account_manager.js +85 -97
- 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 +195 -212
- package/script/client/2_file_manager.d.ts +4 -3
- package/script/client/2_file_manager.d.ts.map +1 -1
- package/script/client/2_file_manager.js +285 -231
- package/script/client/2_file_manager_test.d.ts.map +1 -1
- package/script/client/2_network_statistics_manager.js +8 -21
- 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 +98 -108
- package/script/client/2_update_manager.js +764 -759
- package/script/client/3_client_encrypted_pool.js +10 -26
- package/script/client/3_client_encrypted_pool_test.d.ts.map +1 -1
- package/script/client/3_message_manager.d.ts +1 -1
- package/script/client/3_message_manager.js +441 -448
- package/script/client/3_message_manager_test.d.ts.map +1 -1
- package/script/client/3_video_chat_manager.d.ts +1 -1
- 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 +322 -318
- package/script/client/4_chat_manager.js +118 -131
- package/script/client/4_forum_manager.js +67 -73
- package/script/client/4_gift_manager.js +16 -29
- 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_client.d.ts +7 -0
- package/script/client/5_client.d.ts.map +1 -1
- package/script/client/5_client.js +1269 -1288
- package/script/connection/1_connection_tcp.node.js +48 -65
- package/script/connection/1_connection_web_socket.js +92 -98
- package/script/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
- package/script/deps/jsr.io/@std/assert/1.0.13/equal.js +17 -7
- package/script/deps/jsr.io/@std/async/1.0.13/delay.js +17 -7
- package/script/deps/jsr.io/@std/async/1.0.13/mux_async_iterator.js +31 -47
- package/script/deps/jsr.io/@std/async/1.0.13/tee.js +11 -34
- package/script/deps/jsr.io/@std/datetime/0.225.5/_date_time_formatter.js +4 -17
- package/script/deps/jsr.io/@std/internal/1.0.10/format.js +17 -7
- package/script/deps/jsr.io/@std/internal/1.0.10/styles.js +17 -7
- package/script/deps/jsr.io/@std/path/1.1.0/_os.js +17 -7
- package/script/mod.js +19 -19
- package/script/session/0_session_state.js +12 -38
- package/script/session/1_session.js +66 -79
- package/script/session/2_session_encrypted.js +325 -321
- package/script/storage/1_utilities_test.d.ts.map +1 -1
- package/script/storage/2_storage_indexed_db.js +26 -44
- package/script/storage/2_storage_local_storage.node.js +12 -25
- package/script/storage/2_storage_memory.js +24 -41
- package/script/storage/2_storage_session_storage.js +3 -16
- package/script/tl/0_utilities_test.d.ts.map +1 -1
- package/script/tl/1_tl_reader.js +81 -89
- package/script/tl/1_tl_reader_test.d.ts.map +1 -1
- package/script/tl/1_tl_writer.js +156 -165
- package/script/tl/1_tl_writer_test.d.ts.map +1 -1
- package/script/tl/2_telegram.js +17 -7
- package/script/transport/0_obfuscation.js +17 -7
- 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/transport/2_transport_provider_web_socket.d.ts.map +1 -1
- package/script/types/0_upload_progress.d.ts +29 -0
- package/script/types/0_upload_progress.d.ts.map +1 -0
- package/script/types/0_upload_progress.js +21 -0
- package/script/types/1_sticker.d.ts +1 -1
- package/script/types/1_sticker.d.ts.map +1 -1
- package/script/types/2_poll_answer.d.ts +19 -0
- package/script/types/2_poll_answer.d.ts.map +1 -1
- package/script/types/2_poll_answer.js +19 -0
- package/script/types/7_update.d.ts +21 -2
- package/script/types/7_update.d.ts.map +1 -1
- package/script/utilities/0_bigint.js +17 -7
- package/script/utilities/0_bigint_test.d.ts.map +1 -1
- package/script/utilities/0_buffer.d.ts +1 -1
- package/script/utilities/0_buffer.d.ts.map +1 -1
- package/script/utilities/0_buffer_test.d.ts.map +1 -1
- package/script/utilities/0_env.js +17 -7
- package/script/utilities/0_hash.d.ts +2 -2
- package/script/utilities/0_hash.d.ts.map +1 -1
- package/script/utilities/0_hash.js +17 -7
- package/script/utilities/0_misc.js +17 -7
- package/script/utilities/0_mutex.js +4 -19
- package/script/utilities/0_part_stream.js +11 -25
- package/script/utilities/0_part_stream_test.d.ts.map +1 -1
- package/script/utilities/0_rle.d.ts +2 -2
- package/script/utilities/0_rle.d.ts.map +1 -1
- package/script/utilities/0_rle_test.d.ts.map +1 -1
- package/script/utilities/0_text.d.ts +20 -1
- package/script/utilities/0_text.d.ts.map +1 -1
- package/script/utilities/0_text.js +19 -0
- package/script/utilities/1_auth.d.ts +1 -1
- package/script/utilities/1_auth.d.ts.map +1 -1
- package/script/utilities/1_auth.js +17 -7
- package/script/utilities/1_base64.d.ts +1 -1
- package/script/utilities/1_base64.d.ts.map +1 -1
- package/script/utilities/1_base64_test.d.ts.map +1 -1
- package/script/utilities/1_crypto.js +60 -61
- package/script/utilities/1_crypto_test.d.ts.map +1 -1
- package/script/utilities/1_logger.d.ts +2 -2
- package/script/utilities/1_math_test.d.ts.map +1 -1
- package/script/utilities/2_queue.js +30 -48
|
@@ -18,18 +18,7 @@
|
|
|
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
|
|
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 _UpdateManager_instances, _a, _UpdateManager_c, _UpdateManager_updateState, _UpdateManager_updateHandler, _UpdateManager_LrecoverUpdateGap, _UpdateManager_LrecoverChannelUpdateGap, _UpdateManager_L$handleUpdate, _UpdateManager_L$processUpdates, _UpdateManager_LfetchState, _UpdateManager_LopenChat, _UpdateManager_Lmin, _UpdateManager_defaultDropPendingUpdates, _UpdateManager_mustDropPendingUpdates, _UpdateManager_state, _UpdateManager_getState, _UpdateManager_setState, _UpdateManager_extractMessages, _UpdateManager_extractMinPeerReferences, _UpdateManager_handleUpdateQueues, _UpdateManager_nonFirst, _UpdateManager_getChannelPtsWithDropPendingUpdatesCheck, _UpdateManager_checkGap, _UpdateManager_checkGapQts, _UpdateManager_checkChannelGap, _UpdateManager_channelUpdateQueues, _UpdateManager_processChannelPtsUpdateInner, _UpdateManager_queueUpdate, _UpdateManager_processChannelPtsUpdate, _UpdateManager_processPtsUpdateInner, _UpdateManager_ptsUpdateQueue, _UpdateManager_processPtsUpdate, _UpdateManager_processQtsUpdateInner, _UpdateManager_qtsUpdateQueue, _UpdateManager_processQtsUpdate, _UpdateManager_processUpdatesQueue, _UpdateManager_processUpdates, _UpdateManager_setUpdateStateDate, _UpdateManager_setUpdatePts, _UpdateManager_setUpdateQts, _UpdateManager_getLocalState, _UpdateManager_recoveringUpdateGap, _UpdateManager_recoverUpdateGapMutex, _UpdateManager_recoverChannelUpdateGap, _UpdateManager_handleUpdatesSet, _UpdateManager_handleStoredUpdates, _UpdateManager_handleUpdate, _UpdateManager_needsGetDifference, _UpdateManager_collectChatIds, _UpdateManager_collectChatIdsFromEntities, _UpdateManager_openChats;
|
|
21
|
+
var _a;
|
|
33
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
23
|
exports.UpdateManager = void 0;
|
|
35
24
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
@@ -40,39 +29,28 @@ const _3_errors_js_1 = require("../3_errors.js");
|
|
|
40
29
|
const _4_constants_js_1 = require("../4_constants.js");
|
|
41
30
|
const _2_telegram_js_1 = require("../tl/2_telegram.js");
|
|
42
31
|
class UpdateManager {
|
|
32
|
+
static QTS_COUNT = 1;
|
|
33
|
+
static MAIN_BOX_ID = 0n;
|
|
34
|
+
#c;
|
|
35
|
+
#updateState;
|
|
36
|
+
#updateHandler;
|
|
37
|
+
#LrecoverUpdateGap;
|
|
38
|
+
#LrecoverChannelUpdateGap;
|
|
39
|
+
#L$handleUpdate;
|
|
40
|
+
#L$processUpdates;
|
|
41
|
+
#LfetchState;
|
|
42
|
+
#LopenChat;
|
|
43
|
+
#Lmin;
|
|
43
44
|
constructor(c) {
|
|
44
|
-
|
|
45
|
-
_UpdateManager_c.set(this, void 0);
|
|
46
|
-
_UpdateManager_updateState.set(this, void 0);
|
|
47
|
-
_UpdateManager_updateHandler.set(this, void 0);
|
|
48
|
-
_UpdateManager_LrecoverUpdateGap.set(this, void 0);
|
|
49
|
-
_UpdateManager_LrecoverChannelUpdateGap.set(this, void 0);
|
|
50
|
-
_UpdateManager_L$handleUpdate.set(this, void 0);
|
|
51
|
-
_UpdateManager_L$processUpdates.set(this, void 0);
|
|
52
|
-
_UpdateManager_LfetchState.set(this, void 0);
|
|
53
|
-
_UpdateManager_LopenChat.set(this, void 0);
|
|
54
|
-
_UpdateManager_Lmin.set(this, void 0);
|
|
55
|
-
_UpdateManager_defaultDropPendingUpdates.set(this, null);
|
|
56
|
-
_UpdateManager_state.set(this, undefined);
|
|
57
|
-
_UpdateManager_handleUpdateQueues.set(this, new Map());
|
|
58
|
-
_UpdateManager_nonFirst.set(this, new Set());
|
|
59
|
-
_UpdateManager_channelUpdateQueues.set(this, new Map());
|
|
60
|
-
_UpdateManager_ptsUpdateQueue.set(this, new _1_utilities_js_1.Queue("ptsUpdate"));
|
|
61
|
-
_UpdateManager_qtsUpdateQueue.set(this, new _1_utilities_js_1.Queue("qtsUpdate"));
|
|
62
|
-
_UpdateManager_processUpdatesQueue.set(this, new _1_utilities_js_1.Queue("UpdateManager/processUpdates"));
|
|
63
|
-
_UpdateManager_recoveringUpdateGap.set(this, false);
|
|
64
|
-
_UpdateManager_recoverUpdateGapMutex.set(this, new _1_utilities_js_1.Mutex());
|
|
65
|
-
_UpdateManager_handleUpdatesSet.set(this, new Set());
|
|
66
|
-
_UpdateManager_openChats.set(this, new Map());
|
|
67
|
-
__classPrivateFieldSet(this, _UpdateManager_c, c, "f");
|
|
45
|
+
this.#c = c;
|
|
68
46
|
const L = (0, _1_utilities_js_1.getLogger)("UpdateManager").client(c.id);
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
47
|
+
this.#LrecoverUpdateGap = L.branch("recoverUpdateGap");
|
|
48
|
+
this.#LrecoverChannelUpdateGap = L.branch("recoverChannelUpdateGap");
|
|
49
|
+
this.#L$handleUpdate = L.branch("#handleUpdate");
|
|
50
|
+
this.#L$processUpdates = L.branch("#processUpdates");
|
|
51
|
+
this.#LfetchState = L.branch("fetchState");
|
|
52
|
+
this.#LopenChat = L.branch("openChat");
|
|
53
|
+
this.#Lmin = L.branch("min");
|
|
76
54
|
}
|
|
77
55
|
static isPtsUpdate(v) {
|
|
78
56
|
return _2_tl_js_1.Api.isOneOf(["updateNewMessage", "updateDeleteMessages", "updateReadHistoryInbox", "updateReadHistoryOutbox", "updatePinnedChannelMessages", "updatePinnedMessages", "updateFolderPeers", "updateChannelWebPage", "updateEditMessage", "updateReadMessagesContents", "updateWebPage"], v);
|
|
@@ -88,48 +66,121 @@ class UpdateManager {
|
|
|
88
66
|
"updateChannelTooLong",
|
|
89
67
|
], v);
|
|
90
68
|
}
|
|
69
|
+
#defaultDropPendingUpdates = null;
|
|
70
|
+
async #mustDropPendingUpdates() {
|
|
71
|
+
if (typeof this.#c.dropPendingUpdates === "boolean") {
|
|
72
|
+
return this.#c.dropPendingUpdates;
|
|
73
|
+
}
|
|
74
|
+
if (this.#defaultDropPendingUpdates == null) {
|
|
75
|
+
this.#defaultDropPendingUpdates = await this.#c.storage.getAccountType() == "bot";
|
|
76
|
+
}
|
|
77
|
+
return this.#defaultDropPendingUpdates;
|
|
78
|
+
}
|
|
79
|
+
#state = undefined;
|
|
80
|
+
async #getState() {
|
|
81
|
+
if (await this.#mustDropPendingUpdates()) {
|
|
82
|
+
return this.#state ?? null;
|
|
83
|
+
}
|
|
84
|
+
if (this.#state !== undefined) {
|
|
85
|
+
return this.#state;
|
|
86
|
+
}
|
|
87
|
+
const state = await this.#c.storage.getState();
|
|
88
|
+
return this.#state = state;
|
|
89
|
+
}
|
|
90
|
+
async #setState(state) {
|
|
91
|
+
this.#state = state;
|
|
92
|
+
if (!await this.#mustDropPendingUpdates()) {
|
|
93
|
+
await this.#c.storage.setState(state);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
91
96
|
async fetchState(source) {
|
|
92
|
-
let state = await
|
|
93
|
-
const difference = await
|
|
97
|
+
let state = await this.#c.invoke({ _: "updates.getState" });
|
|
98
|
+
const difference = await this.#c.invoke({ ...state, _: "updates.getDifference" });
|
|
94
99
|
if (_2_tl_js_1.Api.is("updates.difference", difference)) {
|
|
95
100
|
state = difference.state;
|
|
96
101
|
}
|
|
97
102
|
else if (_2_tl_js_1.Api.is("updates.differenceSlice", difference)) {
|
|
98
103
|
state = difference.intermediate_state;
|
|
99
104
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (await
|
|
103
|
-
await
|
|
105
|
+
this.#updateState = state;
|
|
106
|
+
this.#LfetchState.debug(`state fetched [${source}]`);
|
|
107
|
+
if (await this.#mustDropPendingUpdates()) {
|
|
108
|
+
await this.#setState(state);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
#extractMessages(context) {
|
|
112
|
+
const messages = new Array();
|
|
113
|
+
if (Array.isArray(context)) {
|
|
114
|
+
for (const item of context) {
|
|
115
|
+
messages.push(...this.#extractMessages(item));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else if (_2_tl_js_1.Api.isOneOf(["updates", "updatesCombined"], context)) {
|
|
119
|
+
messages.push(...this.#extractMessages(context.updates));
|
|
120
|
+
}
|
|
121
|
+
else if (_2_tl_js_1.Api.isOneOf(["updates.difference", "updates.differenceSlice", "updates.channelDifference"], context)) {
|
|
122
|
+
for (const message of context.new_messages) {
|
|
123
|
+
if (_2_tl_js_1.Api.is("message", message)) {
|
|
124
|
+
messages.push(message);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
messages.push(...this.#extractMessages(context.other_updates));
|
|
128
|
+
}
|
|
129
|
+
else if (_2_tl_js_1.Api.isOneOf(["updateNewMessage", "updateNewChannelMessage", "updateEditMessage", "updateEditChannelMessage", "updateBotNewBusinessMessage", "updateBotNewBusinessMessage"], context)) {
|
|
130
|
+
if (_2_tl_js_1.Api.is("message", context.message)) {
|
|
131
|
+
messages.push(context.message);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
else if (_2_tl_js_1.Api.is("message", context)) {
|
|
135
|
+
messages.push(context);
|
|
136
|
+
}
|
|
137
|
+
else if (context != null && typeof context === "object" && "messages" in context && Array.isArray(context.messages)) {
|
|
138
|
+
for (const message of context.messages) {
|
|
139
|
+
if (_2_tl_js_1.Api.is("message", message)) {
|
|
140
|
+
messages.push(message);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return messages;
|
|
145
|
+
}
|
|
146
|
+
#extractMinPeerReferences(context) {
|
|
147
|
+
const minPeerReferences = new Array();
|
|
148
|
+
const messages = this.#extractMessages(context);
|
|
149
|
+
for (const message of messages) {
|
|
150
|
+
if (!message.from_id) {
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
minPeerReferences.push({ chatId: _2_tl_js_1.Api.peerToChatId(message.peer_id), senderId: _2_tl_js_1.Api.peerToChatId(message.from_id), messageId: message.id });
|
|
104
154
|
}
|
|
155
|
+
return minPeerReferences;
|
|
105
156
|
}
|
|
106
157
|
async processChats(chats, context) {
|
|
107
158
|
for (const chat of chats) {
|
|
108
159
|
if (_2_tl_js_1.Api.isOneOf(["channel", "channelForbidden"], chat)) {
|
|
109
|
-
if (!_2_tl_js_1.Api.is("channel", chat) || !chat.min || chat.min && await
|
|
110
|
-
await
|
|
160
|
+
if (!_2_tl_js_1.Api.is("channel", chat) || !chat.min || chat.min && await this.#c.messageStorage.getEntity(_2_tl_js_1.Api.peerToChatId(chat)) == null) {
|
|
161
|
+
await this.#c.messageStorage.setEntity(chat);
|
|
111
162
|
}
|
|
112
163
|
if (_2_tl_js_1.Api.is("channel", chat) && chat.min) {
|
|
113
|
-
const entity = await
|
|
164
|
+
const entity = await this.#c.messageStorage.getEntity(_2_tl_js_1.Api.peerToChatId(chat));
|
|
114
165
|
const senderChatId = _2_tl_js_1.Api.peerToChatId(chat);
|
|
115
166
|
if (_2_tl_js_1.Api.is("channel", entity) && entity.min) {
|
|
116
|
-
for (const { chatId, senderId, messageId } of
|
|
167
|
+
for (const { chatId, senderId, messageId } of this.#extractMinPeerReferences(context)) {
|
|
117
168
|
if (senderId == senderChatId) {
|
|
118
|
-
await
|
|
119
|
-
|
|
169
|
+
await this.#c.messageStorage.setMinPeerReference(chatId, senderId, messageId);
|
|
170
|
+
this.#Lmin.debug("channel min peer reference stored", chatId, senderId, messageId);
|
|
120
171
|
}
|
|
121
172
|
}
|
|
122
173
|
}
|
|
123
174
|
}
|
|
124
175
|
if ("username" in chat && chat.username) {
|
|
125
|
-
await
|
|
176
|
+
await this.#c.messageStorage.updateUsernames(_2_tl_js_1.Api.peerToChatId(chat), [chat.username]);
|
|
126
177
|
}
|
|
127
178
|
if ("usernames" in chat && chat.usernames) {
|
|
128
|
-
await
|
|
179
|
+
await this.#c.messageStorage.updateUsernames(_2_tl_js_1.Api.peerToChatId(chat), chat.usernames.map((v) => v.username));
|
|
129
180
|
}
|
|
130
181
|
}
|
|
131
182
|
else if (_2_tl_js_1.Api.isOneOf(["chat", "chatForbidden"], chat)) {
|
|
132
|
-
await
|
|
183
|
+
await this.#c.messageStorage.setEntity(chat);
|
|
133
184
|
}
|
|
134
185
|
}
|
|
135
186
|
}
|
|
@@ -162,7 +213,7 @@ class UpdateManager {
|
|
|
162
213
|
if ("messages" in result && Array.isArray(result.messages)) {
|
|
163
214
|
for (const message of result.messages) {
|
|
164
215
|
if (_2_tl_js_1.Api.is("message", message) || _2_tl_js_1.Api.is("messageService", message)) {
|
|
165
|
-
await
|
|
216
|
+
await this.#c.messageStorage.setMessage(_2_tl_js_1.Api.peerToChatId(message.peer_id), message.id, message);
|
|
166
217
|
}
|
|
167
218
|
}
|
|
168
219
|
}
|
|
@@ -170,7 +221,7 @@ class UpdateManager {
|
|
|
170
221
|
if (_2_tl_js_1.Api.is("messages.messages", result)) {
|
|
171
222
|
for (const message of result.messages) {
|
|
172
223
|
if (_2_tl_js_1.Api.is("message", message) || _2_tl_js_1.Api.is("messageService", message)) {
|
|
173
|
-
await
|
|
224
|
+
await this.#c.messageStorage.setMessage(_2_tl_js_1.Api.peerToChatId(message.peer_id), message.id, message);
|
|
174
225
|
}
|
|
175
226
|
}
|
|
176
227
|
}
|
|
@@ -178,35 +229,36 @@ class UpdateManager {
|
|
|
178
229
|
async processUsers(users, context) {
|
|
179
230
|
for (const user of users) {
|
|
180
231
|
if (_2_tl_js_1.Api.is("user", user) && user.access_hash) {
|
|
181
|
-
if (!user.min || user.min && await
|
|
182
|
-
await
|
|
232
|
+
if (!user.min || user.min && await this.#c.messageStorage.getEntity(_2_tl_js_1.Api.peerToChatId(user)) == null) {
|
|
233
|
+
await this.#c.messageStorage.setEntity(user);
|
|
183
234
|
}
|
|
184
235
|
if (user.min) {
|
|
185
|
-
|
|
236
|
+
this.#Lmin.debug("encountered min user");
|
|
186
237
|
}
|
|
187
238
|
if (_2_tl_js_1.Api.is("user", user) && user.min) {
|
|
188
|
-
const entity = await
|
|
239
|
+
const entity = await this.#c.messageStorage.getEntity(_2_tl_js_1.Api.peerToChatId(user));
|
|
189
240
|
const userId = _2_tl_js_1.Api.peerToChatId(user);
|
|
190
241
|
if (_2_tl_js_1.Api.is("user", entity) && entity.min) {
|
|
191
|
-
for (const { chatId, senderId, messageId } of
|
|
242
|
+
for (const { chatId, senderId, messageId } of this.#extractMinPeerReferences(context)) {
|
|
192
243
|
if (senderId == userId) {
|
|
193
|
-
await
|
|
194
|
-
|
|
244
|
+
await this.#c.messageStorage.setMinPeerReference(chatId, senderId, messageId);
|
|
245
|
+
this.#Lmin.debug("user min peer reference stored", chatId, senderId, messageId);
|
|
195
246
|
}
|
|
196
247
|
}
|
|
197
248
|
}
|
|
198
249
|
}
|
|
199
250
|
if (user.username) {
|
|
200
|
-
await
|
|
251
|
+
await this.#c.messageStorage.updateUsernames(_2_tl_js_1.Api.peerToChatId(user), [user.username]);
|
|
201
252
|
}
|
|
202
253
|
if (user.usernames) {
|
|
203
|
-
await
|
|
254
|
+
await this.#c.messageStorage.updateUsernames(_2_tl_js_1.Api.peerToChatId(user), user.usernames.map((v) => v.username));
|
|
204
255
|
}
|
|
205
256
|
}
|
|
206
257
|
}
|
|
207
258
|
}
|
|
259
|
+
#handleUpdateQueues = new Map();
|
|
208
260
|
getHandleUpdateQueue(boxId) {
|
|
209
|
-
let queue =
|
|
261
|
+
let queue = this.#handleUpdateQueues.get(boxId);
|
|
210
262
|
if (queue !== undefined) {
|
|
211
263
|
return queue;
|
|
212
264
|
}
|
|
@@ -215,27 +267,365 @@ class UpdateManager {
|
|
|
215
267
|
return queue;
|
|
216
268
|
}
|
|
217
269
|
}
|
|
270
|
+
#nonFirst = new Set();
|
|
271
|
+
async #getChannelPtsWithDropPendingUpdatesCheck(channelId) {
|
|
272
|
+
if (!(await this.#mustDropPendingUpdates())) {
|
|
273
|
+
return await this.#c.storage.getChannelPts(channelId);
|
|
274
|
+
}
|
|
275
|
+
const first = !this.#nonFirst.has(channelId);
|
|
276
|
+
if (first) {
|
|
277
|
+
this.#nonFirst.add(channelId);
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
return await this.#c.storage.getChannelPts(channelId);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
async #checkGap(pts, ptsCount) {
|
|
285
|
+
const localState = await this.#getLocalState();
|
|
286
|
+
if (localState.pts + ptsCount < pts) {
|
|
287
|
+
await this.recoverUpdateGap("processUpdates[pts]");
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
async #checkGapQts(qts) {
|
|
291
|
+
const localState = await this.#getLocalState();
|
|
292
|
+
if (localState.qts + _a.QTS_COUNT < qts) {
|
|
293
|
+
await this.recoverUpdateGap("processUpdates[qts]");
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
async #checkChannelGap(channelId, pts, ptsCount) {
|
|
297
|
+
let localPts = await this.#getChannelPtsWithDropPendingUpdatesCheck(channelId);
|
|
298
|
+
if (!localPts) {
|
|
299
|
+
localPts = pts - ptsCount;
|
|
300
|
+
}
|
|
301
|
+
if (localPts + ptsCount < pts) {
|
|
302
|
+
await this.#recoverChannelUpdateGap(channelId, "processUpdates");
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
#channelUpdateQueues = new Map();
|
|
306
|
+
async #processChannelPtsUpdateInner(update, checkGap) {
|
|
307
|
+
const channelId = _2_tl_js_1.Api.is("updateNewChannelMessage", update) || _2_tl_js_1.Api.is("updateEditChannelMessage", update) ? _2_tl_js_1.Api.as("peerChannel", update.message.peer_id).channel_id : update.channel_id;
|
|
308
|
+
if (_2_tl_js_1.Api.is("updateChannelTooLong", update)) {
|
|
309
|
+
if (update.pts != undefined) {
|
|
310
|
+
await this.#c.storage.setChannelPts(channelId, update.pts);
|
|
311
|
+
}
|
|
312
|
+
await this.#recoverChannelUpdateGap(channelId, "updateChannelTooLong");
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
if (update.pts != 0) {
|
|
316
|
+
const ptsCount = update.pts_count;
|
|
317
|
+
if (checkGap) {
|
|
318
|
+
await this.#checkChannelGap(channelId, update.pts, ptsCount);
|
|
319
|
+
}
|
|
320
|
+
let currentPts = await this.#getChannelPtsWithDropPendingUpdatesCheck(channelId);
|
|
321
|
+
currentPts ??= update.pts - ptsCount;
|
|
322
|
+
if (currentPts + ptsCount > update.pts) {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
if (this.#c.guaranteeUpdateDelivery) {
|
|
327
|
+
await this.#c.storage.setUpdate(channelId, update);
|
|
328
|
+
}
|
|
329
|
+
if (update.pts != 0) {
|
|
330
|
+
await this.#c.storage.setChannelPts(channelId, update.pts);
|
|
331
|
+
}
|
|
332
|
+
this.#queueUpdate(update, channelId, true);
|
|
333
|
+
}
|
|
334
|
+
#queueUpdate(update, boxId, pts) {
|
|
335
|
+
this.getHandleUpdateQueue(boxId).add(async () => {
|
|
336
|
+
if (this.#c.guaranteeUpdateDelivery && pts) {
|
|
337
|
+
await this.#handleStoredUpdates(boxId);
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
await (await this.#handleUpdate(update))();
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
#processChannelPtsUpdate(update, checkGap) {
|
|
345
|
+
const channelId = _2_tl_js_1.Api.is("updateNewChannelMessage", update) || _2_tl_js_1.Api.is("updateEditChannelMessage", update) ? _2_tl_js_1.Api.as("peerChannel", update.message.peer_id).channel_id : update.channel_id;
|
|
346
|
+
let queue = this.#channelUpdateQueues.get(channelId);
|
|
347
|
+
if (queue == undefined) {
|
|
348
|
+
queue = new _1_utilities_js_1.Queue(`channelUpdates-${channelId}`);
|
|
349
|
+
this.#channelUpdateQueues.set(channelId, queue);
|
|
350
|
+
}
|
|
351
|
+
queue.add(async () => {
|
|
352
|
+
await this.#processChannelPtsUpdateInner(update, checkGap);
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
async #processPtsUpdateInner(update, checkGap) {
|
|
356
|
+
if (update.pts != 0 && checkGap) {
|
|
357
|
+
await this.#checkGap(update.pts, update.pts_count);
|
|
358
|
+
if (await this.#needsGetDifference(update)) {
|
|
359
|
+
await this.recoverUpdateGap("needsGetDifference");
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
const localState = await this.#getLocalState();
|
|
363
|
+
if (localState.pts + update.pts_count > update.pts) {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
if (this.#c.guaranteeUpdateDelivery) {
|
|
367
|
+
await this.#c.storage.setUpdate(_a.MAIN_BOX_ID, update);
|
|
368
|
+
}
|
|
369
|
+
if (update.pts != 0) {
|
|
370
|
+
await this.#setUpdatePts(update.pts);
|
|
371
|
+
}
|
|
372
|
+
this.#queueUpdate(update, 1n, false);
|
|
373
|
+
}
|
|
374
|
+
#ptsUpdateQueue = new _1_utilities_js_1.Queue("ptsUpdate");
|
|
375
|
+
#processPtsUpdate(update, checkGap) {
|
|
376
|
+
this.#ptsUpdateQueue.add(async () => {
|
|
377
|
+
await this.#processPtsUpdateInner(update, checkGap);
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
async #processQtsUpdateInner(update, checkGap) {
|
|
381
|
+
const localState = await this.#getLocalState();
|
|
382
|
+
if (update.qts != 0) {
|
|
383
|
+
if (checkGap) {
|
|
384
|
+
await this.#checkGapQts(update.qts);
|
|
385
|
+
}
|
|
386
|
+
if (localState.qts + _a.QTS_COUNT > update.qts) {
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
if (this.#c.guaranteeUpdateDelivery) {
|
|
391
|
+
await this.#c.storage.setUpdate(_a.MAIN_BOX_ID, update);
|
|
392
|
+
}
|
|
393
|
+
if (update.qts != 0) {
|
|
394
|
+
await this.#setUpdateQts(update.qts);
|
|
395
|
+
}
|
|
396
|
+
this.#queueUpdate(update, 0n, true);
|
|
397
|
+
}
|
|
398
|
+
#qtsUpdateQueue = new _1_utilities_js_1.Queue("qtsUpdate");
|
|
399
|
+
#processQtsUpdate(update, checkGap) {
|
|
400
|
+
this.#qtsUpdateQueue.add(async () => {
|
|
401
|
+
await this.#processQtsUpdateInner(update, checkGap);
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
#processUpdatesQueue = new _1_utilities_js_1.Queue("UpdateManager/processUpdates");
|
|
218
405
|
processUpdates(updates, checkGap, call = null, callback) {
|
|
219
|
-
|
|
406
|
+
this.#processUpdatesQueue.add(() => this.#processUpdates(updates, checkGap, call).finally(callback));
|
|
407
|
+
}
|
|
408
|
+
async #processUpdates(updates_, checkGap, call = null) {
|
|
409
|
+
/// First, individual updates (Update[1]) are extracted from Updates.[2]
|
|
410
|
+
///
|
|
411
|
+
/// If an updatesTooLong[3] was received, an update gap recovery is initiated and no further action will be taken.
|
|
412
|
+
///
|
|
413
|
+
/// [1]: https://core.telegram.org/type/Update
|
|
414
|
+
/// [2]: https://core.telegram.org/type/Updates
|
|
415
|
+
/// [3]: https://core.telegram.org/constructor/updatesTooLong
|
|
416
|
+
let updates;
|
|
417
|
+
if (_2_tl_js_1.Api.is("updatesCombined", updates_) || _2_tl_js_1.Api.is("updates", updates_)) {
|
|
418
|
+
updates = updates_.updates;
|
|
419
|
+
const seq = updates_.seq;
|
|
420
|
+
const seqStart = "seq_start" in updates_ ? updates_.seq_start : updates_.seq;
|
|
421
|
+
if (checkGap) {
|
|
422
|
+
if (seqStart == 0) {
|
|
423
|
+
checkGap = false;
|
|
424
|
+
this.#L$processUpdates.debug("seqStart=0");
|
|
425
|
+
}
|
|
426
|
+
else {
|
|
427
|
+
const localState = await this.#getLocalState();
|
|
428
|
+
const localSeq = localState.seq;
|
|
429
|
+
if (localSeq + 1 == seqStart) {
|
|
430
|
+
// The update sequence can be applied.
|
|
431
|
+
localState.seq = seq;
|
|
432
|
+
localState.date = updates_.date;
|
|
433
|
+
await this.#setUpdateStateDate(updates_.date);
|
|
434
|
+
await this.#setState(localState);
|
|
435
|
+
}
|
|
436
|
+
else if (localSeq + 1 > seqStart) {
|
|
437
|
+
// The update sequence was already applied, and must be ignored.
|
|
438
|
+
this.#L$processUpdates.debug("localSeq + 1 > seqStart");
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
else if (localSeq + 1 < seqStart) {
|
|
442
|
+
// There's an updates gap that must be filled.
|
|
443
|
+
await this.recoverUpdateGap("localSeq + 1 < seqStart");
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
else if (_2_tl_js_1.Api.is("updateShort", updates_)) {
|
|
449
|
+
updates = [updates_.update];
|
|
450
|
+
}
|
|
451
|
+
else if (_2_tl_js_1.Api.is("updateShortMessage", updates_)) {
|
|
452
|
+
updates = [
|
|
453
|
+
{
|
|
454
|
+
_: "updateNewMessage",
|
|
455
|
+
message: ({
|
|
456
|
+
_: "message",
|
|
457
|
+
out: updates_.out,
|
|
458
|
+
mentioned: updates_.mentioned,
|
|
459
|
+
media_unread: updates_.media_unread,
|
|
460
|
+
silent: updates_.silent,
|
|
461
|
+
id: updates_.id,
|
|
462
|
+
from_id: updates_.out ? ({ _: "peerUser", user_id: BigInt(await this.#c.getSelfId()) }) : ({ _: "peerUser", user_id: updates_.user_id }),
|
|
463
|
+
peer_id: ({ _: "peerUser", user_id: updates_.user_id }),
|
|
464
|
+
message: updates_.message,
|
|
465
|
+
date: updates_.date,
|
|
466
|
+
fwd_from: updates_.fwd_from,
|
|
467
|
+
via_bot_id: updates_.via_bot_id,
|
|
468
|
+
reply_to: updates_.reply_to,
|
|
469
|
+
entities: updates_.entities,
|
|
470
|
+
ttl_period: updates_.ttl_period,
|
|
471
|
+
}),
|
|
472
|
+
pts: updates_.pts,
|
|
473
|
+
pts_count: updates_.pts_count,
|
|
474
|
+
},
|
|
475
|
+
];
|
|
476
|
+
}
|
|
477
|
+
else if (_2_tl_js_1.Api.is("updateShortChatMessage", updates_)) {
|
|
478
|
+
updates = [
|
|
479
|
+
{
|
|
480
|
+
_: "updateNewMessage",
|
|
481
|
+
message: ({
|
|
482
|
+
_: "message",
|
|
483
|
+
mentioned: updates_.mentioned,
|
|
484
|
+
media_unread: updates_.media_unread,
|
|
485
|
+
silent: updates_.silent,
|
|
486
|
+
id: updates_.id,
|
|
487
|
+
from_id: { _: "peerUser", user_id: updates_.from_id },
|
|
488
|
+
peer_id: { _: "peerChat", chat_id: updates_.chat_id },
|
|
489
|
+
fwd_from: updates_.fwd_from,
|
|
490
|
+
via_bot_id: updates_.via_bot_id,
|
|
491
|
+
reply_to: updates_.reply_to,
|
|
492
|
+
date: updates_.date,
|
|
493
|
+
message: updates_.message,
|
|
494
|
+
entities: updates_.entities,
|
|
495
|
+
ttl_period: updates_.ttl_period,
|
|
496
|
+
}),
|
|
497
|
+
pts: updates_.pts,
|
|
498
|
+
pts_count: updates_.pts_count,
|
|
499
|
+
},
|
|
500
|
+
];
|
|
501
|
+
}
|
|
502
|
+
else if (_2_tl_js_1.Api.is("updateShortSentMessage", updates_)) {
|
|
503
|
+
if (!_2_tl_js_1.Api.is("messages.sendMessage", call)) {
|
|
504
|
+
(0, _0_deps_js_1.unreachable)();
|
|
505
|
+
}
|
|
506
|
+
updates = [{
|
|
507
|
+
_: "updateNewMessage",
|
|
508
|
+
message: ({
|
|
509
|
+
_: "message",
|
|
510
|
+
out: updates_.out,
|
|
511
|
+
silent: call.silent,
|
|
512
|
+
id: updates_.id,
|
|
513
|
+
from_id: { _: "peerUser", user_id: BigInt(await this.#c.getSelfId()) },
|
|
514
|
+
peer_id: _2_tl_js_1.Api.inputPeerToPeer(call.peer),
|
|
515
|
+
message: call.message,
|
|
516
|
+
media: updates_.media,
|
|
517
|
+
date: updates_.date,
|
|
518
|
+
// reply_to: call.reply_to, // TODO?
|
|
519
|
+
entities: updates_.entities,
|
|
520
|
+
ttl_period: updates_.ttl_period,
|
|
521
|
+
}),
|
|
522
|
+
pts: updates_.pts,
|
|
523
|
+
pts_count: updates_.pts_count,
|
|
524
|
+
}];
|
|
525
|
+
}
|
|
526
|
+
else if (_2_tl_js_1.Api.is("updatesTooLong", updates_)) {
|
|
527
|
+
await this.recoverUpdateGap("updatesTooLong");
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
else if (_2_tl_js_1.Api.isOfEnum("Update", updates_)) {
|
|
531
|
+
updates = [updates_];
|
|
532
|
+
}
|
|
533
|
+
else {
|
|
534
|
+
(0, _0_deps_js_1.unreachable)();
|
|
535
|
+
}
|
|
536
|
+
/// We process the updates when we are sure there is no gap.
|
|
537
|
+
if (_2_tl_js_1.Api.is("updates", updates_) || _2_tl_js_1.Api.is("updatesCombined", updates_)) {
|
|
538
|
+
await this.processChats(updates_.chats, updates_);
|
|
539
|
+
await this.processUsers(updates_.users, updates_);
|
|
540
|
+
await this.#setUpdateStateDate(updates_.date);
|
|
541
|
+
}
|
|
542
|
+
else if (_2_tl_js_1.Api.isOneOf([
|
|
543
|
+
"updateShort",
|
|
544
|
+
"updateShortMessage",
|
|
545
|
+
"updateShortChatMessage",
|
|
546
|
+
"updateShortSentMessage",
|
|
547
|
+
], updates_)) {
|
|
548
|
+
await this.#setUpdateStateDate(updates_.date);
|
|
549
|
+
}
|
|
550
|
+
for (const update of updates) {
|
|
551
|
+
if (_2_tl_js_1.Api.is("updatePtsChanged", update)) {
|
|
552
|
+
await this.fetchState("updatePtsChanged");
|
|
553
|
+
if (this.#updateState) {
|
|
554
|
+
await this.#setState(this.#updateState);
|
|
555
|
+
}
|
|
556
|
+
else {
|
|
557
|
+
(0, _0_deps_js_1.unreachable)();
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
else if (_a.isPtsUpdate(update)) {
|
|
561
|
+
this.#processPtsUpdate(update, checkGap);
|
|
562
|
+
}
|
|
563
|
+
else if (_a.isChannelPtsUpdate(update)) {
|
|
564
|
+
this.#processChannelPtsUpdate(update, checkGap);
|
|
565
|
+
}
|
|
566
|
+
else if (_a.isQtsUpdate(update)) {
|
|
567
|
+
this.#processQtsUpdate(update, checkGap);
|
|
568
|
+
}
|
|
569
|
+
else {
|
|
570
|
+
this.#queueUpdate(update, 0n, false);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
220
573
|
}
|
|
574
|
+
async #setUpdateStateDate(date) {
|
|
575
|
+
const localState = await this.#getLocalState();
|
|
576
|
+
localState.date = date;
|
|
577
|
+
await this.#setState(localState);
|
|
578
|
+
}
|
|
579
|
+
async #setUpdatePts(pts) {
|
|
580
|
+
const localState = await this.#getLocalState();
|
|
581
|
+
localState.pts = pts;
|
|
582
|
+
await this.#setState(localState);
|
|
583
|
+
}
|
|
584
|
+
async #setUpdateQts(qts) {
|
|
585
|
+
const localState = await this.#getLocalState();
|
|
586
|
+
localState.qts = qts;
|
|
587
|
+
await this.#setState(localState);
|
|
588
|
+
}
|
|
589
|
+
async #getLocalState() {
|
|
590
|
+
let localState = await this.#getState();
|
|
591
|
+
if (!localState) {
|
|
592
|
+
if (this.#updateState) {
|
|
593
|
+
localState = this.#updateState;
|
|
594
|
+
await this.#setState(localState);
|
|
595
|
+
}
|
|
596
|
+
else {
|
|
597
|
+
await this.fetchState("getLocalState");
|
|
598
|
+
if (this.#updateState) {
|
|
599
|
+
localState = this.#updateState;
|
|
600
|
+
await this.#setState(localState);
|
|
601
|
+
}
|
|
602
|
+
else {
|
|
603
|
+
(0, _0_deps_js_1.unreachable)();
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
return localState;
|
|
608
|
+
}
|
|
609
|
+
#recoveringUpdateGap = false;
|
|
610
|
+
#recoverUpdateGapMutex = new _1_utilities_js_1.Mutex();
|
|
221
611
|
async recoverUpdateGap(source) {
|
|
222
|
-
const wasRecoveringUpdateGap =
|
|
223
|
-
const unlock = await
|
|
612
|
+
const wasRecoveringUpdateGap = this.#recoveringUpdateGap;
|
|
613
|
+
const unlock = await this.#recoverUpdateGapMutex.lock();
|
|
224
614
|
if (wasRecoveringUpdateGap) {
|
|
225
|
-
|
|
615
|
+
this.#LrecoverUpdateGap.debug(`update gap was just recovered [${source}]`);
|
|
226
616
|
unlock();
|
|
227
617
|
return;
|
|
228
618
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
619
|
+
this.#recoveringUpdateGap = true;
|
|
620
|
+
this.#LrecoverUpdateGap.debug(`recovering from update gap [${source}]`);
|
|
621
|
+
this.#c.setConnectionState("updating");
|
|
232
622
|
try {
|
|
233
623
|
let retryIn = 5;
|
|
234
|
-
let state = await
|
|
624
|
+
let state = await this.#getLocalState();
|
|
235
625
|
while (true) {
|
|
236
626
|
let difference;
|
|
237
627
|
try {
|
|
238
|
-
difference = await
|
|
628
|
+
difference = await this.#c.invoke({ _: "updates.getDifference", pts: state.pts, date: state.date, qts: state.qts ?? 0 });
|
|
239
629
|
}
|
|
240
630
|
catch (err) {
|
|
241
631
|
if (err instanceof _3_errors_js_1.PersistentTimestampInvalid) {
|
|
@@ -254,13 +644,13 @@ class UpdateManager {
|
|
|
254
644
|
await this.processChats(difference.chats, difference);
|
|
255
645
|
await this.processUsers(difference.users, difference);
|
|
256
646
|
for (const message of difference.new_messages) {
|
|
257
|
-
await
|
|
647
|
+
await this.#processUpdates({ _: "updateNewMessage", message, pts: 0, pts_count: 0 }, false);
|
|
258
648
|
}
|
|
259
649
|
for (const update of difference.other_updates) {
|
|
260
|
-
await
|
|
650
|
+
await this.#processUpdates(update, false);
|
|
261
651
|
}
|
|
262
652
|
if (_2_tl_js_1.Api.is("updates.difference", difference)) {
|
|
263
|
-
|
|
653
|
+
this.#LrecoverUpdateGap.debug("recovered from update gap");
|
|
264
654
|
break;
|
|
265
655
|
}
|
|
266
656
|
else if (_2_tl_js_1.Api.is("updates.differenceSlice", difference)) {
|
|
@@ -271,15 +661,15 @@ class UpdateManager {
|
|
|
271
661
|
}
|
|
272
662
|
}
|
|
273
663
|
else if (_2_tl_js_1.Api.is("updates.differenceTooLong", difference)) {
|
|
274
|
-
await
|
|
275
|
-
await
|
|
276
|
-
await
|
|
664
|
+
await this.#c.messageStorage.deleteMessages();
|
|
665
|
+
await this.#c.storage.removeChats(0);
|
|
666
|
+
await this.#c.storage.removeChats(1);
|
|
277
667
|
state.pts = difference.pts;
|
|
278
|
-
|
|
668
|
+
this.#LrecoverUpdateGap.debug("received differenceTooLong");
|
|
279
669
|
}
|
|
280
670
|
else if (_2_tl_js_1.Api.is("updates.differenceEmpty", difference)) {
|
|
281
|
-
await
|
|
282
|
-
|
|
671
|
+
await this.#setUpdateStateDate(difference.date);
|
|
672
|
+
this.#LrecoverUpdateGap.debug("there was no update gap");
|
|
283
673
|
break;
|
|
284
674
|
}
|
|
285
675
|
else {
|
|
@@ -288,40 +678,306 @@ class UpdateManager {
|
|
|
288
678
|
}
|
|
289
679
|
}
|
|
290
680
|
catch (err) {
|
|
291
|
-
|
|
681
|
+
this.#LrecoverUpdateGap.error(err);
|
|
292
682
|
}
|
|
293
683
|
finally {
|
|
294
684
|
unlock();
|
|
295
|
-
|
|
296
|
-
|
|
685
|
+
this.#c.resetConnectionState();
|
|
686
|
+
this.#recoveringUpdateGap = false;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
async #recoverChannelUpdateGap(channelId, source) {
|
|
690
|
+
let lastTimeout = 1;
|
|
691
|
+
this.#LrecoverChannelUpdateGap.debug(`recovering channel update gap [${channelId}, ${source}]`);
|
|
692
|
+
const pts_ = await this.#c.storage.getChannelPts(channelId);
|
|
693
|
+
let pts = pts_ == null ? 1 : pts_;
|
|
694
|
+
let retryIn = 5;
|
|
695
|
+
while (true) {
|
|
696
|
+
const { access_hash } = await this.#c.getInputPeer(_1_utilities_js_1.ZERO_CHANNEL_ID + -Number(channelId)).then((v) => _2_tl_js_1.Api.as("inputPeerChannel", v));
|
|
697
|
+
let difference;
|
|
698
|
+
try {
|
|
699
|
+
difference = await this.#c.invoke({
|
|
700
|
+
_: "updates.getChannelDifference",
|
|
701
|
+
pts,
|
|
702
|
+
channel: { _: "inputChannel", channel_id: channelId, access_hash },
|
|
703
|
+
filter: { _: "channelMessagesFilterEmpty" },
|
|
704
|
+
limit: await this.#c.storage.getAccountType() == "user" ? _4_constants_js_1.CHANNEL_DIFFERENCE_LIMIT_USER : _4_constants_js_1.CHANNEL_DIFFERENCE_LIMIT_BOT,
|
|
705
|
+
});
|
|
706
|
+
lastTimeout = difference.timeout ?? 1;
|
|
707
|
+
}
|
|
708
|
+
catch (err) {
|
|
709
|
+
if (err instanceof _3_errors_js_1.PersistentTimestampInvalid) {
|
|
710
|
+
await (0, _0_deps_js_1.delay)(retryIn * _0_deps_js_1.SECOND);
|
|
711
|
+
retryIn += 5;
|
|
712
|
+
if (retryIn > 60) {
|
|
713
|
+
retryIn = 60;
|
|
714
|
+
}
|
|
715
|
+
continue;
|
|
716
|
+
}
|
|
717
|
+
else {
|
|
718
|
+
throw err;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
if (_2_tl_js_1.Api.is("updates.channelDifference", difference)) {
|
|
722
|
+
await this.processChats(difference.chats, difference);
|
|
723
|
+
await this.processUsers(difference.users, difference);
|
|
724
|
+
for (const message of difference.new_messages) {
|
|
725
|
+
await this.#processUpdates({ _: "updateNewChannelMessage", message, pts: 0, pts_count: 0 }, false);
|
|
726
|
+
}
|
|
727
|
+
for (const update of difference.other_updates) {
|
|
728
|
+
await this.#processUpdates(update, false);
|
|
729
|
+
}
|
|
730
|
+
await this.#c.storage.setChannelPts(channelId, difference.pts);
|
|
731
|
+
this.#LrecoverChannelUpdateGap.debug(`recovered from update gap [${channelId}, ${source}]`, channelId, source);
|
|
732
|
+
break;
|
|
733
|
+
}
|
|
734
|
+
else if (_2_tl_js_1.Api.is("updates.channelDifferenceTooLong", difference)) {
|
|
735
|
+
// TODO: invalidate messages
|
|
736
|
+
this.#LrecoverChannelUpdateGap.debug("received channelDifferenceTooLong");
|
|
737
|
+
await this.processChats(difference.chats, difference);
|
|
738
|
+
await this.processUsers(difference.users, difference);
|
|
739
|
+
for (const message of difference.messages) {
|
|
740
|
+
await this.#processUpdates({ _: "updateNewChannelMessage", message, pts: 0, pts_count: 0 }, false);
|
|
741
|
+
}
|
|
742
|
+
const pts_ = _2_tl_js_1.Api.as("dialog", difference.dialog).pts;
|
|
743
|
+
if (pts_ != undefined) {
|
|
744
|
+
pts = pts_;
|
|
745
|
+
}
|
|
746
|
+
else {
|
|
747
|
+
(0, _0_deps_js_1.unreachable)();
|
|
748
|
+
}
|
|
749
|
+
this.#LrecoverChannelUpdateGap.debug("processed channelDifferenceTooLong");
|
|
750
|
+
}
|
|
751
|
+
else if (_2_tl_js_1.Api.is("updates.channelDifferenceEmpty", difference)) {
|
|
752
|
+
this.#LrecoverChannelUpdateGap.debug("there was no update gap");
|
|
753
|
+
break;
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
return lastTimeout;
|
|
757
|
+
}
|
|
758
|
+
#handleUpdatesSet = new Set();
|
|
759
|
+
async #handleStoredUpdates(boxId) {
|
|
760
|
+
if (this.#handleUpdatesSet.has(boxId)) {
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
this.#handleUpdatesSet.add(boxId);
|
|
764
|
+
do {
|
|
765
|
+
const maybeUpdate = await this.#c.storage.getFirstUpdate(boxId);
|
|
766
|
+
if (maybeUpdate == null) {
|
|
767
|
+
break;
|
|
768
|
+
}
|
|
769
|
+
const [key, update] = maybeUpdate;
|
|
770
|
+
for (let i = 0; i < 100; ++i) {
|
|
771
|
+
try {
|
|
772
|
+
const handle = await this.#handleUpdate(update);
|
|
773
|
+
handle: for (let i = 0; i < 2; ++i) {
|
|
774
|
+
try {
|
|
775
|
+
await handle();
|
|
776
|
+
break handle;
|
|
777
|
+
}
|
|
778
|
+
catch {
|
|
779
|
+
continue handle;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
break;
|
|
783
|
+
}
|
|
784
|
+
catch (err) {
|
|
785
|
+
this.#L$handleUpdate.error(err);
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
await this.#c.storage.set(key, null);
|
|
789
|
+
} while (true);
|
|
790
|
+
this.#handleUpdatesSet.delete(boxId);
|
|
791
|
+
}
|
|
792
|
+
#handleUpdate(update) {
|
|
793
|
+
const handler = this.#updateHandler;
|
|
794
|
+
if (handler) {
|
|
795
|
+
return handler(update);
|
|
796
|
+
}
|
|
797
|
+
else {
|
|
798
|
+
return Promise.resolve(() => Promise.resolve());
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
async #needsGetDifference(update) {
|
|
802
|
+
const chatIds = this.#collectChatIds(update);
|
|
803
|
+
if (!chatIds.size) {
|
|
804
|
+
return false;
|
|
805
|
+
}
|
|
806
|
+
return (await Promise.all(chatIds.values().map((v) => this.#c.messageStorage.getEntity(v)))).some((v) => !v);
|
|
807
|
+
}
|
|
808
|
+
#collectChatIds(object) {
|
|
809
|
+
const chatIds = new Set();
|
|
810
|
+
if (_2_tl_js_1.Api.is("messageFwdHeader", object)) {
|
|
811
|
+
if (object.from_id) {
|
|
812
|
+
chatIds.add((0, _2_telegram_js_1.peerToChatId)(object.from_id));
|
|
813
|
+
}
|
|
814
|
+
if (object.saved_from_peer) {
|
|
815
|
+
chatIds.add((0, _2_telegram_js_1.peerToChatId)(object.saved_from_peer));
|
|
816
|
+
}
|
|
817
|
+
return chatIds;
|
|
818
|
+
}
|
|
819
|
+
if (_2_tl_js_1.Api.isOfEnum("MessageMedia", object)) {
|
|
820
|
+
switch (object._) {
|
|
821
|
+
case "messageMediaContact":
|
|
822
|
+
if (object.user_id) {
|
|
823
|
+
chatIds.add((0, _2_telegram_js_1.peerToChatId)({ _: "peerUser", user_id: object.user_id }));
|
|
824
|
+
}
|
|
825
|
+
break;
|
|
826
|
+
case "messageMediaStory":
|
|
827
|
+
chatIds.add((0, _2_telegram_js_1.peerToChatId)(object.peer));
|
|
828
|
+
break;
|
|
829
|
+
case "messageMediaGiveaway":
|
|
830
|
+
for (const chatId of object.channels.map((v) => (0, _2_telegram_js_1.peerToChatId)({ _: "peerChannel", channel_id: v }))) {
|
|
831
|
+
chatIds.add(chatId);
|
|
832
|
+
}
|
|
833
|
+
break;
|
|
834
|
+
case "messageMediaGiveawayResults":
|
|
835
|
+
chatIds.add((0, _2_telegram_js_1.peerToChatId)({ _: "peerChannel", channel_id: object.channel_id }));
|
|
836
|
+
for (const chatId of object.winners.map((user_id) => (0, _2_telegram_js_1.peerToChatId)({ _: "peerUser", user_id }))) {
|
|
837
|
+
chatIds.add(chatId);
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
return chatIds;
|
|
841
|
+
}
|
|
842
|
+
// messsages
|
|
843
|
+
if (!("message" in object)) {
|
|
844
|
+
return chatIds;
|
|
845
|
+
}
|
|
846
|
+
if (_2_tl_js_1.Api.is("messageEmpty", object.message)) {
|
|
847
|
+
return chatIds;
|
|
848
|
+
}
|
|
849
|
+
chatIds.add((0, _2_telegram_js_1.peerToChatId)(object.message.peer_id));
|
|
850
|
+
if (object.message.from_id) {
|
|
851
|
+
chatIds.add((0, _2_telegram_js_1.peerToChatId)(object.message.from_id));
|
|
852
|
+
}
|
|
853
|
+
if (_2_tl_js_1.Api.is("messageService", object.message)) {
|
|
854
|
+
switch (object.message.action._) {
|
|
855
|
+
case "messageActionChatCreate":
|
|
856
|
+
case "messageActionChatAddUser":
|
|
857
|
+
case "messageActionInviteToGroupCall":
|
|
858
|
+
for (const user_id of object.message.action.users) {
|
|
859
|
+
chatIds.add((0, _2_telegram_js_1.peerToChatId)({ _: "peerUser", user_id }));
|
|
860
|
+
}
|
|
861
|
+
break;
|
|
862
|
+
case "messageActionChatDeleteUser":
|
|
863
|
+
chatIds.add((0, _2_telegram_js_1.peerToChatId)({ _: "peerUser", user_id: object.message.action.user_id }));
|
|
864
|
+
break;
|
|
865
|
+
case "messageActionChatMigrateTo":
|
|
866
|
+
chatIds.add((0, _2_telegram_js_1.peerToChatId)({ _: "peerChannel", channel_id: object.message.action.channel_id }));
|
|
867
|
+
break;
|
|
868
|
+
case "messageActionChannelMigrateFrom":
|
|
869
|
+
chatIds.add((0, _2_telegram_js_1.peerToChatId)({ _: "peerChat", chat_id: object.message.action.chat_id }));
|
|
870
|
+
break;
|
|
871
|
+
case "messageActionConferenceCall":
|
|
872
|
+
if (object.message.action.other_participants) {
|
|
873
|
+
for (const participant of object.message.action.other_participants) {
|
|
874
|
+
chatIds.add((0, _2_telegram_js_1.peerToChatId)(participant));
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
break;
|
|
878
|
+
case "messageActionPaymentRefunded":
|
|
879
|
+
chatIds.add((0, _2_telegram_js_1.peerToChatId)(object.message.action.peer));
|
|
880
|
+
break;
|
|
881
|
+
case "messageActionGiftCode":
|
|
882
|
+
if (object.message.action.boost_peer) {
|
|
883
|
+
chatIds.add((0, _2_telegram_js_1.peerToChatId)(object.message.action.boost_peer));
|
|
884
|
+
}
|
|
885
|
+
break;
|
|
886
|
+
case "messageActionRequestedPeer":
|
|
887
|
+
if (this.#c.storage.accountType === "user") {
|
|
888
|
+
for (const peer of object.message.action.peers) {
|
|
889
|
+
chatIds.add((0, _2_telegram_js_1.peerToChatId)(peer));
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
break;
|
|
893
|
+
case "messageActionSetMessagesTTL":
|
|
894
|
+
if (object.message.action.auto_setting_from) {
|
|
895
|
+
chatIds.add((0, _2_telegram_js_1.peerToChatId)({ _: "peerUser", user_id: object.message.action.auto_setting_from }));
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
else {
|
|
900
|
+
if (object.message.reply_to) {
|
|
901
|
+
switch (object.message.reply_to._) {
|
|
902
|
+
case "messageReplyHeader":
|
|
903
|
+
if (object.message.reply_to.reply_to_peer_id) {
|
|
904
|
+
chatIds.add((0, _2_telegram_js_1.peerToChatId)(object.message.reply_to.reply_to_peer_id));
|
|
905
|
+
}
|
|
906
|
+
if (object.message.reply_to.reply_from) {
|
|
907
|
+
for (const chatId of this.#collectChatIds(object.message.reply_to.reply_from)) {
|
|
908
|
+
chatIds.add(chatId);
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
if (object.message.reply_to.quote_entities) {
|
|
912
|
+
for (const chatId of this.#collectChatIdsFromEntities(object.message.reply_to.quote_entities)) {
|
|
913
|
+
chatIds.add(chatId);
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
if (object.message.reply_to.reply_media) {
|
|
917
|
+
for (const chatId of this.#collectChatIds(object.message.reply_to.reply_media)) {
|
|
918
|
+
chatIds.add(chatId);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
break;
|
|
922
|
+
case "messageReplyStoryHeader":
|
|
923
|
+
chatIds.add((0, _2_telegram_js_1.peerToChatId)(object.message.reply_to.peer));
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
if (object.message.fwd_from) {
|
|
927
|
+
for (const chatId of this.#collectChatIds(object.message.fwd_from)) {
|
|
928
|
+
chatIds.add(chatId);
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
if (object.message.via_bot_id) {
|
|
932
|
+
chatIds.add((0, _2_telegram_js_1.peerToChatId)({ _: "peerUser", user_id: object.message.via_bot_id }));
|
|
933
|
+
}
|
|
934
|
+
if (object.message.entities) {
|
|
935
|
+
for (const chatId of this.#collectChatIdsFromEntities(object.message.entities)) {
|
|
936
|
+
chatIds.add(chatId);
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
if (object.message.media) {
|
|
940
|
+
for (const chatId of this.#collectChatIds(object.message.media)) {
|
|
941
|
+
chatIds.add(chatId);
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
return chatIds;
|
|
946
|
+
}
|
|
947
|
+
#collectChatIdsFromEntities(entities) {
|
|
948
|
+
const chatIds = new Array();
|
|
949
|
+
for (const user_id of entities.filter((v) => _2_tl_js_1.Api.is("messageEntityMentionName", v)).map((v) => v.user_id)) {
|
|
950
|
+
chatIds.push((0, _2_telegram_js_1.peerToChatId)({ _: "peerUser", user_id }));
|
|
297
951
|
}
|
|
952
|
+
return chatIds;
|
|
298
953
|
}
|
|
299
954
|
setUpdateHandler(handler) {
|
|
300
|
-
|
|
955
|
+
this.#updateHandler = handler;
|
|
301
956
|
}
|
|
957
|
+
#openChats = new Map();
|
|
302
958
|
async openChat(chatId) {
|
|
303
|
-
const channel = await
|
|
959
|
+
const channel = await this.#c.getInputChannel(chatId);
|
|
304
960
|
const channelId = channel.channel_id;
|
|
305
|
-
if (
|
|
961
|
+
if (this.#openChats.has(channelId)) {
|
|
306
962
|
return;
|
|
307
963
|
}
|
|
308
964
|
const controller = new AbortController();
|
|
309
965
|
const promise = Promise.resolve().then(async () => {
|
|
310
|
-
const logger =
|
|
966
|
+
const logger = this.#LopenChat.branch(_2_tl_js_1.Api.peerToChatId(channel) + "");
|
|
311
967
|
while (true) {
|
|
312
|
-
if (
|
|
968
|
+
if (this.#c.disconnected()) {
|
|
313
969
|
logger.debug("disconnected, stopping the loop");
|
|
314
|
-
|
|
970
|
+
this.#openChats.delete(channelId);
|
|
315
971
|
break;
|
|
316
972
|
}
|
|
317
|
-
if (!
|
|
973
|
+
if (!this.#openChats.has(channelId)) {
|
|
318
974
|
const aborted = controller.signal.aborted;
|
|
319
975
|
logger.debug(`closed${(aborted ? " (aborted)" : "")}, stopping the loop`);
|
|
320
976
|
break;
|
|
321
977
|
}
|
|
322
978
|
try {
|
|
323
979
|
const Ti = Date.now();
|
|
324
|
-
const timeout = await
|
|
980
|
+
const timeout = await this.#recoverChannelUpdateGap(channelId, "openChat");
|
|
325
981
|
const dT = Date.now() - Ti;
|
|
326
982
|
const delay = Math.max(timeout * 1_000 - dT, 0);
|
|
327
983
|
logger.debug("timeout=", timeout, "delay=", delay, "dT=", dT);
|
|
@@ -340,20 +996,20 @@ class UpdateManager {
|
|
|
340
996
|
}
|
|
341
997
|
}
|
|
342
998
|
catch (err) {
|
|
343
|
-
if (
|
|
999
|
+
if (this.#c.disconnected()) {
|
|
344
1000
|
continue; // breaks the loop
|
|
345
1001
|
}
|
|
346
|
-
|
|
1002
|
+
this.#LopenChat.error("An unexpected error occurred:", err);
|
|
347
1003
|
}
|
|
348
1004
|
}
|
|
349
1005
|
});
|
|
350
|
-
|
|
1006
|
+
this.#openChats.set(channelId, { controller, promise });
|
|
351
1007
|
}
|
|
352
1008
|
async closeChat(chatId) {
|
|
353
|
-
const { channel_id } = await
|
|
354
|
-
const openChat =
|
|
1009
|
+
const { channel_id } = await this.#c.getInputChannel(chatId);
|
|
1010
|
+
const openChat = this.#openChats.get(channel_id);
|
|
355
1011
|
if (openChat) {
|
|
356
|
-
|
|
1012
|
+
this.#openChats.delete(channel_id);
|
|
357
1013
|
openChat.controller.abort();
|
|
358
1014
|
}
|
|
359
1015
|
else {
|
|
@@ -361,662 +1017,11 @@ class UpdateManager {
|
|
|
361
1017
|
}
|
|
362
1018
|
}
|
|
363
1019
|
closeAllChats() {
|
|
364
|
-
for (const [channelId, openChat] of
|
|
365
|
-
|
|
1020
|
+
for (const [channelId, openChat] of this.#openChats.entries()) {
|
|
1021
|
+
this.#openChats.delete(channelId);
|
|
366
1022
|
openChat.controller.abort();
|
|
367
1023
|
}
|
|
368
1024
|
}
|
|
369
1025
|
}
|
|
370
1026
|
exports.UpdateManager = UpdateManager;
|
|
371
|
-
_a = UpdateManager
|
|
372
|
-
if (typeof __classPrivateFieldGet(this, _UpdateManager_c, "f").dropPendingUpdates === "boolean") {
|
|
373
|
-
return __classPrivateFieldGet(this, _UpdateManager_c, "f").dropPendingUpdates;
|
|
374
|
-
}
|
|
375
|
-
if (__classPrivateFieldGet(this, _UpdateManager_defaultDropPendingUpdates, "f") == null) {
|
|
376
|
-
__classPrivateFieldSet(this, _UpdateManager_defaultDropPendingUpdates, await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.getAccountType() == "bot", "f");
|
|
377
|
-
}
|
|
378
|
-
return __classPrivateFieldGet(this, _UpdateManager_defaultDropPendingUpdates, "f");
|
|
379
|
-
}, _UpdateManager_getState = async function _UpdateManager_getState() {
|
|
380
|
-
if (await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_mustDropPendingUpdates).call(this)) {
|
|
381
|
-
return __classPrivateFieldGet(this, _UpdateManager_state, "f") ?? null;
|
|
382
|
-
}
|
|
383
|
-
if (__classPrivateFieldGet(this, _UpdateManager_state, "f") !== undefined) {
|
|
384
|
-
return __classPrivateFieldGet(this, _UpdateManager_state, "f");
|
|
385
|
-
}
|
|
386
|
-
const state = await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.getState();
|
|
387
|
-
return __classPrivateFieldSet(this, _UpdateManager_state, state, "f");
|
|
388
|
-
}, _UpdateManager_setState = async function _UpdateManager_setState(state) {
|
|
389
|
-
__classPrivateFieldSet(this, _UpdateManager_state, state, "f");
|
|
390
|
-
if (!await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_mustDropPendingUpdates).call(this)) {
|
|
391
|
-
await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.setState(state);
|
|
392
|
-
}
|
|
393
|
-
}, _UpdateManager_extractMessages = function _UpdateManager_extractMessages(context) {
|
|
394
|
-
const messages = new Array();
|
|
395
|
-
if (Array.isArray(context)) {
|
|
396
|
-
for (const item of context) {
|
|
397
|
-
messages.push(...__classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_extractMessages).call(this, item));
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
else if (_2_tl_js_1.Api.isOneOf(["updates", "updatesCombined"], context)) {
|
|
401
|
-
messages.push(...__classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_extractMessages).call(this, context.updates));
|
|
402
|
-
}
|
|
403
|
-
else if (_2_tl_js_1.Api.isOneOf(["updates.difference", "updates.differenceSlice", "updates.channelDifference"], context)) {
|
|
404
|
-
for (const message of context.new_messages) {
|
|
405
|
-
if (_2_tl_js_1.Api.is("message", message)) {
|
|
406
|
-
messages.push(message);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
messages.push(...__classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_extractMessages).call(this, context.other_updates));
|
|
410
|
-
}
|
|
411
|
-
else if (_2_tl_js_1.Api.isOneOf(["updateNewMessage", "updateNewChannelMessage", "updateEditMessage", "updateEditChannelMessage", "updateBotNewBusinessMessage", "updateBotNewBusinessMessage"], context)) {
|
|
412
|
-
if (_2_tl_js_1.Api.is("message", context.message)) {
|
|
413
|
-
messages.push(context.message);
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
else if (_2_tl_js_1.Api.is("message", context)) {
|
|
417
|
-
messages.push(context);
|
|
418
|
-
}
|
|
419
|
-
else if (context != null && typeof context === "object" && "messages" in context && Array.isArray(context.messages)) {
|
|
420
|
-
for (const message of context.messages) {
|
|
421
|
-
if (_2_tl_js_1.Api.is("message", message)) {
|
|
422
|
-
messages.push(message);
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
return messages;
|
|
427
|
-
}, _UpdateManager_extractMinPeerReferences = function _UpdateManager_extractMinPeerReferences(context) {
|
|
428
|
-
const minPeerReferences = new Array();
|
|
429
|
-
const messages = __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_extractMessages).call(this, context);
|
|
430
|
-
for (const message of messages) {
|
|
431
|
-
if (!message.from_id) {
|
|
432
|
-
continue;
|
|
433
|
-
}
|
|
434
|
-
minPeerReferences.push({ chatId: _2_tl_js_1.Api.peerToChatId(message.peer_id), senderId: _2_tl_js_1.Api.peerToChatId(message.from_id), messageId: message.id });
|
|
435
|
-
}
|
|
436
|
-
return minPeerReferences;
|
|
437
|
-
}, _UpdateManager_getChannelPtsWithDropPendingUpdatesCheck = async function _UpdateManager_getChannelPtsWithDropPendingUpdatesCheck(channelId) {
|
|
438
|
-
if (!(await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_mustDropPendingUpdates).call(this))) {
|
|
439
|
-
return await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.getChannelPts(channelId);
|
|
440
|
-
}
|
|
441
|
-
const first = !__classPrivateFieldGet(this, _UpdateManager_nonFirst, "f").has(channelId);
|
|
442
|
-
if (first) {
|
|
443
|
-
__classPrivateFieldGet(this, _UpdateManager_nonFirst, "f").add(channelId);
|
|
444
|
-
return null;
|
|
445
|
-
}
|
|
446
|
-
else {
|
|
447
|
-
return await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.getChannelPts(channelId);
|
|
448
|
-
}
|
|
449
|
-
}, _UpdateManager_checkGap = async function _UpdateManager_checkGap(pts, ptsCount) {
|
|
450
|
-
const localState = await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_getLocalState).call(this);
|
|
451
|
-
if (localState.pts + ptsCount < pts) {
|
|
452
|
-
await this.recoverUpdateGap("processUpdates[pts]");
|
|
453
|
-
}
|
|
454
|
-
}, _UpdateManager_checkGapQts = async function _UpdateManager_checkGapQts(qts) {
|
|
455
|
-
const localState = await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_getLocalState).call(this);
|
|
456
|
-
if (localState.qts + _a.QTS_COUNT < qts) {
|
|
457
|
-
await this.recoverUpdateGap("processUpdates[qts]");
|
|
458
|
-
}
|
|
459
|
-
}, _UpdateManager_checkChannelGap = async function _UpdateManager_checkChannelGap(channelId, pts, ptsCount) {
|
|
460
|
-
let localPts = await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_getChannelPtsWithDropPendingUpdatesCheck).call(this, channelId);
|
|
461
|
-
if (!localPts) {
|
|
462
|
-
localPts = pts - ptsCount;
|
|
463
|
-
}
|
|
464
|
-
if (localPts + ptsCount < pts) {
|
|
465
|
-
await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_recoverChannelUpdateGap).call(this, channelId, "processUpdates");
|
|
466
|
-
}
|
|
467
|
-
}, _UpdateManager_processChannelPtsUpdateInner = async function _UpdateManager_processChannelPtsUpdateInner(update, checkGap) {
|
|
468
|
-
const channelId = _2_tl_js_1.Api.is("updateNewChannelMessage", update) || _2_tl_js_1.Api.is("updateEditChannelMessage", update) ? _2_tl_js_1.Api.as("peerChannel", update.message.peer_id).channel_id : update.channel_id;
|
|
469
|
-
if (_2_tl_js_1.Api.is("updateChannelTooLong", update)) {
|
|
470
|
-
if (update.pts != undefined) {
|
|
471
|
-
await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.setChannelPts(channelId, update.pts);
|
|
472
|
-
}
|
|
473
|
-
await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_recoverChannelUpdateGap).call(this, channelId, "updateChannelTooLong");
|
|
474
|
-
return;
|
|
475
|
-
}
|
|
476
|
-
if (update.pts != 0) {
|
|
477
|
-
const ptsCount = update.pts_count;
|
|
478
|
-
if (checkGap) {
|
|
479
|
-
await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_checkChannelGap).call(this, channelId, update.pts, ptsCount);
|
|
480
|
-
}
|
|
481
|
-
let currentPts = await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_getChannelPtsWithDropPendingUpdatesCheck).call(this, channelId);
|
|
482
|
-
currentPts ??= update.pts - ptsCount;
|
|
483
|
-
if (currentPts + ptsCount > update.pts) {
|
|
484
|
-
return;
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
if (__classPrivateFieldGet(this, _UpdateManager_c, "f").guaranteeUpdateDelivery) {
|
|
488
|
-
await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.setUpdate(channelId, update);
|
|
489
|
-
}
|
|
490
|
-
if (update.pts != 0) {
|
|
491
|
-
await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.setChannelPts(channelId, update.pts);
|
|
492
|
-
}
|
|
493
|
-
__classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_queueUpdate).call(this, update, channelId, true);
|
|
494
|
-
}, _UpdateManager_queueUpdate = function _UpdateManager_queueUpdate(update, boxId, pts) {
|
|
495
|
-
this.getHandleUpdateQueue(boxId).add(async () => {
|
|
496
|
-
if (__classPrivateFieldGet(this, _UpdateManager_c, "f").guaranteeUpdateDelivery && pts) {
|
|
497
|
-
await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_handleStoredUpdates).call(this, boxId);
|
|
498
|
-
}
|
|
499
|
-
else {
|
|
500
|
-
await (await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_handleUpdate).call(this, update))();
|
|
501
|
-
}
|
|
502
|
-
});
|
|
503
|
-
}, _UpdateManager_processChannelPtsUpdate = function _UpdateManager_processChannelPtsUpdate(update, checkGap) {
|
|
504
|
-
const channelId = _2_tl_js_1.Api.is("updateNewChannelMessage", update) || _2_tl_js_1.Api.is("updateEditChannelMessage", update) ? _2_tl_js_1.Api.as("peerChannel", update.message.peer_id).channel_id : update.channel_id;
|
|
505
|
-
let queue = __classPrivateFieldGet(this, _UpdateManager_channelUpdateQueues, "f").get(channelId);
|
|
506
|
-
if (queue == undefined) {
|
|
507
|
-
queue = new _1_utilities_js_1.Queue(`channelUpdates-${channelId}`);
|
|
508
|
-
__classPrivateFieldGet(this, _UpdateManager_channelUpdateQueues, "f").set(channelId, queue);
|
|
509
|
-
}
|
|
510
|
-
queue.add(async () => {
|
|
511
|
-
await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_processChannelPtsUpdateInner).call(this, update, checkGap);
|
|
512
|
-
});
|
|
513
|
-
}, _UpdateManager_processPtsUpdateInner = async function _UpdateManager_processPtsUpdateInner(update, checkGap) {
|
|
514
|
-
if (update.pts != 0 && checkGap) {
|
|
515
|
-
await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_checkGap).call(this, update.pts, update.pts_count);
|
|
516
|
-
if (await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_needsGetDifference).call(this, update)) {
|
|
517
|
-
await this.recoverUpdateGap("needsGetDifference");
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
const localState = await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_getLocalState).call(this);
|
|
521
|
-
if (localState.pts + update.pts_count > update.pts) {
|
|
522
|
-
return;
|
|
523
|
-
}
|
|
524
|
-
if (__classPrivateFieldGet(this, _UpdateManager_c, "f").guaranteeUpdateDelivery) {
|
|
525
|
-
await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.setUpdate(_a.MAIN_BOX_ID, update);
|
|
526
|
-
}
|
|
527
|
-
if (update.pts != 0) {
|
|
528
|
-
await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_setUpdatePts).call(this, update.pts);
|
|
529
|
-
}
|
|
530
|
-
__classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_queueUpdate).call(this, update, 1n, false);
|
|
531
|
-
}, _UpdateManager_processPtsUpdate = function _UpdateManager_processPtsUpdate(update, checkGap) {
|
|
532
|
-
__classPrivateFieldGet(this, _UpdateManager_ptsUpdateQueue, "f").add(async () => {
|
|
533
|
-
await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_processPtsUpdateInner).call(this, update, checkGap);
|
|
534
|
-
});
|
|
535
|
-
}, _UpdateManager_processQtsUpdateInner = async function _UpdateManager_processQtsUpdateInner(update, checkGap) {
|
|
536
|
-
const localState = await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_getLocalState).call(this);
|
|
537
|
-
if (update.qts != 0) {
|
|
538
|
-
if (checkGap) {
|
|
539
|
-
await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_checkGapQts).call(this, update.qts);
|
|
540
|
-
}
|
|
541
|
-
if (localState.qts + _a.QTS_COUNT > update.qts) {
|
|
542
|
-
return;
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
if (__classPrivateFieldGet(this, _UpdateManager_c, "f").guaranteeUpdateDelivery) {
|
|
546
|
-
await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.setUpdate(_a.MAIN_BOX_ID, update);
|
|
547
|
-
}
|
|
548
|
-
if (update.qts != 0) {
|
|
549
|
-
await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_setUpdateQts).call(this, update.qts);
|
|
550
|
-
}
|
|
551
|
-
__classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_queueUpdate).call(this, update, 0n, true);
|
|
552
|
-
}, _UpdateManager_processQtsUpdate = function _UpdateManager_processQtsUpdate(update, checkGap) {
|
|
553
|
-
__classPrivateFieldGet(this, _UpdateManager_qtsUpdateQueue, "f").add(async () => {
|
|
554
|
-
await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_processQtsUpdateInner).call(this, update, checkGap);
|
|
555
|
-
});
|
|
556
|
-
}, _UpdateManager_processUpdates = async function _UpdateManager_processUpdates(updates_, checkGap, call = null) {
|
|
557
|
-
/// First, individual updates (Update[1]) are extracted from Updates.[2]
|
|
558
|
-
///
|
|
559
|
-
/// If an updatesTooLong[3] was received, an update gap recovery is initiated and no further action will be taken.
|
|
560
|
-
///
|
|
561
|
-
/// [1]: https://core.telegram.org/type/Update
|
|
562
|
-
/// [2]: https://core.telegram.org/type/Updates
|
|
563
|
-
/// [3]: https://core.telegram.org/constructor/updatesTooLong
|
|
564
|
-
let updates;
|
|
565
|
-
if (_2_tl_js_1.Api.is("updatesCombined", updates_) || _2_tl_js_1.Api.is("updates", updates_)) {
|
|
566
|
-
updates = updates_.updates;
|
|
567
|
-
const seq = updates_.seq;
|
|
568
|
-
const seqStart = "seq_start" in updates_ ? updates_.seq_start : updates_.seq;
|
|
569
|
-
if (checkGap) {
|
|
570
|
-
if (seqStart == 0) {
|
|
571
|
-
checkGap = false;
|
|
572
|
-
__classPrivateFieldGet(this, _UpdateManager_L$processUpdates, "f").debug("seqStart=0");
|
|
573
|
-
}
|
|
574
|
-
else {
|
|
575
|
-
const localState = await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_getLocalState).call(this);
|
|
576
|
-
const localSeq = localState.seq;
|
|
577
|
-
if (localSeq + 1 == seqStart) {
|
|
578
|
-
// The update sequence can be applied.
|
|
579
|
-
localState.seq = seq;
|
|
580
|
-
localState.date = updates_.date;
|
|
581
|
-
await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_setUpdateStateDate).call(this, updates_.date);
|
|
582
|
-
await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_setState).call(this, localState);
|
|
583
|
-
}
|
|
584
|
-
else if (localSeq + 1 > seqStart) {
|
|
585
|
-
// The update sequence was already applied, and must be ignored.
|
|
586
|
-
__classPrivateFieldGet(this, _UpdateManager_L$processUpdates, "f").debug("localSeq + 1 > seqStart");
|
|
587
|
-
return;
|
|
588
|
-
}
|
|
589
|
-
else if (localSeq + 1 < seqStart) {
|
|
590
|
-
// There's an updates gap that must be filled.
|
|
591
|
-
await this.recoverUpdateGap("localSeq + 1 < seqStart");
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
else if (_2_tl_js_1.Api.is("updateShort", updates_)) {
|
|
597
|
-
updates = [updates_.update];
|
|
598
|
-
}
|
|
599
|
-
else if (_2_tl_js_1.Api.is("updateShortMessage", updates_)) {
|
|
600
|
-
updates = [
|
|
601
|
-
{
|
|
602
|
-
_: "updateNewMessage",
|
|
603
|
-
message: ({
|
|
604
|
-
_: "message",
|
|
605
|
-
out: updates_.out,
|
|
606
|
-
mentioned: updates_.mentioned,
|
|
607
|
-
media_unread: updates_.media_unread,
|
|
608
|
-
silent: updates_.silent,
|
|
609
|
-
id: updates_.id,
|
|
610
|
-
from_id: updates_.out ? ({ _: "peerUser", user_id: BigInt(await __classPrivateFieldGet(this, _UpdateManager_c, "f").getSelfId()) }) : ({ _: "peerUser", user_id: updates_.user_id }),
|
|
611
|
-
peer_id: ({ _: "peerUser", user_id: updates_.user_id }),
|
|
612
|
-
message: updates_.message,
|
|
613
|
-
date: updates_.date,
|
|
614
|
-
fwd_from: updates_.fwd_from,
|
|
615
|
-
via_bot_id: updates_.via_bot_id,
|
|
616
|
-
reply_to: updates_.reply_to,
|
|
617
|
-
entities: updates_.entities,
|
|
618
|
-
ttl_period: updates_.ttl_period,
|
|
619
|
-
}),
|
|
620
|
-
pts: updates_.pts,
|
|
621
|
-
pts_count: updates_.pts_count,
|
|
622
|
-
},
|
|
623
|
-
];
|
|
624
|
-
}
|
|
625
|
-
else if (_2_tl_js_1.Api.is("updateShortChatMessage", updates_)) {
|
|
626
|
-
updates = [
|
|
627
|
-
{
|
|
628
|
-
_: "updateNewMessage",
|
|
629
|
-
message: ({
|
|
630
|
-
_: "message",
|
|
631
|
-
mentioned: updates_.mentioned,
|
|
632
|
-
media_unread: updates_.media_unread,
|
|
633
|
-
silent: updates_.silent,
|
|
634
|
-
id: updates_.id,
|
|
635
|
-
from_id: { _: "peerUser", user_id: updates_.from_id },
|
|
636
|
-
peer_id: { _: "peerChat", chat_id: updates_.chat_id },
|
|
637
|
-
fwd_from: updates_.fwd_from,
|
|
638
|
-
via_bot_id: updates_.via_bot_id,
|
|
639
|
-
reply_to: updates_.reply_to,
|
|
640
|
-
date: updates_.date,
|
|
641
|
-
message: updates_.message,
|
|
642
|
-
entities: updates_.entities,
|
|
643
|
-
ttl_period: updates_.ttl_period,
|
|
644
|
-
}),
|
|
645
|
-
pts: updates_.pts,
|
|
646
|
-
pts_count: updates_.pts_count,
|
|
647
|
-
},
|
|
648
|
-
];
|
|
649
|
-
}
|
|
650
|
-
else if (_2_tl_js_1.Api.is("updateShortSentMessage", updates_)) {
|
|
651
|
-
if (!_2_tl_js_1.Api.is("messages.sendMessage", call)) {
|
|
652
|
-
(0, _0_deps_js_1.unreachable)();
|
|
653
|
-
}
|
|
654
|
-
updates = [{
|
|
655
|
-
_: "updateNewMessage",
|
|
656
|
-
message: ({
|
|
657
|
-
_: "message",
|
|
658
|
-
out: updates_.out,
|
|
659
|
-
silent: call.silent,
|
|
660
|
-
id: updates_.id,
|
|
661
|
-
from_id: { _: "peerUser", user_id: BigInt(await __classPrivateFieldGet(this, _UpdateManager_c, "f").getSelfId()) },
|
|
662
|
-
peer_id: _2_tl_js_1.Api.inputPeerToPeer(call.peer),
|
|
663
|
-
message: call.message,
|
|
664
|
-
media: updates_.media,
|
|
665
|
-
date: updates_.date,
|
|
666
|
-
// reply_to: call.reply_to, // TODO?
|
|
667
|
-
entities: updates_.entities,
|
|
668
|
-
ttl_period: updates_.ttl_period,
|
|
669
|
-
}),
|
|
670
|
-
pts: updates_.pts,
|
|
671
|
-
pts_count: updates_.pts_count,
|
|
672
|
-
}];
|
|
673
|
-
}
|
|
674
|
-
else if (_2_tl_js_1.Api.is("updatesTooLong", updates_)) {
|
|
675
|
-
await this.recoverUpdateGap("updatesTooLong");
|
|
676
|
-
return;
|
|
677
|
-
}
|
|
678
|
-
else if (_2_tl_js_1.Api.isOfEnum("Update", updates_)) {
|
|
679
|
-
updates = [updates_];
|
|
680
|
-
}
|
|
681
|
-
else {
|
|
682
|
-
(0, _0_deps_js_1.unreachable)();
|
|
683
|
-
}
|
|
684
|
-
/// We process the updates when we are sure there is no gap.
|
|
685
|
-
if (_2_tl_js_1.Api.is("updates", updates_) || _2_tl_js_1.Api.is("updatesCombined", updates_)) {
|
|
686
|
-
await this.processChats(updates_.chats, updates_);
|
|
687
|
-
await this.processUsers(updates_.users, updates_);
|
|
688
|
-
await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_setUpdateStateDate).call(this, updates_.date);
|
|
689
|
-
}
|
|
690
|
-
else if (_2_tl_js_1.Api.isOneOf([
|
|
691
|
-
"updateShort",
|
|
692
|
-
"updateShortMessage",
|
|
693
|
-
"updateShortChatMessage",
|
|
694
|
-
"updateShortSentMessage",
|
|
695
|
-
], updates_)) {
|
|
696
|
-
await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_setUpdateStateDate).call(this, updates_.date);
|
|
697
|
-
}
|
|
698
|
-
for (const update of updates) {
|
|
699
|
-
if (_2_tl_js_1.Api.is("updatePtsChanged", update)) {
|
|
700
|
-
await this.fetchState("updatePtsChanged");
|
|
701
|
-
if (__classPrivateFieldGet(this, _UpdateManager_updateState, "f")) {
|
|
702
|
-
await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_setState).call(this, __classPrivateFieldGet(this, _UpdateManager_updateState, "f"));
|
|
703
|
-
}
|
|
704
|
-
else {
|
|
705
|
-
(0, _0_deps_js_1.unreachable)();
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
else if (_a.isPtsUpdate(update)) {
|
|
709
|
-
__classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_processPtsUpdate).call(this, update, checkGap);
|
|
710
|
-
}
|
|
711
|
-
else if (_a.isChannelPtsUpdate(update)) {
|
|
712
|
-
__classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_processChannelPtsUpdate).call(this, update, checkGap);
|
|
713
|
-
}
|
|
714
|
-
else if (_a.isQtsUpdate(update)) {
|
|
715
|
-
__classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_processQtsUpdate).call(this, update, checkGap);
|
|
716
|
-
}
|
|
717
|
-
else {
|
|
718
|
-
__classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_queueUpdate).call(this, update, 0n, false);
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
}, _UpdateManager_setUpdateStateDate = async function _UpdateManager_setUpdateStateDate(date) {
|
|
722
|
-
const localState = await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_getLocalState).call(this);
|
|
723
|
-
localState.date = date;
|
|
724
|
-
await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_setState).call(this, localState);
|
|
725
|
-
}, _UpdateManager_setUpdatePts = async function _UpdateManager_setUpdatePts(pts) {
|
|
726
|
-
const localState = await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_getLocalState).call(this);
|
|
727
|
-
localState.pts = pts;
|
|
728
|
-
await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_setState).call(this, localState);
|
|
729
|
-
}, _UpdateManager_setUpdateQts = async function _UpdateManager_setUpdateQts(qts) {
|
|
730
|
-
const localState = await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_getLocalState).call(this);
|
|
731
|
-
localState.qts = qts;
|
|
732
|
-
await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_setState).call(this, localState);
|
|
733
|
-
}, _UpdateManager_getLocalState = async function _UpdateManager_getLocalState() {
|
|
734
|
-
let localState = await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_getState).call(this);
|
|
735
|
-
if (!localState) {
|
|
736
|
-
if (__classPrivateFieldGet(this, _UpdateManager_updateState, "f")) {
|
|
737
|
-
localState = __classPrivateFieldGet(this, _UpdateManager_updateState, "f");
|
|
738
|
-
await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_setState).call(this, localState);
|
|
739
|
-
}
|
|
740
|
-
else {
|
|
741
|
-
await this.fetchState("getLocalState");
|
|
742
|
-
if (__classPrivateFieldGet(this, _UpdateManager_updateState, "f")) {
|
|
743
|
-
localState = __classPrivateFieldGet(this, _UpdateManager_updateState, "f");
|
|
744
|
-
await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_setState).call(this, localState);
|
|
745
|
-
}
|
|
746
|
-
else {
|
|
747
|
-
(0, _0_deps_js_1.unreachable)();
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
return localState;
|
|
752
|
-
}, _UpdateManager_recoverChannelUpdateGap = async function _UpdateManager_recoverChannelUpdateGap(channelId, source) {
|
|
753
|
-
let lastTimeout = 1;
|
|
754
|
-
__classPrivateFieldGet(this, _UpdateManager_LrecoverChannelUpdateGap, "f").debug(`recovering channel update gap [${channelId}, ${source}]`);
|
|
755
|
-
const pts_ = await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.getChannelPts(channelId);
|
|
756
|
-
let pts = pts_ == null ? 1 : pts_;
|
|
757
|
-
let retryIn = 5;
|
|
758
|
-
while (true) {
|
|
759
|
-
const { access_hash } = await __classPrivateFieldGet(this, _UpdateManager_c, "f").getInputPeer(_1_utilities_js_1.ZERO_CHANNEL_ID + -Number(channelId)).then((v) => _2_tl_js_1.Api.as("inputPeerChannel", v));
|
|
760
|
-
let difference;
|
|
761
|
-
try {
|
|
762
|
-
difference = await __classPrivateFieldGet(this, _UpdateManager_c, "f").invoke({
|
|
763
|
-
_: "updates.getChannelDifference",
|
|
764
|
-
pts,
|
|
765
|
-
channel: { _: "inputChannel", channel_id: channelId, access_hash },
|
|
766
|
-
filter: { _: "channelMessagesFilterEmpty" },
|
|
767
|
-
limit: await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.getAccountType() == "user" ? _4_constants_js_1.CHANNEL_DIFFERENCE_LIMIT_USER : _4_constants_js_1.CHANNEL_DIFFERENCE_LIMIT_BOT,
|
|
768
|
-
});
|
|
769
|
-
lastTimeout = difference.timeout ?? 1;
|
|
770
|
-
}
|
|
771
|
-
catch (err) {
|
|
772
|
-
if (err instanceof _3_errors_js_1.PersistentTimestampInvalid) {
|
|
773
|
-
await (0, _0_deps_js_1.delay)(retryIn * _0_deps_js_1.SECOND);
|
|
774
|
-
retryIn += 5;
|
|
775
|
-
if (retryIn > 60) {
|
|
776
|
-
retryIn = 60;
|
|
777
|
-
}
|
|
778
|
-
continue;
|
|
779
|
-
}
|
|
780
|
-
else {
|
|
781
|
-
throw err;
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
if (_2_tl_js_1.Api.is("updates.channelDifference", difference)) {
|
|
785
|
-
await this.processChats(difference.chats, difference);
|
|
786
|
-
await this.processUsers(difference.users, difference);
|
|
787
|
-
for (const message of difference.new_messages) {
|
|
788
|
-
await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_processUpdates).call(this, { _: "updateNewChannelMessage", message, pts: 0, pts_count: 0 }, false);
|
|
789
|
-
}
|
|
790
|
-
for (const update of difference.other_updates) {
|
|
791
|
-
await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_processUpdates).call(this, update, false);
|
|
792
|
-
}
|
|
793
|
-
await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.setChannelPts(channelId, difference.pts);
|
|
794
|
-
__classPrivateFieldGet(this, _UpdateManager_LrecoverChannelUpdateGap, "f").debug(`recovered from update gap [${channelId}, ${source}]`, channelId, source);
|
|
795
|
-
break;
|
|
796
|
-
}
|
|
797
|
-
else if (_2_tl_js_1.Api.is("updates.channelDifferenceTooLong", difference)) {
|
|
798
|
-
// TODO: invalidate messages
|
|
799
|
-
__classPrivateFieldGet(this, _UpdateManager_LrecoverChannelUpdateGap, "f").debug("received channelDifferenceTooLong");
|
|
800
|
-
await this.processChats(difference.chats, difference);
|
|
801
|
-
await this.processUsers(difference.users, difference);
|
|
802
|
-
for (const message of difference.messages) {
|
|
803
|
-
await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_processUpdates).call(this, { _: "updateNewChannelMessage", message, pts: 0, pts_count: 0 }, false);
|
|
804
|
-
}
|
|
805
|
-
const pts_ = _2_tl_js_1.Api.as("dialog", difference.dialog).pts;
|
|
806
|
-
if (pts_ != undefined) {
|
|
807
|
-
pts = pts_;
|
|
808
|
-
}
|
|
809
|
-
else {
|
|
810
|
-
(0, _0_deps_js_1.unreachable)();
|
|
811
|
-
}
|
|
812
|
-
__classPrivateFieldGet(this, _UpdateManager_LrecoverChannelUpdateGap, "f").debug("processed channelDifferenceTooLong");
|
|
813
|
-
}
|
|
814
|
-
else if (_2_tl_js_1.Api.is("updates.channelDifferenceEmpty", difference)) {
|
|
815
|
-
__classPrivateFieldGet(this, _UpdateManager_LrecoverChannelUpdateGap, "f").debug("there was no update gap");
|
|
816
|
-
break;
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
return lastTimeout;
|
|
820
|
-
}, _UpdateManager_handleStoredUpdates = async function _UpdateManager_handleStoredUpdates(boxId) {
|
|
821
|
-
if (__classPrivateFieldGet(this, _UpdateManager_handleUpdatesSet, "f").has(boxId)) {
|
|
822
|
-
return;
|
|
823
|
-
}
|
|
824
|
-
__classPrivateFieldGet(this, _UpdateManager_handleUpdatesSet, "f").add(boxId);
|
|
825
|
-
do {
|
|
826
|
-
const maybeUpdate = await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.getFirstUpdate(boxId);
|
|
827
|
-
if (maybeUpdate == null) {
|
|
828
|
-
break;
|
|
829
|
-
}
|
|
830
|
-
const [key, update] = maybeUpdate;
|
|
831
|
-
for (let i = 0; i < 100; ++i) {
|
|
832
|
-
try {
|
|
833
|
-
const handle = await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_handleUpdate).call(this, update);
|
|
834
|
-
handle: for (let i = 0; i < 2; ++i) {
|
|
835
|
-
try {
|
|
836
|
-
await handle();
|
|
837
|
-
break handle;
|
|
838
|
-
}
|
|
839
|
-
catch {
|
|
840
|
-
continue handle;
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
break;
|
|
844
|
-
}
|
|
845
|
-
catch (err) {
|
|
846
|
-
__classPrivateFieldGet(this, _UpdateManager_L$handleUpdate, "f").error(err);
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
await __classPrivateFieldGet(this, _UpdateManager_c, "f").storage.set(key, null);
|
|
850
|
-
} while (true);
|
|
851
|
-
__classPrivateFieldGet(this, _UpdateManager_handleUpdatesSet, "f").delete(boxId);
|
|
852
|
-
}, _UpdateManager_handleUpdate = function _UpdateManager_handleUpdate(update) {
|
|
853
|
-
const handler = __classPrivateFieldGet(this, _UpdateManager_updateHandler, "f");
|
|
854
|
-
if (handler) {
|
|
855
|
-
return handler(update);
|
|
856
|
-
}
|
|
857
|
-
else {
|
|
858
|
-
return Promise.resolve(() => Promise.resolve());
|
|
859
|
-
}
|
|
860
|
-
}, _UpdateManager_needsGetDifference = async function _UpdateManager_needsGetDifference(update) {
|
|
861
|
-
const chatIds = __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_collectChatIds).call(this, update);
|
|
862
|
-
if (!chatIds.size) {
|
|
863
|
-
return false;
|
|
864
|
-
}
|
|
865
|
-
return (await Promise.all(chatIds.values().map((v) => __classPrivateFieldGet(this, _UpdateManager_c, "f").messageStorage.getEntity(v)))).some((v) => !v);
|
|
866
|
-
}, _UpdateManager_collectChatIds = function _UpdateManager_collectChatIds(object) {
|
|
867
|
-
const chatIds = new Set();
|
|
868
|
-
if (_2_tl_js_1.Api.is("messageFwdHeader", object)) {
|
|
869
|
-
if (object.from_id) {
|
|
870
|
-
chatIds.add((0, _2_telegram_js_1.peerToChatId)(object.from_id));
|
|
871
|
-
}
|
|
872
|
-
if (object.saved_from_peer) {
|
|
873
|
-
chatIds.add((0, _2_telegram_js_1.peerToChatId)(object.saved_from_peer));
|
|
874
|
-
}
|
|
875
|
-
return chatIds;
|
|
876
|
-
}
|
|
877
|
-
if (_2_tl_js_1.Api.isOfEnum("MessageMedia", object)) {
|
|
878
|
-
switch (object._) {
|
|
879
|
-
case "messageMediaContact":
|
|
880
|
-
if (object.user_id) {
|
|
881
|
-
chatIds.add((0, _2_telegram_js_1.peerToChatId)({ _: "peerUser", user_id: object.user_id }));
|
|
882
|
-
}
|
|
883
|
-
break;
|
|
884
|
-
case "messageMediaStory":
|
|
885
|
-
chatIds.add((0, _2_telegram_js_1.peerToChatId)(object.peer));
|
|
886
|
-
break;
|
|
887
|
-
case "messageMediaGiveaway":
|
|
888
|
-
for (const chatId of object.channels.map((v) => (0, _2_telegram_js_1.peerToChatId)({ _: "peerChannel", channel_id: v }))) {
|
|
889
|
-
chatIds.add(chatId);
|
|
890
|
-
}
|
|
891
|
-
break;
|
|
892
|
-
case "messageMediaGiveawayResults":
|
|
893
|
-
chatIds.add((0, _2_telegram_js_1.peerToChatId)({ _: "peerChannel", channel_id: object.channel_id }));
|
|
894
|
-
for (const chatId of object.winners.map((user_id) => (0, _2_telegram_js_1.peerToChatId)({ _: "peerUser", user_id }))) {
|
|
895
|
-
chatIds.add(chatId);
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
return chatIds;
|
|
899
|
-
}
|
|
900
|
-
// messsages
|
|
901
|
-
if (!("message" in object)) {
|
|
902
|
-
return chatIds;
|
|
903
|
-
}
|
|
904
|
-
if (_2_tl_js_1.Api.is("messageEmpty", object.message)) {
|
|
905
|
-
return chatIds;
|
|
906
|
-
}
|
|
907
|
-
chatIds.add((0, _2_telegram_js_1.peerToChatId)(object.message.peer_id));
|
|
908
|
-
if (object.message.from_id) {
|
|
909
|
-
chatIds.add((0, _2_telegram_js_1.peerToChatId)(object.message.from_id));
|
|
910
|
-
}
|
|
911
|
-
if (_2_tl_js_1.Api.is("messageService", object.message)) {
|
|
912
|
-
switch (object.message.action._) {
|
|
913
|
-
case "messageActionChatCreate":
|
|
914
|
-
case "messageActionChatAddUser":
|
|
915
|
-
case "messageActionInviteToGroupCall":
|
|
916
|
-
for (const user_id of object.message.action.users) {
|
|
917
|
-
chatIds.add((0, _2_telegram_js_1.peerToChatId)({ _: "peerUser", user_id }));
|
|
918
|
-
}
|
|
919
|
-
break;
|
|
920
|
-
case "messageActionChatDeleteUser":
|
|
921
|
-
chatIds.add((0, _2_telegram_js_1.peerToChatId)({ _: "peerUser", user_id: object.message.action.user_id }));
|
|
922
|
-
break;
|
|
923
|
-
case "messageActionChatMigrateTo":
|
|
924
|
-
chatIds.add((0, _2_telegram_js_1.peerToChatId)({ _: "peerChannel", channel_id: object.message.action.channel_id }));
|
|
925
|
-
break;
|
|
926
|
-
case "messageActionChannelMigrateFrom":
|
|
927
|
-
chatIds.add((0, _2_telegram_js_1.peerToChatId)({ _: "peerChat", chat_id: object.message.action.chat_id }));
|
|
928
|
-
break;
|
|
929
|
-
case "messageActionConferenceCall":
|
|
930
|
-
if (object.message.action.other_participants) {
|
|
931
|
-
for (const participant of object.message.action.other_participants) {
|
|
932
|
-
chatIds.add((0, _2_telegram_js_1.peerToChatId)(participant));
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
break;
|
|
936
|
-
case "messageActionPaymentRefunded":
|
|
937
|
-
chatIds.add((0, _2_telegram_js_1.peerToChatId)(object.message.action.peer));
|
|
938
|
-
break;
|
|
939
|
-
case "messageActionGiftCode":
|
|
940
|
-
if (object.message.action.boost_peer) {
|
|
941
|
-
chatIds.add((0, _2_telegram_js_1.peerToChatId)(object.message.action.boost_peer));
|
|
942
|
-
}
|
|
943
|
-
break;
|
|
944
|
-
case "messageActionRequestedPeer":
|
|
945
|
-
if (__classPrivateFieldGet(this, _UpdateManager_c, "f").storage.accountType === "user") {
|
|
946
|
-
for (const peer of object.message.action.peers) {
|
|
947
|
-
chatIds.add((0, _2_telegram_js_1.peerToChatId)(peer));
|
|
948
|
-
}
|
|
949
|
-
}
|
|
950
|
-
break;
|
|
951
|
-
case "messageActionSetMessagesTTL":
|
|
952
|
-
if (object.message.action.auto_setting_from) {
|
|
953
|
-
chatIds.add((0, _2_telegram_js_1.peerToChatId)({ _: "peerUser", user_id: object.message.action.auto_setting_from }));
|
|
954
|
-
}
|
|
955
|
-
}
|
|
956
|
-
}
|
|
957
|
-
else {
|
|
958
|
-
if (object.message.reply_to) {
|
|
959
|
-
switch (object.message.reply_to._) {
|
|
960
|
-
case "messageReplyHeader":
|
|
961
|
-
if (object.message.reply_to.reply_to_peer_id) {
|
|
962
|
-
chatIds.add((0, _2_telegram_js_1.peerToChatId)(object.message.reply_to.reply_to_peer_id));
|
|
963
|
-
}
|
|
964
|
-
if (object.message.reply_to.reply_from) {
|
|
965
|
-
for (const chatId of __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_collectChatIds).call(this, object.message.reply_to.reply_from)) {
|
|
966
|
-
chatIds.add(chatId);
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
if (object.message.reply_to.quote_entities) {
|
|
970
|
-
for (const chatId of __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_collectChatIdsFromEntities).call(this, object.message.reply_to.quote_entities)) {
|
|
971
|
-
chatIds.add(chatId);
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
if (object.message.reply_to.reply_media) {
|
|
975
|
-
for (const chatId of __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_collectChatIds).call(this, object.message.reply_to.reply_media)) {
|
|
976
|
-
chatIds.add(chatId);
|
|
977
|
-
}
|
|
978
|
-
}
|
|
979
|
-
break;
|
|
980
|
-
case "messageReplyStoryHeader":
|
|
981
|
-
chatIds.add((0, _2_telegram_js_1.peerToChatId)(object.message.reply_to.peer));
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
if (object.message.fwd_from) {
|
|
985
|
-
for (const chatId of __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_collectChatIds).call(this, object.message.fwd_from)) {
|
|
986
|
-
chatIds.add(chatId);
|
|
987
|
-
}
|
|
988
|
-
}
|
|
989
|
-
if (object.message.via_bot_id) {
|
|
990
|
-
chatIds.add((0, _2_telegram_js_1.peerToChatId)({ _: "peerUser", user_id: object.message.via_bot_id }));
|
|
991
|
-
}
|
|
992
|
-
if (object.message.entities) {
|
|
993
|
-
for (const chatId of __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_collectChatIdsFromEntities).call(this, object.message.entities)) {
|
|
994
|
-
chatIds.add(chatId);
|
|
995
|
-
}
|
|
996
|
-
}
|
|
997
|
-
if (object.message.media) {
|
|
998
|
-
for (const chatId of __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_collectChatIds).call(this, object.message.media)) {
|
|
999
|
-
chatIds.add(chatId);
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
return chatIds;
|
|
1004
|
-
}, _UpdateManager_collectChatIdsFromEntities = function _UpdateManager_collectChatIdsFromEntities(entities) {
|
|
1005
|
-
const chatIds = new Array();
|
|
1006
|
-
for (const user_id of entities.filter((v) => _2_tl_js_1.Api.is("messageEntityMentionName", v)).map((v) => v.user_id)) {
|
|
1007
|
-
chatIds.push((0, _2_telegram_js_1.peerToChatId)({ _: "peerUser", user_id }));
|
|
1008
|
-
}
|
|
1009
|
-
return chatIds;
|
|
1010
|
-
};
|
|
1011
|
-
Object.defineProperty(UpdateManager, "QTS_COUNT", {
|
|
1012
|
-
enumerable: true,
|
|
1013
|
-
configurable: true,
|
|
1014
|
-
writable: true,
|
|
1015
|
-
value: 1
|
|
1016
|
-
});
|
|
1017
|
-
Object.defineProperty(UpdateManager, "MAIN_BOX_ID", {
|
|
1018
|
-
enumerable: true,
|
|
1019
|
-
configurable: true,
|
|
1020
|
-
writable: true,
|
|
1021
|
-
value: 0n
|
|
1022
|
-
});
|
|
1027
|
+
_a = UpdateManager;
|