From f9161dccc3a7d8271ea75552610c58cdf6719f58 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 17 Aug 2022 20:01:03 +0300 Subject: [PATCH] Remove "auth" internal option. --- td/telegram/AuthManager.cpp | 4 ++++ td/telegram/Global.cpp | 5 ++--- td/telegram/Global.h | 6 ++++++ td/telegram/OptionManager.cpp | 6 +----- td/telegram/Td.cpp | 1 + 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/td/telegram/AuthManager.cpp b/td/telegram/AuthManager.cpp index 1c48bae00..a7a2d3476 100644 --- a/td/telegram/AuthManager.cpp +++ b/td/telegram/AuthManager.cpp @@ -720,6 +720,10 @@ void AuthManager::on_authorization_lost(string source) { LOG(INFO) << "Ignore authorization loss because of " << source << ", while logging out"; return; } + if (state_ == State::Closing || state_ == State::DestroyingKeys) { + LOG(INFO) << "Ignore duplicate authorization loss because of " << source; + return; + } LOG(WARNING) << "Lost authorization because of " << source; destroy_auth_keys(); } diff --git a/td/telegram/Global.cpp b/td/telegram/Global.cpp index 066c5a6c3..0adebb4ca 100644 --- a/td/telegram/Global.cpp +++ b/td/telegram/Global.cpp @@ -6,6 +6,7 @@ // #include "td/telegram/Global.h" +#include "td/telegram/AuthManager.h" #include "td/telegram/ConfigShared.h" #include "td/telegram/net/ConnectionCreator.h" #include "td/telegram/net/NetQueryDispatcher.h" @@ -29,9 +30,7 @@ Global::Global() = default; Global::~Global() = default; void Global::log_out(Slice reason) { - if (!have_option("auth")) { - set_option_string("auth", reason); - } + send_closure(auth_manager_, &AuthManager::on_authorization_lost, reason.str()); } void Global::close_all(Promise<> on_finished) { diff --git a/td/telegram/Global.h b/td/telegram/Global.h index 049403f07..eedb0a82b 100644 --- a/td/telegram/Global.h +++ b/td/telegram/Global.h @@ -34,6 +34,7 @@ namespace td { class AnimationsManager; class AttachMenuManager; +class AuthManager; class BackgroundManager; class CallManager; class ConfigManager; @@ -206,6 +207,10 @@ class Global final : public ActorContext { attach_menu_manager_ = attach_menu_manager; } + void set_auth_manager(ActorId auth_manager) { + auth_manager_ = auth_manager; + } + ActorId background_manager() const { return background_manager_; } @@ -479,6 +484,7 @@ class Global final : public ActorContext { ActorId td_; ActorId animations_manager_; ActorId attach_menu_manager_; + ActorId auth_manager_; ActorId background_manager_; ActorId call_manager_; ActorId config_manager_; diff --git a/td/telegram/OptionManager.cpp b/td/telegram/OptionManager.cpp index ae8c95f90..7a27b482b 100644 --- a/td/telegram/OptionManager.cpp +++ b/td/telegram/OptionManager.cpp @@ -128,8 +128,7 @@ bool OptionManager::is_internal_option(Slice name) { switch (name[0]) { case 'a': return name == "about_length_limit_default" || name == "about_length_limit_premium" || - name == "animated_emoji_zoom" || name == "animation_search_emojis" || - name == "animation_search_provider" || name == "auth"; + name == "animated_emoji_zoom" || name == "animation_search_emojis" || name == "animation_search_provider"; case 'b': return name == "base_language_pack_version"; case 'c': @@ -201,9 +200,6 @@ void OptionManager::on_option_updated(const string &name) { if (name == "animation_search_provider") { td_->animations_manager_->on_update_animation_search_provider(G()->get_option_string(name)); } - if (name == "auth") { - send_closure(td_->auth_manager_actor_, &AuthManager::on_authorization_lost, G()->get_option_string(name)); - } break; case 'b': if (name == "base_language_pack_version") { diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 4026534c7..9b8f59e9d 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -3674,6 +3674,7 @@ void Td::init(Result r_opened_database) { VLOG(td_init) << "Create AuthManager"; auth_manager_ = td::make_unique(parameters_.api_id, parameters_.api_hash, create_reference()); auth_manager_actor_ = register_actor("AuthManager", auth_manager_.get()); + G()->set_auth_manager(auth_manager_actor_.get()); init_file_manager();