From 3de61c80f212f9532332379f0afe7aa311e0d8f5 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 18 Aug 2022 19:54:04 +0300 Subject: [PATCH] Postpone some getOption requests until initialization. --- td/telegram/OptionManager.cpp | 22 ++++++++++++++++++---- td/telegram/OptionManager.h | 2 ++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/td/telegram/OptionManager.cpp b/td/telegram/OptionManager.cpp index 3e788e118..2421cfaa8 100644 --- a/td/telegram/OptionManager.cpp +++ b/td/telegram/OptionManager.cpp @@ -112,6 +112,11 @@ void OptionManager::on_td_inited() { have_pending_is_location_visible_ = false; td_->contacts_manager_->set_location_visibility(); } + + for (auto &request : pending_get_options_) { + get_option(request.first, std::move(request.second)); + } + reset_to_empty(pending_get_options_); } void OptionManager::set_option_boolean(Slice name, bool value) { @@ -463,8 +468,13 @@ void OptionManager::get_option(const string &name, Promisenotification_manager_actor_, - &NotificationManager::get_disable_contact_registered_notifications, wrap_promise()); + if (is_td_inited_) { + send_closure_later(td_->notification_manager_actor_, + &NotificationManager::get_disable_contact_registered_notifications, wrap_promise()); + } else { + pending_get_options_.emplace_back(name, std::move(promise)); + } + return; } break; case 'i': @@ -472,8 +482,12 @@ void OptionManager::get_option(const string &name, Promiseconfig_manager_, &ConfigManager::get_content_settings, wrap_promise()); } if (!is_bot && name == "is_location_visible") { - return send_closure_later(td_->contacts_manager_actor_, &ContactsManager::get_is_location_visible, - wrap_promise()); + if (is_td_inited_) { + send_closure_later(td_->contacts_manager_actor_, &ContactsManager::get_is_location_visible, wrap_promise()); + } else { + pending_get_options_.emplace_back(name, std::move(promise)); + } + return; } break; case 'o': diff --git a/td/telegram/OptionManager.h b/td/telegram/OptionManager.h index 6f6315675..c9e7e44d1 100644 --- a/td/telegram/OptionManager.h +++ b/td/telegram/OptionManager.h @@ -14,6 +14,7 @@ #include #include +#include namespace td { @@ -84,6 +85,7 @@ class OptionManager { Td *td_; bool is_td_inited_ = false; bool have_pending_is_location_visible_ = false; + vector>>> pending_get_options_; unique_ptr options_; std::shared_ptr option_pmc_;