From b1cb40b22fe3be5c015f3a5554e9e480551331fd Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 6 Jul 2023 18:42:44 +0300 Subject: [PATCH] Add scopeNotificationSettings.use_default_mute_stories. --- td/generate/scheme/td_api.tl | 3 ++- td/telegram/NotificationSettingsManager.cpp | 4 ++-- td/telegram/ScopeNotificationSettings.cpp | 21 ++++++++++++++------- td/telegram/ScopeNotificationSettings.h | 5 ++++- td/telegram/ScopeNotificationSettings.hpp | 5 +++++ td/telegram/cli.cpp | 6 +++--- 6 files changed, 30 insertions(+), 14 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index e0acb953d..32958257a 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -1325,12 +1325,13 @@ chatNotificationSettings use_default_mute_for:Bool mute_for:int32 use_default_so //@mute_for Time left before notifications will be unmuted, in seconds //@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 +//@use_default_mute_stories If true, mute_stories is ignored and stories are unmuted only for the first 5 chats from topChatCategoryUsers //@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 stories 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 story_sound_id:int64 show_story_sender:Bool disable_pinned_message_notifications:Bool disable_mention_notifications:Bool = ScopeNotificationSettings; +scopeNotificationSettings mute_for:int32 sound_id:int64 show_preview:Bool use_default_mute_stories: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/NotificationSettingsManager.cpp b/td/telegram/NotificationSettingsManager.cpp index 753776687..24cb54dbf 100644 --- a/td/telegram/NotificationSettingsManager.cpp +++ b/td/telegram/NotificationSettingsManager.cpp @@ -540,8 +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, nullptr, false, false, - false); + chats_notification_settings_.show_preview, chats_notification_settings_.use_default_mute_stories, + 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/ScopeNotificationSettings.cpp b/td/telegram/ScopeNotificationSettings.cpp index a20e996c0..6c14f2ab5 100644 --- a/td/telegram/ScopeNotificationSettings.cpp +++ b/td/telegram/ScopeNotificationSettings.cpp @@ -16,7 +16,6 @@ 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_HIDE_SENDER_MASK; if (sound != nullptr) { flags |= telegram_api::inputPeerNotifySettings::SOUND_MASK; @@ -24,6 +23,9 @@ ScopeNotificationSettings::get_input_peer_notify_settings() const { if (story_sound != nullptr) { flags |= telegram_api::inputPeerNotifySettings::STORIES_SOUND_MASK; } + if (!use_default_mute_stories) { + flags |= telegram_api::inputPeerNotifySettings::STORIES_MUTED_MASK; + } return telegram_api::make_object( flags, show_preview, false, mute_until, get_input_notification_sound(sound), mute_stories, hide_story_sender, get_input_notification_sound(story_sound)); @@ -31,8 +33,9 @@ ScopeNotificationSettings::get_input_peer_notify_settings() const { 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.show_preview << ", " << notification_settings.use_default_mute_stories + << ", " << 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 << "]"; @@ -44,8 +47,9 @@ 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, get_notification_sound_ringtone_id(notification_settings->story_sound), - !notification_settings->hide_story_sender, notification_settings->disable_pinned_message_notifications, + notification_settings->use_default_mute_stories, 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); } @@ -71,8 +75,9 @@ 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_, get_notification_sound(false, notification_settings->story_sound_id_), - !notification_settings->show_story_sender_, notification_settings->disable_pinned_message_notifications_, + notification_settings->use_default_mute_stories_, 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_); } @@ -87,11 +92,13 @@ ScopeNotificationSettings get_scope_notification_settings(tl_object_ptrshow_previews_; + auto use_default_mute_stories = (settings->flags_ & telegram_api::peerNotifySettings::STORIES_MUTED_MASK) == 0; auto mute_stories = settings->stories_muted_; auto hide_story_sender = settings->stories_hide_sender_; return {mute_until, get_notification_sound(settings.get(), false), show_preview, + use_default_mute_stories, mute_stories, get_notification_sound(settings.get(), true), hide_story_sender, diff --git a/td/telegram/ScopeNotificationSettings.h b/td/telegram/ScopeNotificationSettings.h index 39baa77ee..bc510e447 100644 --- a/td/telegram/ScopeNotificationSettings.h +++ b/td/telegram/ScopeNotificationSettings.h @@ -22,6 +22,7 @@ class ScopeNotificationSettings { unique_ptr sound; unique_ptr story_sound; bool show_preview = true; + bool use_default_mute_stories = true; bool mute_stories = false; bool hide_story_sender = false; bool is_synchronized = false; @@ -33,12 +34,14 @@ class ScopeNotificationSettings { ScopeNotificationSettings() = default; ScopeNotificationSettings(int32 mute_until, unique_ptr &&sound, bool show_preview, - bool mute_stories, unique_ptr &&story_sound, bool hide_story_sender, + bool use_default_mute_stories, 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) + , use_default_mute_stories(use_default_mute_stories) , mute_stories(mute_stories) , hide_story_sender(hide_story_sender) , is_synchronized(true) diff --git a/td/telegram/ScopeNotificationSettings.hpp b/td/telegram/ScopeNotificationSettings.hpp index 5149a5f7c..b83fa1649 100644 --- a/td/telegram/ScopeNotificationSettings.hpp +++ b/td/telegram/ScopeNotificationSettings.hpp @@ -20,6 +20,7 @@ void store(const ScopeNotificationSettings ¬ification_settings, StorerT &stor bool has_sound = notification_settings.sound != nullptr; bool has_ringtone_support = true; bool has_story_sound = notification_settings.story_sound != nullptr; + bool use_mute_stories = !notification_settings.use_default_mute_stories; BEGIN_STORE_FLAGS(); STORE_FLAG(is_muted); STORE_FLAG(has_sound); @@ -32,6 +33,7 @@ void store(const ScopeNotificationSettings ¬ification_settings, StorerT &stor STORE_FLAG(notification_settings.mute_stories); STORE_FLAG(has_story_sound); STORE_FLAG(notification_settings.hide_story_sender); + STORE_FLAG(use_mute_stories); END_STORE_FLAGS(); if (is_muted) { store(notification_settings.mute_until, storer); @@ -51,6 +53,7 @@ void parse(ScopeNotificationSettings ¬ification_settings, ParserT &parser) { bool silent_send_message_ignored; bool has_ringtone_support; bool has_story_sound; + bool use_mute_stories; BEGIN_PARSE_FLAGS(); PARSE_FLAG(is_muted); PARSE_FLAG(has_sound); @@ -63,6 +66,7 @@ void parse(ScopeNotificationSettings ¬ification_settings, ParserT &parser) { PARSE_FLAG(notification_settings.mute_stories); PARSE_FLAG(has_story_sound); PARSE_FLAG(notification_settings.hide_story_sender); + PARSE_FLAG(use_mute_stories); END_PARSE_FLAGS(); (void)silent_send_message_ignored; if (is_muted) { @@ -80,6 +84,7 @@ void parse(ScopeNotificationSettings ¬ification_settings, ParserT &parser) { if (has_story_sound) { parse_notification_sound(notification_settings.story_sound, parser); } + notification_settings.use_default_mute_stories = !use_mute_stories; } } // namespace td diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 86c41272a..df672c300 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -5534,9 +5534,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), story_sound_id, - as_bool(hide_story_sender), as_bool(disable_pinned_message_notifications), - as_bool(disable_mention_notifications)))); + to_integer(mute_for), sound_id, as_bool(show_preview), mute_stories.empty(), + 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(),