diff --git a/td/telegram/DialogNotificationSettings.cpp b/td/telegram/DialogNotificationSettings.cpp index 63bad6abf..315376af9 100644 --- a/td/telegram/DialogNotificationSettings.cpp +++ b/td/telegram/DialogNotificationSettings.cpp @@ -120,4 +120,26 @@ bool are_default_dialog_notification_settings(const DialogNotificationSettings & settings.use_default_disable_mention_notifications; } +NeedUpdateDialogNotificationSettings need_update_dialog_notification_settings( + const DialogNotificationSettings *current_settings, const DialogNotificationSettings &new_settings) { + NeedUpdateDialogNotificationSettings result; + result.need_update_server = current_settings->mute_until != new_settings.mute_until || + !are_equivalent_notification_sounds(current_settings->sound, new_settings.sound) || + current_settings->show_preview != new_settings.show_preview || + current_settings->use_default_mute_until != new_settings.use_default_mute_until || + current_settings->use_default_show_preview != new_settings.use_default_show_preview; + result.need_update_local = + current_settings->use_default_disable_pinned_message_notifications != + new_settings.use_default_disable_pinned_message_notifications || + current_settings->disable_pinned_message_notifications != new_settings.disable_pinned_message_notifications || + current_settings->use_default_disable_mention_notifications != + new_settings.use_default_disable_mention_notifications || + current_settings->disable_mention_notifications != new_settings.disable_mention_notifications; + result.are_changed = result.need_update_server || result.need_update_local || + current_settings->is_synchronized != new_settings.is_synchronized || + current_settings->is_use_default_fixed != new_settings.is_use_default_fixed || + are_different_equivalent_notification_sounds(current_settings->sound, new_settings.sound); + return result; +} + } // namespace td diff --git a/td/telegram/DialogNotificationSettings.h b/td/telegram/DialogNotificationSettings.h index 1c17c5244..03e8c61b4 100644 --- a/td/telegram/DialogNotificationSettings.h +++ b/td/telegram/DialogNotificationSettings.h @@ -69,4 +69,12 @@ DialogNotificationSettings get_dialog_notification_settings(tl_object_ptrmute_until != new_settings.mute_until || - !are_equivalent_notification_sounds(current_settings->sound, new_settings.sound) || - current_settings->show_preview != new_settings.show_preview || - current_settings->use_default_mute_until != new_settings.use_default_mute_until || - current_settings->use_default_show_preview != new_settings.use_default_show_preview; - bool need_update_local = - current_settings->use_default_disable_pinned_message_notifications != - new_settings.use_default_disable_pinned_message_notifications || - current_settings->disable_pinned_message_notifications != new_settings.disable_pinned_message_notifications || - current_settings->use_default_disable_mention_notifications != - new_settings.use_default_disable_mention_notifications || - current_settings->disable_mention_notifications != new_settings.disable_mention_notifications; - - bool is_changed = need_update_server || need_update_local || - current_settings->is_synchronized != new_settings.is_synchronized || - current_settings->is_use_default_fixed != new_settings.is_use_default_fixed || - are_different_equivalent_notification_sounds(current_settings->sound, new_settings.sound); - - if (is_changed) { + auto need_update = need_update_dialog_notification_settings(current_settings, new_settings); + if (need_update.are_changed) { // TODO update unmute timeouts, td_api updates, remove notifications *current_settings = std::move(new_settings); @@ -475,7 +458,7 @@ bool ForumTopicManager::update_forum_topic_notification_settings(DialogId dialog topic->need_save_to_database_ = true; save_topic_to_database(dialog_id, topic); } - return need_update_server; + return need_update.need_update_server; } void ForumTopicManager::get_forum_topic(DialogId dialog_id, MessageId top_thread_message_id, diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 74a03b531..7d8f36ebc 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -8213,25 +8213,8 @@ bool MessagesManager::update_dialog_notification_settings(DialogId dialog_id, return false; } - bool need_update_server = current_settings->mute_until != new_settings.mute_until || - !are_equivalent_notification_sounds(current_settings->sound, new_settings.sound) || - current_settings->show_preview != new_settings.show_preview || - current_settings->use_default_mute_until != new_settings.use_default_mute_until || - current_settings->use_default_show_preview != new_settings.use_default_show_preview; - bool need_update_local = - current_settings->use_default_disable_pinned_message_notifications != - new_settings.use_default_disable_pinned_message_notifications || - current_settings->disable_pinned_message_notifications != new_settings.disable_pinned_message_notifications || - current_settings->use_default_disable_mention_notifications != - new_settings.use_default_disable_mention_notifications || - current_settings->disable_mention_notifications != new_settings.disable_mention_notifications; - - bool is_changed = need_update_server || need_update_local || - current_settings->is_synchronized != new_settings.is_synchronized || - current_settings->is_use_default_fixed != new_settings.is_use_default_fixed || - are_different_equivalent_notification_sounds(current_settings->sound, new_settings.sound); - - if (is_changed) { + auto need_update = need_update_dialog_notification_settings(current_settings, new_settings); + if (need_update.are_changed) { Dialog *d = get_dialog(dialog_id); LOG_CHECK(d != nullptr) << "Wrong " << dialog_id << " in update_dialog_notification_settings"; bool was_dialog_mentions_disabled = is_dialog_mention_notifications_disabled(d); @@ -8261,13 +8244,13 @@ bool MessagesManager::update_dialog_notification_settings(DialogId dialog_id, } } - if (need_update_server || need_update_local) { + if (need_update.need_update_server || need_update.need_update_local) { send_closure(G()->td(), &Td::send_update, make_tl_object( dialog_id.get(), get_chat_notification_settings_object(current_settings))); } } - return need_update_server; + return need_update.need_update_server; } void MessagesManager::schedule_dialog_unmute(DialogId dialog_id, bool use_default, int32 mute_until) {