Improve get_dialog_notification_settings(td_api::object_ptr<td_api::chatNotificationSettings> &¬ification_settings).
This commit is contained in:
parent
3c842f1ecb
commit
58d84a1c7e
@ -51,17 +51,24 @@ static int32 get_mute_until(int32 mute_for) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Result<DialogNotificationSettings> get_dialog_notification_settings(
|
Result<DialogNotificationSettings> get_dialog_notification_settings(
|
||||||
td_api::object_ptr<td_api::chatNotificationSettings> &¬ification_settings, bool old_silent_send_message) {
|
td_api::object_ptr<td_api::chatNotificationSettings> &¬ification_settings,
|
||||||
|
const DialogNotificationSettings *old_settings) {
|
||||||
if (notification_settings == nullptr) {
|
if (notification_settings == nullptr) {
|
||||||
return Status::Error(400, "New notification settings must be non-empty");
|
return Status::Error(400, "New notification settings must be non-empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CHECK(old_settings != nullptr);
|
||||||
|
|
||||||
int32 mute_until =
|
int32 mute_until =
|
||||||
notification_settings->use_default_mute_for_ ? 0 : get_mute_until(notification_settings->mute_for_);
|
notification_settings->use_default_mute_for_ ? 0 : get_mute_until(notification_settings->mute_for_);
|
||||||
return DialogNotificationSettings(
|
auto notification_sound =
|
||||||
notification_settings->use_default_mute_for_, mute_until,
|
get_notification_sound(notification_settings->use_default_sound_, notification_settings->sound_id_);
|
||||||
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_settings->use_default_show_preview_, notification_settings->show_preview_, old_silent_send_message,
|
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->use_default_disable_pinned_message_notifications_,
|
||||||
notification_settings->disable_pinned_message_notifications_,
|
notification_settings->disable_pinned_message_notifications_,
|
||||||
notification_settings->use_default_disable_mention_notifications_,
|
notification_settings->use_default_disable_mention_notifications_,
|
||||||
|
@ -61,7 +61,8 @@ td_api::object_ptr<td_api::chatNotificationSettings> get_chat_notification_setti
|
|||||||
const DialogNotificationSettings *notification_settings);
|
const DialogNotificationSettings *notification_settings);
|
||||||
|
|
||||||
Result<DialogNotificationSettings> get_dialog_notification_settings(
|
Result<DialogNotificationSettings> get_dialog_notification_settings(
|
||||||
td_api::object_ptr<td_api::chatNotificationSettings> &¬ification_settings, bool old_silent_send_message);
|
td_api::object_ptr<td_api::chatNotificationSettings> &¬ification_settings,
|
||||||
|
const DialogNotificationSettings *old_settings);
|
||||||
|
|
||||||
DialogNotificationSettings get_dialog_notification_settings(tl_object_ptr<telegram_api::peerNotifySettings> &&settings,
|
DialogNotificationSettings get_dialog_notification_settings(tl_object_ptr<telegram_api::peerNotifySettings> &&settings,
|
||||||
const DialogNotificationSettings *old_settings);
|
const DialogNotificationSettings *old_settings);
|
||||||
|
@ -430,11 +430,7 @@ Status ForumTopicManager::set_forum_topic_notification_settings(
|
|||||||
return Status::Error(400, "Unknown forum topic identifier specified");
|
return Status::Error(400, "Unknown forum topic identifier specified");
|
||||||
}
|
}
|
||||||
|
|
||||||
TRY_RESULT(new_settings,
|
TRY_RESULT(new_settings, get_dialog_notification_settings(std::move(notification_settings), current_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);
|
|
||||||
}
|
|
||||||
if (update_forum_topic_notification_settings(dialog_id, top_thread_message_id, current_settings,
|
if (update_forum_topic_notification_settings(dialog_id, top_thread_message_id, current_settings,
|
||||||
std::move(new_settings))) {
|
std::move(new_settings))) {
|
||||||
// TODO log event
|
// TODO log event
|
||||||
|
@ -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");
|
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),
|
TRY_RESULT(new_settings, ::td::get_dialog_notification_settings(std::move(notification_settings), current_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);
|
|
||||||
}
|
|
||||||
if (update_dialog_notification_settings(dialog_id, current_settings, std::move(new_settings))) {
|
if (update_dialog_notification_settings(dialog_id, current_settings, std::move(new_settings))) {
|
||||||
update_dialog_notification_settings_on_server(dialog_id, false);
|
update_dialog_notification_settings_on_server(dialog_id, false);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user