From 58d84a1c7e1b579081ce956311512652e82e241c Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 6 Dec 2022 16:18:11 +0300 Subject: [PATCH] Improve get_dialog_notification_settings(td_api::object_ptr &¬ification_settings). --- td/telegram/DialogNotificationSettings.cpp | 25 ++++++++++++++-------- td/telegram/DialogNotificationSettings.h | 3 ++- td/telegram/ForumTopicManager.cpp | 6 +----- td/telegram/MessagesManager.cpp | 6 +----- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/td/telegram/DialogNotificationSettings.cpp b/td/telegram/DialogNotificationSettings.cpp index 9502df6dd..63bad6abf 100644 --- a/td/telegram/DialogNotificationSettings.cpp +++ b/td/telegram/DialogNotificationSettings.cpp @@ -51,21 +51,28 @@ static int32 get_mute_until(int32 mute_for) { } Result get_dialog_notification_settings( - td_api::object_ptr &¬ification_settings, bool old_silent_send_message) { + td_api::object_ptr &¬ification_settings, + const DialogNotificationSettings *old_settings) { if (notification_settings == nullptr) { return Status::Error(400, "New notification settings must be non-empty"); } + CHECK(old_settings != nullptr); + int32 mute_until = notification_settings->use_default_mute_for_ ? 0 : get_mute_until(notification_settings->mute_for_); - return DialogNotificationSettings( - notification_settings->use_default_mute_for_, mute_until, - get_notification_sound(notification_settings->use_default_sound_, notification_settings->sound_id_), - notification_settings->use_default_show_preview_, notification_settings->show_preview_, old_silent_send_message, - notification_settings->use_default_disable_pinned_message_notifications_, - notification_settings->disable_pinned_message_notifications_, - notification_settings->use_default_disable_mention_notifications_, - notification_settings->disable_mention_notifications_); + auto notification_sound = + get_notification_sound(notification_settings->use_default_sound_, notification_settings->sound_id_); + if (is_notification_sound_default(old_settings->sound) && is_notification_sound_default(notification_sound)) { + notification_sound = dup_notification_sound(old_settings->sound); + } + return DialogNotificationSettings(notification_settings->use_default_mute_for_, mute_until, + std::move(notification_sound), notification_settings->use_default_show_preview_, + notification_settings->show_preview_, old_settings->silent_send_message, + notification_settings->use_default_disable_pinned_message_notifications_, + notification_settings->disable_pinned_message_notifications_, + notification_settings->use_default_disable_mention_notifications_, + notification_settings->disable_mention_notifications_); } DialogNotificationSettings get_dialog_notification_settings(tl_object_ptr &&settings, diff --git a/td/telegram/DialogNotificationSettings.h b/td/telegram/DialogNotificationSettings.h index e566e56e3..1c17c5244 100644 --- a/td/telegram/DialogNotificationSettings.h +++ b/td/telegram/DialogNotificationSettings.h @@ -61,7 +61,8 @@ td_api::object_ptr get_chat_notification_setti const DialogNotificationSettings *notification_settings); Result get_dialog_notification_settings( - td_api::object_ptr &¬ification_settings, bool old_silent_send_message); + td_api::object_ptr &¬ification_settings, + const DialogNotificationSettings *old_settings); DialogNotificationSettings get_dialog_notification_settings(tl_object_ptr &&settings, const DialogNotificationSettings *old_settings); diff --git a/td/telegram/ForumTopicManager.cpp b/td/telegram/ForumTopicManager.cpp index cbae6290a..96b4b9c49 100644 --- a/td/telegram/ForumTopicManager.cpp +++ b/td/telegram/ForumTopicManager.cpp @@ -430,11 +430,7 @@ Status ForumTopicManager::set_forum_topic_notification_settings( return Status::Error(400, "Unknown forum topic identifier specified"); } - TRY_RESULT(new_settings, - get_dialog_notification_settings(std::move(notification_settings), current_settings->silent_send_message)); - if (is_notification_sound_default(current_settings->sound) && is_notification_sound_default(new_settings.sound)) { - new_settings.sound = dup_notification_sound(current_settings->sound); - } + TRY_RESULT(new_settings, get_dialog_notification_settings(std::move(notification_settings), current_settings)); if (update_forum_topic_notification_settings(dialog_id, top_thread_message_id, current_settings, std::move(new_settings))) { // TODO log event diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index f45b4e508..74a03b531 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -22165,11 +22165,7 @@ Status MessagesManager::set_dialog_notification_settings( return Status::Error(400, "Notification settings of the Saved Messages chat can't be changed"); } - TRY_RESULT(new_settings, ::td::get_dialog_notification_settings(std::move(notification_settings), - current_settings->silent_send_message)); - if (is_notification_sound_default(current_settings->sound) && is_notification_sound_default(new_settings.sound)) { - new_settings.sound = dup_notification_sound(current_settings->sound); - } + TRY_RESULT(new_settings, ::td::get_dialog_notification_settings(std::move(notification_settings), current_settings)); if (update_dialog_notification_settings(dialog_id, current_settings, std::move(new_settings))) { update_dialog_notification_settings_on_server(dialog_id, false); }