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