Add need_update_dialog_notification_settings.

This commit is contained in:
levlam 2022-12-06 16:34:17 +03:00
parent 58d84a1c7e
commit bc2e23a27f
4 changed files with 37 additions and 41 deletions

View File

@ -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

View File

@ -69,4 +69,12 @@ DialogNotificationSettings get_dialog_notification_settings(tl_object_ptr<telegr
bool are_default_dialog_notification_settings(const DialogNotificationSettings &settings, bool compare_sound);
struct NeedUpdateDialogNotificationSettings {
bool need_update_server = false;
bool need_update_local = false;
bool are_changed = false;
};
NeedUpdateDialogNotificationSettings need_update_dialog_notification_settings(
const DialogNotificationSettings *current_settings, const DialogNotificationSettings &new_settings);
} // namespace td

View File

@ -448,25 +448,8 @@ bool ForumTopicManager::update_forum_topic_notification_settings(DialogId dialog
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) {
// 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,

View File

@ -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<td_api::updateChatNotificationSettings>(
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) {