Add InvalidateSignInCodesOnServerLogEvent.

This commit is contained in:
levlam 2023-09-22 16:16:14 +03:00
parent df3d50b056
commit 7eef4ec47a
4 changed files with 49 additions and 4 deletions

View File

@ -602,7 +602,12 @@ class ImportContactTokenQuery final : public Td::ResultHandler {
};
class InvalidateSignInCodesQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
public:
explicit InvalidateSignInCodesQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(vector<string> &&codes) {
send_query(G()->net_query_creator().create(telegram_api::account_invalidateSignInCodes(std::move(codes))));
}
@ -614,10 +619,12 @@ class InvalidateSignInCodesQuery final : public Td::ResultHandler {
}
LOG(DEBUG) << "Receive result for InvalidateSignInCodesQuery: " << result_ptr.ok();
promise_.set_value(Unit());
}
void on_error(Status status) final {
LOG(DEBUG) << "Receive error for InvalidateSignInCodesQuery: " << status;
promise_.set_error(std::move(status));
}
};
@ -1134,8 +1141,34 @@ void AccountManager::import_contact_token(const string &token, Promise<td_api::o
td_->create_handler<ImportContactTokenQuery>(std::move(promise))->send(token);
}
class AccountManager::InvalidateSignInCodesOnServerLogEvent {
public:
vector<string> authentication_codes_;
template <class StorerT>
void store(StorerT &storer) const {
td::store(authentication_codes_, storer);
}
template <class ParserT>
void parse(ParserT &parser) {
td::parse(authentication_codes_, parser);
}
};
void AccountManager::invalidate_sign_in_codes_on_server(vector<string> authentication_codes, uint64 log_event_id) {
if (log_event_id == 0) {
InvalidateSignInCodesOnServerLogEvent log_event{authentication_codes};
log_event_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::InvalidateSignInCodesOnServer,
get_log_event_storer(log_event));
}
td_->create_handler<InvalidateSignInCodesQuery>(get_erase_log_event_promise(log_event_id))
->send(std::move(authentication_codes));
}
void AccountManager::invalidate_authentication_codes(vector<string> &&authentication_codes) {
td_->create_handler<InvalidateSignInCodesQuery>()->send(std::move(authentication_codes));
invalidate_sign_in_codes_on_server(std::move(authentication_codes), 0);
}
void AccountManager::on_new_unconfirmed_authorization(int64 hash, int32 date, string &&device, string &&location) {
@ -1243,6 +1276,13 @@ void AccountManager::on_binlog_events(vector<BinlogEvent> &&events) {
Auto());
break;
}
case LogEvent::HandlerType::InvalidateSignInCodesOnServer: {
InvalidateSignInCodesOnServerLogEvent log_event;
log_event_parse(log_event, event.get_data()).ensure();
invalidate_sign_in_codes_on_server(std::move(log_event.authentication_codes_), event.id_);
break;
}
case LogEvent::HandlerType::ResetAuthorizationOnServer: {
ResetAuthorizationOnServerLogEvent log_event;
log_event_parse(log_event, event.get_data()).ensure();

View File

@ -79,6 +79,7 @@ class AccountManager final : public Actor {
class UnconfirmedAuthorizations;
class ChangeAuthorizationSettingsOnServerLogEvent;
class InvalidateSignInCodesOnServerLogEvent;
class ResetAuthorizationOnServerLogEvent;
class ResetAuthorizationsOnServerLogEvent;
class ResetWebAuthorizationOnServerLogEvent;
@ -110,6 +111,8 @@ class AccountManager final : public Actor {
bool call_requests_disabled, bool confirm, uint64 log_event_id,
Promise<Unit> &&promise);
void invalidate_sign_in_codes_on_server(vector<string> authentication_codes, uint64 log_event_id);
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);

View File

@ -145,13 +145,14 @@ Status init_binlog(Binlog &binlog, string path, BinlogKeyValue<Binlog> &binlog_p
events.save_app_log_events.push_back(event.clone());
break;
case LogEvent::HandlerType::ChangeAuthorizationSettingsOnServer:
case LogEvent::HandlerType::InvalidateSignInCodesOnServer:
case LogEvent::HandlerType::ResetAuthorizationOnServer:
case LogEvent::HandlerType::ResetAuthorizationsOnServer:
case LogEvent::HandlerType::SetDefaultHistoryTtlOnServer:
case LogEvent::HandlerType::SetAccountTtlOnServer:
case LogEvent::HandlerType::SetAuthorizationTtlOnServer:
case LogEvent::HandlerType::ResetWebAuthorizationOnServer:
case LogEvent::HandlerType::ResetWebAuthorizationsOnServer:
case LogEvent::HandlerType::SetAccountTtlOnServer:
case LogEvent::HandlerType::SetAuthorizationTtlOnServer:
case LogEvent::HandlerType::SetDefaultHistoryTtlOnServer:
events.to_account_manager.push_back(event.clone());
break;
case LogEvent::HandlerType::BinlogPmcMagic:

View File

@ -120,6 +120,7 @@ class LogEvent {
SetAuthorizationTtlOnServer = 0x505,
ResetWebAuthorizationOnServer = 0x506,
ResetWebAuthorizationsOnServer = 0x507,
InvalidateSignInCodesOnServer = 0x508,
ConfigPmcMagic = 0x1f18,
BinlogPmcMagic = 0x4327
};