diff --git a/td/telegram/AccountManager.cpp b/td/telegram/AccountManager.cpp index 2a6941a6f..7d32578ed 100644 --- a/td/telegram/AccountManager.cpp +++ b/td/telegram/AccountManager.cpp @@ -811,9 +811,37 @@ void AccountManager::get_active_sessions(Promisecreate_handler(std::move(promise))->send(); } +class AccountManager::ResetAuthorizationOnServerLogEvent { + public: + int64 hash_; + + template + void store(StorerT &storer) const { + td::store(hash_, storer); + } + + template + void parse(ParserT &parser) { + td::parse(hash_, parser); + } +}; + +void AccountManager::reset_authorization_on_server(int64 hash, uint64 log_event_id, Promise &&promise) { + if (log_event_id == 0) { + ResetAuthorizationOnServerLogEvent log_event{hash}; + log_event_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ResetAuthorizationOnServer, + get_log_event_storer(log_event)); + } + + auto new_promise = get_erase_log_event_promise(log_event_id, std::move(promise)); + promise = std::move(new_promise); // to prevent self-move + + td_->create_handler(std::move(promise))->send(hash); +} + void AccountManager::terminate_session(int64 session_id, Promise &&promise) { on_confirm_authorization(session_id); - td_->create_handler(std::move(promise))->send(session_id); + reset_authorization_on_server(session_id, 0, std::move(promise)); } void AccountManager::terminate_all_other_sessions(Promise &&promise) { @@ -860,28 +888,20 @@ class AccountManager::ChangeAuthorizationSettingsOnServerLogEvent { } }; -uint64 AccountManager::save_change_authorization_settings_on_server_log_event( - int64 hash, bool set_encrypted_requests_disabled, bool encrypted_requests_disabled, bool set_call_requests_disabled, - bool call_requests_disabled, bool confirm) { - ChangeAuthorizationSettingsOnServerLogEvent log_event{hash, - set_encrypted_requests_disabled, - encrypted_requests_disabled, - set_call_requests_disabled, - call_requests_disabled, - confirm}; - return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ChangeAuthorizationSettingsOnServer, - get_log_event_storer(log_event)); -} - void AccountManager::change_authorization_settings_on_server(int64 hash, bool set_encrypted_requests_disabled, bool encrypted_requests_disabled, bool set_call_requests_disabled, bool call_requests_disabled, bool confirm, uint64 log_event_id, Promise &&promise) { if (log_event_id == 0) { - log_event_id = save_change_authorization_settings_on_server_log_event( - hash, set_encrypted_requests_disabled, encrypted_requests_disabled, set_call_requests_disabled, - call_requests_disabled, confirm); + ChangeAuthorizationSettingsOnServerLogEvent log_event{hash, + set_encrypted_requests_disabled, + encrypted_requests_disabled, + set_call_requests_disabled, + call_requests_disabled, + confirm}; + log_event_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ChangeAuthorizationSettingsOnServer, + get_log_event_storer(log_event)); } auto new_promise = get_erase_log_event_promise(log_event_id, std::move(promise)); @@ -1061,6 +1081,13 @@ void AccountManager::on_binlog_events(vector &&events) { Auto()); break; } + case LogEvent::HandlerType::ResetAuthorizationOnServer: { + ResetAuthorizationOnServerLogEvent log_event; + log_event_parse(log_event, event.get_data()).ensure(); + + reset_authorization_on_server(log_event.hash_, event.id_, Auto()); + break; + } default: LOG(FATAL) << "Unsupported log event type " << event.type_; } diff --git a/td/telegram/AccountManager.h b/td/telegram/AccountManager.h index 9ee9bba02..393d9298c 100644 --- a/td/telegram/AccountManager.h +++ b/td/telegram/AccountManager.h @@ -79,6 +79,7 @@ class AccountManager final : public Actor { class UnconfirmedAuthorizations; class ChangeAuthorizationSettingsOnServerLogEvent; + class ResetAuthorizationOnServerLogEvent; void start_up() final; @@ -98,16 +99,13 @@ class AccountManager final : public Actor { void send_update_unconfirmed_session() const; - uint64 save_change_authorization_settings_on_server_log_event(int64 hash, bool set_encrypted_requests_disabled, - bool encrypted_requests_disabled, - bool set_call_requests_disabled, - bool call_requests_disabled, bool confirm); - void change_authorization_settings_on_server(int64 hash, bool set_encrypted_requests_disabled, bool encrypted_requests_disabled, bool set_call_requests_disabled, bool call_requests_disabled, bool confirm, uint64 log_event_id, Promise &&promise); + void reset_authorization_on_server(int64 hash, uint64 log_event_id, Promise &&promise); + Td *td_; ActorShared<> parent_; diff --git a/td/telegram/TdDb.cpp b/td/telegram/TdDb.cpp index f09256f06..e5701fae3 100644 --- a/td/telegram/TdDb.cpp +++ b/td/telegram/TdDb.cpp @@ -145,6 +145,7 @@ Status init_binlog(Binlog &binlog, string path, BinlogKeyValue &binlog_p events.save_app_log_events.push_back(event.clone()); break; case LogEvent::HandlerType::ChangeAuthorizationSettingsOnServer: + case LogEvent::HandlerType::ResetAuthorizationOnServer: events.to_account_manager.push_back(event.clone()); break; case LogEvent::HandlerType::BinlogPmcMagic: diff --git a/td/telegram/logevent/LogEvent.h b/td/telegram/logevent/LogEvent.h index 480e067ae..5429b9a66 100644 --- a/td/telegram/logevent/LogEvent.h +++ b/td/telegram/logevent/LogEvent.h @@ -113,6 +113,7 @@ class LogEvent { SendStory = 0x403, EditStory = 0x404, ChangeAuthorizationSettingsOnServer = 0x500, + ResetAuthorizationOnServer = 0x501, ConfigPmcMagic = 0x1f18, BinlogPmcMagic = 0x4327 };