diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 1ab45a787..1485fb1c6 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -3084,7 +3084,12 @@ class UpdateScopeNotifySettingsQuery : public Td::ResultHandler { }; class ResetNotifySettingsQuery : public Td::ResultHandler { + Promise promise_; + public: + explicit ResetNotifySettingsQuery(Promise &&promise) : promise_(std::move(promise)) { + } + void send() { send_query(G()->net_query_creator().create(create_storer(telegram_api::account_resetNotifySettings()))); } @@ -3099,11 +3104,13 @@ class ResetNotifySettingsQuery : public Td::ResultHandler { if (!result) { return on_error(id, Status::Error(400, "Receive false as result")); } + + promise_.set_value(Unit()); } void on_error(uint64 id, Status status) override { - LOG(WARNING) << "Receive error for reset notification settings: " << status; - status.ignore(); + LOG(ERROR) << "Receive error for reset notification settings: " << status; + promise_.set_error(std::move(status)); } }; @@ -13380,7 +13387,39 @@ void MessagesManager::reset_all_notification_settings() { Dialog *d = dialog.second.get(); update_dialog_notification_settings(d->dialog_id, &d->notification_settings, new_dialog_settings); } - td_->create_handler()->send(); + reset_all_notification_settings_on_server(0); +} + +class MessagesManager::ResetAllNotificationSettingsOnServerLogEvent { + public: + template + void store(StorerT &storer) const { + } + + template + void parse(ParserT &parser) { + } +}; + +void MessagesManager::reset_all_notification_settings_on_server(uint64 logevent_id) { + if (logevent_id == 0) { + ResetAllNotificationSettingsOnServerLogEvent logevent; + auto storer = LogEventStorerImpl(logevent); + logevent_id = BinlogHelper::add(G()->td_db()->get_binlog(), + LogEvent::HandlerType::ResetAllNotificationSettingsOnServer, storer); + } + + Promise<> promise; + if (logevent_id != 0) { + promise = PromiseCreator::lambda([logevent_id](Result result) mutable { + if (!G()->close_flag()) { + BinlogHelper::erase(G()->td_db()->get_binlog(), logevent_id); + } + }); + } + + LOG(INFO) << "Reset all notification settings"; + td_->create_handler(std::move(promise))->send(); } unique_ptr MessagesManager::get_draft_message( @@ -25297,6 +25336,13 @@ void MessagesManager::on_binlog_events(vector &&events) { update_scope_notification_settings_on_server(log_event.scope_, event.id_); break; } + case LogEvent::HandlerType::ResetAllNotificationSettingsOnServer: { + ResetAllNotificationSettingsOnServerLogEvent log_event; + log_event_parse(log_event, event.data_).ensure(); + + reset_all_notification_settings_on_server(event.id_); + break; + } case LogEvent::HandlerType::GetChannelDifference: { GetChannelDifferenceLogEvent log_event; log_event_parse(log_event, event.data_).ensure(); diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index d6ee66ab8..e84700753 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -1841,6 +1841,7 @@ class MessagesManager : public Actor { class SaveDialogDraftMessageOnServerLogEvent; class UpdateDialogNotificationSettingsOnServerLogEvent; class UpdateScopeNotificationSettingsOnServerLogEvent; + class ResetAllNotificationSettingsOnServerLogEvent; class SendBotStartMessageLogEvent; class SendInlineQueryResultMessageLogEvent; class SendMessageLogEvent; @@ -2485,9 +2486,11 @@ class MessagesManager : public Actor { void update_dialog_notification_settings_on_server(DialogId dialog_id, bool from_binlog); + void on_updated_dialog_notification_settings(DialogId dialog_id, uint64 generation); + void update_scope_notification_settings_on_server(NotificationSettingsScope scope, uint64 logevent_id); - void on_updated_dialog_notification_settings(DialogId dialog_id, uint64 generation); + void reset_all_notification_settings_on_server(uint64 logevent_id); int64 get_next_pinned_dialog_order(); diff --git a/td/telegram/TdDb.cpp b/td/telegram/TdDb.cpp index 404f715ce..0f5f393bf 100644 --- a/td/telegram/TdDb.cpp +++ b/td/telegram/TdDb.cpp @@ -84,6 +84,7 @@ Status init_binlog(Binlog &binlog, string path, BinlogKeyValue &binlog_p case LogEvent::HandlerType::SaveDialogDraftMessageOnServer: case LogEvent::HandlerType::UpdateDialogNotificationSettingsOnServer: case LogEvent::HandlerType::UpdateScopeNotificationSettingsOnServer: + case LogEvent::HandlerType::ResetAllNotificationSettingsOnServer: case LogEvent::HandlerType::GetChannelDifference: events.to_messages_manager.push_back(event.clone()); break; diff --git a/td/telegram/logevent/LogEvent.h b/td/telegram/logevent/LogEvent.h index 29438f1a2..ac68896fe 100644 --- a/td/telegram/logevent/LogEvent.h +++ b/td/telegram/logevent/LogEvent.h @@ -85,6 +85,7 @@ class LogEvent { SaveDialogDraftMessageOnServer = 0x10e, UpdateDialogNotificationSettingsOnServer = 0x10f, UpdateScopeNotificationSettingsOnServer = 0x110, + ResetAllNotificationSettingsOnServer = 0x111, GetChannelDifference = 0x140, ConfigPmcMagic = 0x1f18, BinlogPmcMagic = 0x4327