Add ResetAuthorizationsOnServerLogEvent.

This commit is contained in:
levlam 2023-09-22 14:50:44 +03:00
parent f2b2f01c33
commit b222f48d05
4 changed files with 37 additions and 1 deletions

View File

@ -844,6 +844,30 @@ void AccountManager::terminate_session(int64 session_id, Promise<Unit> &&promise
reset_authorization_on_server(session_id, 0, std::move(promise)); reset_authorization_on_server(session_id, 0, std::move(promise));
} }
class AccountManager::ResetAuthorizationsOnServerLogEvent {
public:
template <class StorerT>
void store(StorerT &storer) const {
}
template <class ParserT>
void parse(ParserT &parser) {
}
};
void AccountManager::reset_authorizations_on_server(uint64 log_event_id, Promise<Unit> &&promise) {
if (log_event_id == 0) {
ResetAuthorizationsOnServerLogEvent log_event;
log_event_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ResetAuthorizationsOnServer,
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<ResetAuthorizationsQuery>(std::move(promise))->send();
}
void AccountManager::terminate_all_other_sessions(Promise<Unit> &&promise) { void AccountManager::terminate_all_other_sessions(Promise<Unit> &&promise) {
if (unconfirmed_authorizations_ != nullptr) { if (unconfirmed_authorizations_ != nullptr) {
unconfirmed_authorizations_ = nullptr; unconfirmed_authorizations_ = nullptr;
@ -851,7 +875,7 @@ void AccountManager::terminate_all_other_sessions(Promise<Unit> &&promise) {
send_update_unconfirmed_session(); send_update_unconfirmed_session();
save_unconfirmed_authorizations(); save_unconfirmed_authorizations();
} }
td_->create_handler<ResetAuthorizationsQuery>(std::move(promise))->send(); reset_authorizations_on_server(0, std::move(promise));
} }
class AccountManager::ChangeAuthorizationSettingsOnServerLogEvent { class AccountManager::ChangeAuthorizationSettingsOnServerLogEvent {
@ -1088,6 +1112,13 @@ void AccountManager::on_binlog_events(vector<BinlogEvent> &&events) {
reset_authorization_on_server(log_event.hash_, event.id_, Auto()); reset_authorization_on_server(log_event.hash_, event.id_, Auto());
break; break;
} }
case LogEvent::HandlerType::ResetAuthorizationsOnServer: {
ResetAuthorizationsOnServerLogEvent log_event;
log_event_parse(log_event, event.get_data()).ensure();
reset_authorizations_on_server(event.id_, Auto());
break;
}
default: default:
LOG(FATAL) << "Unsupported log event type " << event.type_; LOG(FATAL) << "Unsupported log event type " << event.type_;
} }

View File

@ -80,6 +80,7 @@ class AccountManager final : public Actor {
class ChangeAuthorizationSettingsOnServerLogEvent; class ChangeAuthorizationSettingsOnServerLogEvent;
class ResetAuthorizationOnServerLogEvent; class ResetAuthorizationOnServerLogEvent;
class ResetAuthorizationsOnServerLogEvent;
void start_up() final; void start_up() final;
@ -106,6 +107,8 @@ class AccountManager final : public Actor {
void reset_authorization_on_server(int64 hash, uint64 log_event_id, Promise<Unit> &&promise); void reset_authorization_on_server(int64 hash, uint64 log_event_id, Promise<Unit> &&promise);
void reset_authorizations_on_server(uint64 log_event_id, Promise<Unit> &&promise);
Td *td_; Td *td_;
ActorShared<> parent_; ActorShared<> parent_;

View File

@ -146,6 +146,7 @@ Status init_binlog(Binlog &binlog, string path, BinlogKeyValue<Binlog> &binlog_p
break; break;
case LogEvent::HandlerType::ChangeAuthorizationSettingsOnServer: case LogEvent::HandlerType::ChangeAuthorizationSettingsOnServer:
case LogEvent::HandlerType::ResetAuthorizationOnServer: case LogEvent::HandlerType::ResetAuthorizationOnServer:
case LogEvent::HandlerType::ResetAuthorizationsOnServer:
events.to_account_manager.push_back(event.clone()); events.to_account_manager.push_back(event.clone());
break; break;
case LogEvent::HandlerType::BinlogPmcMagic: case LogEvent::HandlerType::BinlogPmcMagic:

View File

@ -114,6 +114,7 @@ class LogEvent {
EditStory = 0x404, EditStory = 0x404,
ChangeAuthorizationSettingsOnServer = 0x500, ChangeAuthorizationSettingsOnServer = 0x500,
ResetAuthorizationOnServer = 0x501, ResetAuthorizationOnServer = 0x501,
ResetAuthorizationsOnServer = 0x502,
ConfigPmcMagic = 0x1f18, ConfigPmcMagic = 0x1f18,
BinlogPmcMagic = 0x4327 BinlogPmcMagic = 0x4327
}; };