From 9a8262f146a67f4460ad48935b18f278a36ed91b Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 12 Jun 2023 16:29:35 +0300 Subject: [PATCH] Add DialogNotificationSettings::get_input_peer_notify_settings. --- td/telegram/DialogNotificationSettings.cpp | 19 +++++++++++++++++++ td/telegram/DialogNotificationSettings.h | 2 ++ td/telegram/NotificationSettingsManager.cpp | 18 +----------------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/td/telegram/DialogNotificationSettings.cpp b/td/telegram/DialogNotificationSettings.cpp index 8b57716f0..6acd3d053 100644 --- a/td/telegram/DialogNotificationSettings.cpp +++ b/td/telegram/DialogNotificationSettings.cpp @@ -12,6 +12,25 @@ namespace td { +telegram_api::object_ptr +DialogNotificationSettings::get_input_peer_notify_settings() const { + int32 flags = 0; + if (!use_default_mute_until) { + flags |= telegram_api::inputPeerNotifySettings::MUTE_UNTIL_MASK; + } + if (sound != nullptr) { + flags |= telegram_api::inputPeerNotifySettings::SOUND_MASK; + } + if (!use_default_show_preview) { + flags |= telegram_api::inputPeerNotifySettings::SHOW_PREVIEWS_MASK; + } + if (silent_send_message) { + flags |= telegram_api::inputPeerNotifySettings::SILENT_MASK; + } + return telegram_api::make_object( + flags, show_preview, silent_send_message, mute_until, get_input_notification_sound(sound), false, false, nullptr); +} + StringBuilder &operator<<(StringBuilder &string_builder, const DialogNotificationSettings ¬ification_settings) { return string_builder << "[" << notification_settings.mute_until << ", " << notification_settings.sound << ", " << notification_settings.show_preview << ", " << notification_settings.silent_send_message diff --git a/td/telegram/DialogNotificationSettings.h b/td/telegram/DialogNotificationSettings.h index 33c041c8f..d949c9d44 100644 --- a/td/telegram/DialogNotificationSettings.h +++ b/td/telegram/DialogNotificationSettings.h @@ -53,6 +53,8 @@ class DialogNotificationSettings { , use_default_disable_mention_notifications(use_default_disable_mention_notifications) , disable_mention_notifications(disable_mention_notifications) { } + + telegram_api::object_ptr get_input_peer_notify_settings() const; }; StringBuilder &operator<<(StringBuilder &string_builder, const DialogNotificationSettings ¬ification_settings); diff --git a/td/telegram/NotificationSettingsManager.cpp b/td/telegram/NotificationSettingsManager.cpp index e15490635..b9696151b 100644 --- a/td/telegram/NotificationSettingsManager.cpp +++ b/td/telegram/NotificationSettingsManager.cpp @@ -334,24 +334,8 @@ class UpdateDialogNotifySettingsQuery final : public Td::ResultHandler { return on_error(Status::Error(500, "Can't update chat notification settings")); } - int32 flags = 0; - if (!new_settings.use_default_mute_until) { - flags |= telegram_api::inputPeerNotifySettings::MUTE_UNTIL_MASK; - } - if (new_settings.sound != nullptr) { - flags |= telegram_api::inputPeerNotifySettings::SOUND_MASK; - } - if (!new_settings.use_default_show_preview) { - flags |= telegram_api::inputPeerNotifySettings::SHOW_PREVIEWS_MASK; - } - if (new_settings.silent_send_message) { - flags |= telegram_api::inputPeerNotifySettings::SILENT_MASK; - } send_query(G()->net_query_creator().create(telegram_api::account_updateNotifySettings( - std::move(input_notify_peer), - make_tl_object( - flags, new_settings.show_preview, new_settings.silent_send_message, new_settings.mute_until, - get_input_notification_sound(new_settings.sound), false, false, nullptr)))); + std::move(input_notify_peer), new_settings.get_input_peer_notify_settings()))); } void on_result(BufferSlice packet) final {