From 8b97d2e8e4e0397df03e5847454641dc5330cb95 Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 13 Jan 2024 00:42:49 +0300 Subject: [PATCH] Move binlog events processing to Td::process_binlog_events. --- td/telegram/Td.cpp | 54 +++++++++++++++++++++++++--------------------- td/telegram/Td.h | 2 ++ 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index a267a39e0..7eb59cec6 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -3652,6 +3652,35 @@ void Td::init(Parameters parameters, Result r_opened_datab option_manager_->on_td_inited(); + if (is_online_) { + on_online_updated(true, true); + } + if (auth_manager_->is_bot()) { + set_is_bot_online(true); + } + + process_binlog_events(std::move(events)); + + VLOG(td_init) << "Ping datacenter"; + if (!auth_manager_->is_authorized()) { + country_info_manager_->get_current_country_code(Promise()); + } else { + updates_manager_->get_difference("init"); + schedule_get_terms_of_service(0); + reload_promo_data(); + } + + complete_pending_preauthentication_requests([](int32 id) { return true; }); + + VLOG(td_init) << "Finish initialization"; + + state_ = State::Run; + + send_closure(actor_id(this), &Td::send_result, set_parameters_request_id_, td_api::make_object()); + return finish_set_parameters(); +} + +void Td::process_binlog_events(TdDb::OpenedDatabase &&events) { VLOG(td_init) << "Send binlog events"; for (auto &event : events.user_events) { contacts_manager_->on_binlog_user_event(std::move(event)); @@ -3678,13 +3707,6 @@ void Td::init(Parameters parameters, Result r_opened_datab on_save_app_log_binlog_event(this, std::move(event)); } - if (is_online_) { - on_online_updated(true, true); - } - if (auth_manager_->is_bot()) { - set_is_bot_online(true); - } - // Send binlog events to managers // // 1. Actors must receive all binlog events before other queries. @@ -3722,24 +3744,6 @@ void Td::init(Parameters parameters, Result r_opened_datab std::move(events.to_notification_settings_manager)); send_closure(secret_chats_manager_, &SecretChatsManager::binlog_replay_finish); - - VLOG(td_init) << "Ping datacenter"; - if (!auth_manager_->is_authorized()) { - country_info_manager_->get_current_country_code(Promise()); - } else { - updates_manager_->get_difference("init"); - schedule_get_terms_of_service(0); - reload_promo_data(); - } - - complete_pending_preauthentication_requests([](int32 id) { return true; }); - - VLOG(td_init) << "Finish initialization"; - - state_ = State::Run; - - send_closure(actor_id(this), &Td::send_result, set_parameters_request_id_, td_api::make_object()); - return finish_set_parameters(); } void Td::init_options_and_network() { diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 78bc77d54..d8847675e 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1835,6 +1835,8 @@ class Td final : public Actor { void init_managers(); + void process_binlog_events(TdDb::OpenedDatabase &&events); + void clear(); void close_impl(bool destroy_flag);