Add Global::log_out helper.

This commit is contained in:
levlam 2022-05-02 20:59:07 +03:00
parent 6b838b706b
commit 746816e7d7
4 changed files with 10 additions and 4 deletions

View File

@ -31,11 +31,17 @@ Global::Global() = default;
Global::~Global() = default;
void Global::log_out(Slice reason) {
CHECK(shared_config_ != nullptr);
shared_config_->set_option_string("auth", reason);
}
void Global::close_all(Promise<> on_finished) {
td_db_->close_all(std::move(on_finished));
state_manager_.clear();
parameters_ = TdParameters();
}
void Global::close_and_destroy_all(Promise<> on_finished) {
td_db_->close_and_destroy_all(std::move(on_finished));
state_manager_.clear();

View File

@ -84,6 +84,8 @@ class Global final : public ActorContext {
return td_db_.get();
}
void log_out(Slice reason);
void close_all(Promise<> on_finished);
void close_and_destroy_all(Promise<> on_finished);

View File

@ -6,7 +6,6 @@
//
#include "td/telegram/net/DcAuthManager.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/Global.h"
#include "td/telegram/net/AuthDataShared.h"
#include "td/telegram/net/NetQuery.h"
@ -233,7 +232,7 @@ void DcAuthManager::loop() {
auto main_dc = find_dc(main_dc_id_.get_raw_id());
if (!main_dc || main_dc->auth_key_state != AuthKeyState::OK) {
if (need_check_authorization_is_ok_) {
G()->shared_config().set_option_string("auth", "Authorization check failed in DcAuthManager");
G()->log_out("Authorization check failed in DcAuthManager");
}
VLOG(dc) << "Skip loop, because main DC is " << main_dc_id_ << ", main auth key state is "
<< (main_dc != nullptr ? main_dc->auth_key_state : AuthKeyState::Empty);

View File

@ -6,7 +6,6 @@
//
#include "td/telegram/net/Session.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/DhCache.h"
#include "td/telegram/Global.h"
#include "td/telegram/net/DcAuthManager.h"
@ -837,7 +836,7 @@ void Session::on_message_result_error(uint64 id, int error_code, string message)
"write to recover@telegram.org your phone number and other details to recover the account.";
}
auth_data_.set_auth_flag(false);
G()->shared_config().set_option_string("auth", message);
G()->log_out(message);
shared_auth_data_->set_auth_key(auth_data_.get_main_auth_key());
on_session_failed(Status::OK());
}