Add SetDefaultHistoryTtlOnServerLogEvent.

This commit is contained in:
levlam 2023-09-22 15:03:02 +03:00
parent b222f48d05
commit 6600f9279e
4 changed files with 42 additions and 1 deletions

View File

@ -778,10 +778,39 @@ void AccountManager::tear_down() {
parent_.reset();
}
void AccountManager::set_default_message_ttl(int32 message_ttl, Promise<Unit> &&promise) {
class AccountManager::SetDefaultHistoryTtlOnServerLogEvent {
public:
int32 message_ttl_;
template <class StorerT>
void store(StorerT &storer) const {
td::store(message_ttl_, storer);
}
template <class ParserT>
void parse(ParserT &parser) {
td::parse(message_ttl_, parser);
}
};
void AccountManager::set_default_history_ttl_on_server(int32 message_ttl, uint64 log_event_id,
Promise<Unit> &&promise) {
if (log_event_id == 0) {
SetDefaultHistoryTtlOnServerLogEvent log_event{message_ttl};
log_event_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SetDefaultHistoryTtlOnServer,
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<SetDefaultHistoryTtlQuery>(std::move(promise))->send(message_ttl);
}
void AccountManager::set_default_message_ttl(int32 message_ttl, Promise<Unit> &&promise) {
set_default_history_ttl_on_server(message_ttl, 0, std::move(promise));
}
void AccountManager::get_default_message_ttl(Promise<int32> &&promise) {
td_->create_handler<GetDefaultHistoryTtlQuery>(std::move(promise))->send();
}
@ -1119,6 +1148,13 @@ void AccountManager::on_binlog_events(vector<BinlogEvent> &&events) {
reset_authorizations_on_server(event.id_, Auto());
break;
}
case LogEvent::HandlerType::SetDefaultHistoryTtlOnServer: {
SetDefaultHistoryTtlOnServerLogEvent log_event;
log_event_parse(log_event, event.get_data()).ensure();
set_default_history_ttl_on_server(log_event.message_ttl_, event.id_, Auto());
break;
}
default:
LOG(FATAL) << "Unsupported log event type " << event.type_;
}

View File

@ -81,6 +81,7 @@ class AccountManager final : public Actor {
class ChangeAuthorizationSettingsOnServerLogEvent;
class ResetAuthorizationOnServerLogEvent;
class ResetAuthorizationsOnServerLogEvent;
class SetDefaultHistoryTtlOnServerLogEvent;
void start_up() final;
@ -109,6 +110,8 @@ class AccountManager final : public Actor {
void reset_authorizations_on_server(uint64 log_event_id, Promise<Unit> &&promise);
void set_default_history_ttl_on_server(int32 message_ttl, uint64 log_event_id, Promise<Unit> &&promise);
Td *td_;
ActorShared<> parent_;

View File

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

View File

@ -115,6 +115,7 @@ class LogEvent {
ChangeAuthorizationSettingsOnServer = 0x500,
ResetAuthorizationOnServer = 0x501,
ResetAuthorizationsOnServer = 0x502,
SetDefaultHistoryTtlOnServer = 0x503,
ConfigPmcMagic = 0x1f18,
BinlogPmcMagic = 0x4327
};