diff --git a/td/telegram/AuthManager.cpp b/td/telegram/AuthManager.cpp index 5836d0efe..efb032825 100644 --- a/td/telegram/AuthManager.cpp +++ b/td/telegram/AuthManager.cpp @@ -59,6 +59,7 @@ AuthManager::AuthManager(int32 api_id, const string &api_hash, ActorShared<> par td, PromiseCreator::lambda([this](Result result) { update_state(State::Ok); })); } } else if (auth_str == "logout") { + LOG(WARNING) << "Continue to log out"; update_state(State::LoggingOut); } else if (auth_str == "destroy") { update_state(State::DestroyingKeys); @@ -345,10 +346,11 @@ void AuthManager::log_out(uint64 query_id) { if (state_ != State::Ok) { // TODO: could skip full logout if still no authorization // TODO: send auth.cancelCode if state_ == State::WaitCode + LOG(WARNING) << "Destroying auth keys by user request"; destroy_auth_keys(); on_query_ok(); } else { - LOG(INFO) << "Logging out"; + LOG(WARNING) << "Logging out by user request"; G()->td_db()->get_binlog_pmc()->set("auth", "logout"); update_state(State::LoggingOut); send_log_out_query(); @@ -628,12 +630,13 @@ void AuthManager::on_log_out_result(NetQueryPtr &result) { on_query_ok(); } } -void AuthManager::on_authorization_lost() { +void AuthManager::on_authorization_lost(const string &source) { + LOG(WARNING) << "Lost authorization because of " << source; destroy_auth_keys(); } void AuthManager::destroy_auth_keys() { - if (state_ == State::Closing) { + if (state_ == State::Closing || state_ == State::DestroyingKeys) { return; } update_state(State::DestroyingKeys); diff --git a/td/telegram/AuthManager.h b/td/telegram/AuthManager.h index dd071021f..5336a1c03 100644 --- a/td/telegram/AuthManager.h +++ b/td/telegram/AuthManager.h @@ -48,7 +48,7 @@ class AuthManager : public NetActor { void on_update_login_token(); - void on_authorization_lost(); + void on_authorization_lost(const string &source); void on_closing(bool destroy_flag); // can return nullptr if state isn't initialized yet diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index 9261d3baa..72f6b6777 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -3027,7 +3027,7 @@ Status NotificationManager::process_push_notification_payload(string payload, bo if (loc_key == "SESSION_REVOKE") { if (was_encrypted) { - send_closure(td_->auth_manager_actor_, &AuthManager::on_authorization_lost); + send_closure(td_->auth_manager_actor_, &AuthManager::on_authorization_lost, "SESSION_REVOKE"); } else { LOG(ERROR) << "Receive unencrypted SESSION_REVOKE push notification"; } diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index d98f7106d..216301ae4 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -3607,7 +3607,9 @@ void Td::on_config_option_updated(const string &name) { return; } if (name == "auth") { - return on_authorization_lost(); + send_closure(auth_manager_actor_, &AuthManager::on_authorization_lost, + G()->shared_config().get_option_string(name)); + return; } else if (name == "saved_animations_limit") { return animations_manager_->on_update_saved_animations_limit( narrow_cast(G()->shared_config().get_option_integer(name))); @@ -3715,11 +3717,6 @@ void Td::on_connection_state_changed(StateManager::State new_state) { make_tl_object(get_connection_state_object(connection_state_))); } -void Td::on_authorization_lost() { - LOG(WARNING) << "Lost authorization"; - send_closure(auth_manager_actor_, &AuthManager::on_authorization_lost); -} - void Td::start_up() { always_wait_for_mailbox(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 1a12c4d59..620fa32d1 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -116,8 +116,6 @@ class Td final : public NetQueryCallback { void on_update_server_time_difference(); - void on_authorization_lost(); - void on_online_updated(bool force, bool send_update); void on_update_status_success(bool is_online); diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 88f7bc5b5..e20718267 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -909,6 +909,9 @@ void UpdatesManager::on_failed_get_difference(Status &&error) { } void UpdatesManager::schedule_get_difference(const char *source) { + if (G()->close_flag()) { + return; + } if (!retry_timeout_.has_timeout()) { LOG(WARNING) << "Schedule getDifference in " << retry_time_ << " seconds with pts = " << get_pts() << ", qts = " << get_qts() << ", date = " << get_date() << " from " << source; diff --git a/td/telegram/net/Session.cpp b/td/telegram/net/Session.cpp index b2a13c4ed..2b53e3af1 100644 --- a/td/telegram/net/Session.cpp +++ b/td/telegram/net/Session.cpp @@ -780,11 +780,9 @@ void Session::on_message_result_error(uint64 id, int error_code, BufferSlice mes if (message.as_slice() == CSlice("USER_DEACTIVATED_BAN")) { LOG(PLAIN) << "Your account was suspended for suspicious activity. If you think that this is a mistake, please " "write to recover@telegram.org your phone number and other details to recover the account."; - } else { - LOG(WARNING) << "Lost authorization due to " << tag("msg", message.as_slice()); } auth_data_.set_auth_flag(false); - G()->shared_config().set_option_boolean("auth", false); + G()->shared_config().set_option_string("auth", message.as_slice().str()); shared_auth_data_->set_auth_key(auth_data_.get_main_auth_key()); on_session_failed(Status::OK()); }