From b36ea8934b482eee9680ccb4d8106cec2ad2e075 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 27 Jun 2023 18:30:05 +0300 Subject: [PATCH] Add more story scope notification settings. --- td/generate/scheme/td_api.tl | 4 ++- td/telegram/DialogNotificationSettings.cpp | 2 +- td/telegram/NotificationSettingsManager.cpp | 3 +- td/telegram/NotificationSound.cpp | 8 ++--- td/telegram/NotificationSound.h | 2 +- td/telegram/ScopeNotificationSettings.cpp | 33 +++++++++++++++------ td/telegram/ScopeNotificationSettings.h | 8 +++-- td/telegram/ScopeNotificationSettings.hpp | 12 ++++++++ td/telegram/cli.cpp | 7 +++-- 9 files changed, 58 insertions(+), 21 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 8fb4cca75..9596343c3 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -1323,9 +1323,11 @@ chatNotificationSettings use_default_mute_for:Bool mute_for:int32 use_default_so //@sound_id Identifier of the notification sound to be played; 0 if sound is disabled //@show_preview True, if message content must be displayed in notifications //@mute_stories True, if story notifications are received without sound +//@story_sound_id Identifier of the notification sound to be played for stories; 0 if sound is disabled +//@show_story_sender True, if the sender of the story must be displayed in notifications //@disable_pinned_message_notifications True, if notifications for incoming pinned messages will be created as for an ordinary unread message //@disable_mention_notifications True, if notifications for messages with mentions will be created as for an ordinary unread message -scopeNotificationSettings mute_for:int32 sound_id:int64 show_preview:Bool mute_stories:Bool disable_pinned_message_notifications:Bool disable_mention_notifications:Bool = ScopeNotificationSettings; +scopeNotificationSettings mute_for:int32 sound_id:int64 show_preview:Bool mute_stories:Bool story_sound_id:int64 show_story_sender:Bool disable_pinned_message_notifications:Bool disable_mention_notifications:Bool = ScopeNotificationSettings; //@description Contains information about a message draft diff --git a/td/telegram/DialogNotificationSettings.cpp b/td/telegram/DialogNotificationSettings.cpp index a34b9d146..508036313 100644 --- a/td/telegram/DialogNotificationSettings.cpp +++ b/td/telegram/DialogNotificationSettings.cpp @@ -132,7 +132,7 @@ DialogNotificationSettings get_dialog_notification_settings(tl_object_ptrsilent_; return {use_default_mute_until, mute_until, - get_notification_sound(settings.get()), + get_notification_sound(settings.get(), false), use_default_show_preview, settings->show_previews_, use_default_mute_stories, diff --git a/td/telegram/NotificationSettingsManager.cpp b/td/telegram/NotificationSettingsManager.cpp index d7de27580..9f1691101 100644 --- a/td/telegram/NotificationSettingsManager.cpp +++ b/td/telegram/NotificationSettingsManager.cpp @@ -540,7 +540,8 @@ void NotificationSettingsManager::init() { if (!channels_notification_settings_.is_synchronized && is_authorized) { channels_notification_settings_ = ScopeNotificationSettings( chats_notification_settings_.mute_until, dup_notification_sound(chats_notification_settings_.sound), - chats_notification_settings_.show_preview, chats_notification_settings_.mute_stories, false, false); + chats_notification_settings_.show_preview, chats_notification_settings_.mute_stories, nullptr, false, false, + false); channels_notification_settings_.is_synchronized = false; send_get_scope_notification_settings_query(NotificationSettingsScope::Channel, Promise<>()); } diff --git a/td/telegram/NotificationSound.cpp b/td/telegram/NotificationSound.cpp index 38cc8f53a..8f6d9d465 100644 --- a/td/telegram/NotificationSound.cpp +++ b/td/telegram/NotificationSound.cpp @@ -251,15 +251,15 @@ static unique_ptr get_notification_sound(telegram_api::Notifi } } -unique_ptr get_notification_sound(telegram_api::peerNotifySettings *settings) { +unique_ptr get_notification_sound(telegram_api::peerNotifySettings *settings, bool for_stories) { CHECK(settings != nullptr); telegram_api::NotificationSound *sound = #if TD_ANDROID - settings->android_sound_.get(); + for_stories ? settings->stories_android_sound_.get() : settings->android_sound_.get(); #elif TD_DARWIN_IOS || TD_DARWIN_TV_OS || TD_DARWIN_WATCH_OS - settings->ios_sound_.get(); + for_stories ? settings->stories_ios_sound_.get() : settings->ios_sound_.get(); #else - settings->other_sound_.get(); + for_stories ? settings->stories_other_sound_.get() : settings->other_sound_.get(); #endif return get_notification_sound(sound); } diff --git a/td/telegram/NotificationSound.h b/td/telegram/NotificationSound.h index accfb141d..64ae20435 100644 --- a/td/telegram/NotificationSound.h +++ b/td/telegram/NotificationSound.h @@ -57,7 +57,7 @@ unique_ptr get_legacy_notification_sound(const string &sound) unique_ptr get_notification_sound(bool use_default_sound, int64 ringtone_id); -unique_ptr get_notification_sound(telegram_api::peerNotifySettings *settings); +unique_ptr get_notification_sound(telegram_api::peerNotifySettings *settings, bool for_stories); telegram_api::object_ptr get_input_notification_sound( const unique_ptr ¬ification_sound); diff --git a/td/telegram/ScopeNotificationSettings.cpp b/td/telegram/ScopeNotificationSettings.cpp index 5ef16f39b..a20e996c0 100644 --- a/td/telegram/ScopeNotificationSettings.cpp +++ b/td/telegram/ScopeNotificationSettings.cpp @@ -16,17 +16,23 @@ telegram_api::object_ptr ScopeNotificationSettings::get_input_peer_notify_settings() const { int32 flags = telegram_api::inputPeerNotifySettings::MUTE_UNTIL_MASK | telegram_api::inputPeerNotifySettings::SHOW_PREVIEWS_MASK | - telegram_api::inputPeerNotifySettings::STORIES_MUTED_MASK; + telegram_api::inputPeerNotifySettings::STORIES_MUTED_MASK | + telegram_api::inputPeerNotifySettings::STORIES_HIDE_SENDER_MASK; if (sound != nullptr) { flags |= telegram_api::inputPeerNotifySettings::SOUND_MASK; } + if (story_sound != nullptr) { + flags |= telegram_api::inputPeerNotifySettings::STORIES_SOUND_MASK; + } return telegram_api::make_object( - flags, show_preview, false, mute_until, get_input_notification_sound(sound), mute_stories, false, nullptr); + flags, show_preview, false, mute_until, get_input_notification_sound(sound), mute_stories, hide_story_sender, + get_input_notification_sound(story_sound)); } StringBuilder &operator<<(StringBuilder &string_builder, const ScopeNotificationSettings ¬ification_settings) { return string_builder << "[" << notification_settings.mute_until << ", " << notification_settings.sound << ", " << notification_settings.show_preview << ", " << notification_settings.mute_stories << ", " + << notification_settings.story_sound << ", " << notification_settings.hide_story_sender << ", " << notification_settings.is_synchronized << ", " << notification_settings.disable_pinned_message_notifications << ", " << notification_settings.disable_mention_notifications << "]"; @@ -38,7 +44,8 @@ td_api::object_ptr get_scope_notification_set return td_api::make_object( max(0, notification_settings->mute_until - G()->unix_time()), get_notification_sound_ringtone_id(notification_settings->sound), notification_settings->show_preview, - notification_settings->mute_stories, notification_settings->disable_pinned_message_notifications, + notification_settings->mute_stories, get_notification_sound_ringtone_id(notification_settings->story_sound), + !notification_settings->hide_story_sender, notification_settings->disable_pinned_message_notifications, notification_settings->disable_mention_notifications); } @@ -62,10 +69,11 @@ Result get_scope_notification_settings( } auto mute_until = get_mute_until(notification_settings->mute_for_); - return ScopeNotificationSettings(mute_until, get_notification_sound(false, notification_settings->sound_id_), - notification_settings->show_preview_, notification_settings->mute_stories_, - notification_settings->disable_pinned_message_notifications_, - notification_settings->disable_mention_notifications_); + return ScopeNotificationSettings( + mute_until, get_notification_sound(false, notification_settings->sound_id_), notification_settings->show_preview_, + notification_settings->mute_stories_, get_notification_sound(false, notification_settings->story_sound_id_), + !notification_settings->show_story_sender_, notification_settings->disable_pinned_message_notifications_, + notification_settings->disable_mention_notifications_); } ScopeNotificationSettings get_scope_notification_settings(tl_object_ptr &&settings, @@ -80,8 +88,15 @@ ScopeNotificationSettings get_scope_notification_settings(tl_object_ptrshow_previews_; auto mute_stories = settings->stories_muted_; - return {mute_until, get_notification_sound(settings.get()), show_preview, - mute_stories, old_disable_pinned_message_notifications, old_disable_mention_notifications}; + auto hide_story_sender = settings->stories_hide_sender_; + return {mute_until, + get_notification_sound(settings.get(), false), + show_preview, + mute_stories, + get_notification_sound(settings.get(), true), + hide_story_sender, + old_disable_pinned_message_notifications, + old_disable_mention_notifications}; } } // namespace td diff --git a/td/telegram/ScopeNotificationSettings.h b/td/telegram/ScopeNotificationSettings.h index cd6de7d86..39baa77ee 100644 --- a/td/telegram/ScopeNotificationSettings.h +++ b/td/telegram/ScopeNotificationSettings.h @@ -20,8 +20,10 @@ class ScopeNotificationSettings { public: int32 mute_until = 0; unique_ptr sound; + unique_ptr story_sound; bool show_preview = true; bool mute_stories = false; + bool hide_story_sender = false; bool is_synchronized = false; // local settings @@ -31,12 +33,14 @@ class ScopeNotificationSettings { ScopeNotificationSettings() = default; ScopeNotificationSettings(int32 mute_until, unique_ptr &&sound, bool show_preview, - bool mute_stories, bool disable_pinned_message_notifications, - bool disable_mention_notifications) + bool mute_stories, unique_ptr &&story_sound, bool hide_story_sender, + bool disable_pinned_message_notifications, bool disable_mention_notifications) : mute_until(mute_until) , sound(std::move(sound)) + , story_sound(std::move(story_sound)) , show_preview(show_preview) , mute_stories(mute_stories) + , hide_story_sender(hide_story_sender) , is_synchronized(true) , disable_pinned_message_notifications(disable_pinned_message_notifications) , disable_mention_notifications(disable_mention_notifications) { diff --git a/td/telegram/ScopeNotificationSettings.hpp b/td/telegram/ScopeNotificationSettings.hpp index af24597a8..5149a5f7c 100644 --- a/td/telegram/ScopeNotificationSettings.hpp +++ b/td/telegram/ScopeNotificationSettings.hpp @@ -19,6 +19,7 @@ void store(const ScopeNotificationSettings ¬ification_settings, StorerT &stor bool is_muted = notification_settings.mute_until != 0 && notification_settings.mute_until > G()->unix_time(); bool has_sound = notification_settings.sound != nullptr; bool has_ringtone_support = true; + bool has_story_sound = notification_settings.story_sound != nullptr; BEGIN_STORE_FLAGS(); STORE_FLAG(is_muted); STORE_FLAG(has_sound); @@ -29,6 +30,8 @@ void store(const ScopeNotificationSettings ¬ification_settings, StorerT &stor STORE_FLAG(notification_settings.disable_mention_notifications); STORE_FLAG(has_ringtone_support); STORE_FLAG(notification_settings.mute_stories); + STORE_FLAG(has_story_sound); + STORE_FLAG(notification_settings.hide_story_sender); END_STORE_FLAGS(); if (is_muted) { store(notification_settings.mute_until, storer); @@ -36,6 +39,9 @@ void store(const ScopeNotificationSettings ¬ification_settings, StorerT &stor if (has_sound) { store(notification_settings.sound, storer); } + if (has_story_sound) { + store(notification_settings.story_sound, storer); + } } template @@ -44,6 +50,7 @@ void parse(ScopeNotificationSettings ¬ification_settings, ParserT &parser) { bool has_sound; bool silent_send_message_ignored; bool has_ringtone_support; + bool has_story_sound; BEGIN_PARSE_FLAGS(); PARSE_FLAG(is_muted); PARSE_FLAG(has_sound); @@ -54,6 +61,8 @@ void parse(ScopeNotificationSettings ¬ification_settings, ParserT &parser) { PARSE_FLAG(notification_settings.disable_mention_notifications); PARSE_FLAG(has_ringtone_support); PARSE_FLAG(notification_settings.mute_stories); + PARSE_FLAG(has_story_sound); + PARSE_FLAG(notification_settings.hide_story_sender); END_PARSE_FLAGS(); (void)silent_send_message_ignored; if (is_muted) { @@ -68,6 +77,9 @@ void parse(ScopeNotificationSettings ¬ification_settings, ParserT &parser) { notification_settings.sound = get_legacy_notification_sound(sound); } } + if (has_story_sound) { + parse_notification_sound(notification_settings.story_sound, parser); + } } } // namespace td diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index d21bd11c8..57bfc15a7 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -5516,6 +5516,8 @@ class CliClient final : public Actor { int64 sound_id; string show_preview; string mute_stories; + int64 story_sound_id; + string hide_story_sender; string disable_pinned_message_notifications; string disable_mention_notifications; get_args(args, scope, mute_for, sound_id, show_preview, mute_stories, disable_pinned_message_notifications, @@ -5524,8 +5526,9 @@ class CliClient final : public Actor { send_request(td_api::make_object( as_notification_settings_scope(scope), td_api::make_object( - to_integer(mute_for), sound_id, as_bool(show_preview), as_bool(mute_stories), - as_bool(disable_pinned_message_notifications), as_bool(disable_mention_notifications)))); + to_integer(mute_for), sound_id, as_bool(show_preview), as_bool(mute_stories), story_sound_id, + as_bool(hide_story_sender), as_bool(disable_pinned_message_notifications), + as_bool(disable_mention_notifications)))); } else { auto settings = td_api::make_object( mute_for.empty(), to_integer(mute_for), sound_id == -1, sound_id, show_preview.empty(),