From fb859209c16fd7e86bd1d02e6783983fde546739 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 22 Sep 2023 15:06:53 +0300 Subject: [PATCH] Add SetAccountTtlOnServerLogEvent. --- td/telegram/AccountManager.cpp | 37 ++++++++++++++++++++++++++++++++- td/telegram/AccountManager.h | 3 +++ td/telegram/TdDb.cpp | 1 + td/telegram/logevent/LogEvent.h | 1 + 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/td/telegram/AccountManager.cpp b/td/telegram/AccountManager.cpp index 741b5d453ab3..84747eeb26c4 100644 --- a/td/telegram/AccountManager.cpp +++ b/td/telegram/AccountManager.cpp @@ -815,10 +815,38 @@ void AccountManager::get_default_message_ttl(Promise &&promise) { td_->create_handler(std::move(promise))->send(); } -void AccountManager::set_account_ttl(int32 account_ttl, Promise &&promise) { +class AccountManager::SetAccountTtlOnServerLogEvent { + public: + int32 account_ttl_; + + template + void store(StorerT &storer) const { + td::store(account_ttl_, storer); + } + + template + void parse(ParserT &parser) { + td::parse(account_ttl_, parser); + } +}; + +void AccountManager::set_account_ttl_on_server(int32 account_ttl, uint64 log_event_id, Promise &&promise) { + if (log_event_id == 0) { + SetAccountTtlOnServerLogEvent log_event{account_ttl}; + log_event_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SetAccountTtlOnServer, + 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(account_ttl); } +void AccountManager::set_account_ttl(int32 account_ttl, Promise &&promise) { + set_account_ttl_on_server(account_ttl, 0, std::move(promise)); +} + void AccountManager::get_account_ttl(Promise &&promise) { td_->create_handler(std::move(promise))->send(); } @@ -1148,6 +1176,13 @@ void AccountManager::on_binlog_events(vector &&events) { reset_authorizations_on_server(event.id_, Auto()); break; } + case LogEvent::HandlerType::SetAccountTtlOnServer: { + SetAccountTtlOnServerLogEvent log_event; + log_event_parse(log_event, event.get_data()).ensure(); + + set_account_ttl_on_server(log_event.account_ttl_, event.id_, Auto()); + break; + } case LogEvent::HandlerType::SetDefaultHistoryTtlOnServer: { SetDefaultHistoryTtlOnServerLogEvent log_event; log_event_parse(log_event, event.get_data()).ensure(); diff --git a/td/telegram/AccountManager.h b/td/telegram/AccountManager.h index 466b247d767e..44883727bfaa 100644 --- a/td/telegram/AccountManager.h +++ b/td/telegram/AccountManager.h @@ -81,6 +81,7 @@ class AccountManager final : public Actor { class ChangeAuthorizationSettingsOnServerLogEvent; class ResetAuthorizationOnServerLogEvent; class ResetAuthorizationsOnServerLogEvent; + class SetAccountTtlOnServerLogEvent; class SetDefaultHistoryTtlOnServerLogEvent; void start_up() final; @@ -110,6 +111,8 @@ class AccountManager final : public Actor { void reset_authorizations_on_server(uint64 log_event_id, Promise &&promise); + void set_account_ttl_on_server(int32 account_ttl, uint64 log_event_id, Promise &&promise); + void set_default_history_ttl_on_server(int32 message_ttl, uint64 log_event_id, Promise &&promise); Td *td_; diff --git a/td/telegram/TdDb.cpp b/td/telegram/TdDb.cpp index 0bc6892cbae1..883cc6293898 100644 --- a/td/telegram/TdDb.cpp +++ b/td/telegram/TdDb.cpp @@ -148,6 +148,7 @@ Status init_binlog(Binlog &binlog, string path, BinlogKeyValue &binlog_p case LogEvent::HandlerType::ResetAuthorizationOnServer: case LogEvent::HandlerType::ResetAuthorizationsOnServer: case LogEvent::HandlerType::SetDefaultHistoryTtlOnServer: + case LogEvent::HandlerType::SetAccountTtlOnServer: 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 e47e1eb216b8..5761cd59b253 100644 --- a/td/telegram/logevent/LogEvent.h +++ b/td/telegram/logevent/LogEvent.h @@ -116,6 +116,7 @@ class LogEvent { ResetAuthorizationOnServer = 0x501, ResetAuthorizationsOnServer = 0x502, SetDefaultHistoryTtlOnServer = 0x503, + SetAccountTtlOnServer = 0x504, ConfigPmcMagic = 0x1f18, BinlogPmcMagic = 0x4327 };