Add more story scope notification settings.

This commit is contained in:
levlam 2023-06-27 18:30:05 +03:00
parent 108b0fc9f8
commit b36ea8934b
9 changed files with 58 additions and 21 deletions

View File

@ -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 //@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 //@show_preview True, if message content must be displayed in notifications
//@mute_stories True, if story notifications are received without sound //@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_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 //@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 //@description Contains information about a message draft

View File

@ -132,7 +132,7 @@ DialogNotificationSettings get_dialog_notification_settings(tl_object_ptr<telegr
bool silent_send_message = settings->silent_; bool silent_send_message = settings->silent_;
return {use_default_mute_until, return {use_default_mute_until,
mute_until, mute_until,
get_notification_sound(settings.get()), get_notification_sound(settings.get(), false),
use_default_show_preview, use_default_show_preview,
settings->show_previews_, settings->show_previews_,
use_default_mute_stories, use_default_mute_stories,

View File

@ -540,7 +540,8 @@ void NotificationSettingsManager::init() {
if (!channels_notification_settings_.is_synchronized && is_authorized) { if (!channels_notification_settings_.is_synchronized && is_authorized) {
channels_notification_settings_ = ScopeNotificationSettings( channels_notification_settings_ = ScopeNotificationSettings(
chats_notification_settings_.mute_until, dup_notification_sound(chats_notification_settings_.sound), 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; channels_notification_settings_.is_synchronized = false;
send_get_scope_notification_settings_query(NotificationSettingsScope::Channel, Promise<>()); send_get_scope_notification_settings_query(NotificationSettingsScope::Channel, Promise<>());
} }

View File

@ -251,15 +251,15 @@ static unique_ptr<NotificationSound> get_notification_sound(telegram_api::Notifi
} }
} }
unique_ptr<NotificationSound> get_notification_sound(telegram_api::peerNotifySettings *settings) { unique_ptr<NotificationSound> get_notification_sound(telegram_api::peerNotifySettings *settings, bool for_stories) {
CHECK(settings != nullptr); CHECK(settings != nullptr);
telegram_api::NotificationSound *sound = telegram_api::NotificationSound *sound =
#if TD_ANDROID #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 #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 #else
settings->other_sound_.get(); for_stories ? settings->stories_other_sound_.get() : settings->other_sound_.get();
#endif #endif
return get_notification_sound(sound); return get_notification_sound(sound);
} }

View File

@ -57,7 +57,7 @@ unique_ptr<NotificationSound> get_legacy_notification_sound(const string &sound)
unique_ptr<NotificationSound> get_notification_sound(bool use_default_sound, int64 ringtone_id); unique_ptr<NotificationSound> get_notification_sound(bool use_default_sound, int64 ringtone_id);
unique_ptr<NotificationSound> get_notification_sound(telegram_api::peerNotifySettings *settings); unique_ptr<NotificationSound> get_notification_sound(telegram_api::peerNotifySettings *settings, bool for_stories);
telegram_api::object_ptr<telegram_api::NotificationSound> get_input_notification_sound( telegram_api::object_ptr<telegram_api::NotificationSound> get_input_notification_sound(
const unique_ptr<NotificationSound> &notification_sound); const unique_ptr<NotificationSound> &notification_sound);

View File

@ -16,17 +16,23 @@ telegram_api::object_ptr<telegram_api::inputPeerNotifySettings>
ScopeNotificationSettings::get_input_peer_notify_settings() const { ScopeNotificationSettings::get_input_peer_notify_settings() const {
int32 flags = telegram_api::inputPeerNotifySettings::MUTE_UNTIL_MASK | int32 flags = telegram_api::inputPeerNotifySettings::MUTE_UNTIL_MASK |
telegram_api::inputPeerNotifySettings::SHOW_PREVIEWS_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) { if (sound != nullptr) {
flags |= telegram_api::inputPeerNotifySettings::SOUND_MASK; flags |= telegram_api::inputPeerNotifySettings::SOUND_MASK;
} }
if (story_sound != nullptr) {
flags |= telegram_api::inputPeerNotifySettings::STORIES_SOUND_MASK;
}
return telegram_api::make_object<telegram_api::inputPeerNotifySettings>( return telegram_api::make_object<telegram_api::inputPeerNotifySettings>(
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 &notification_settings) { StringBuilder &operator<<(StringBuilder &string_builder, const ScopeNotificationSettings &notification_settings) {
return string_builder << "[" << notification_settings.mute_until << ", " << notification_settings.sound << ", " return string_builder << "[" << notification_settings.mute_until << ", " << notification_settings.sound << ", "
<< notification_settings.show_preview << ", " << notification_settings.mute_stories << ", " << notification_settings.show_preview << ", " << notification_settings.mute_stories << ", "
<< notification_settings.story_sound << ", " << notification_settings.hide_story_sender << ", "
<< notification_settings.is_synchronized << ", " << notification_settings.is_synchronized << ", "
<< notification_settings.disable_pinned_message_notifications << ", " << notification_settings.disable_pinned_message_notifications << ", "
<< notification_settings.disable_mention_notifications << "]"; << notification_settings.disable_mention_notifications << "]";
@ -38,7 +44,8 @@ td_api::object_ptr<td_api::scopeNotificationSettings> get_scope_notification_set
return td_api::make_object<td_api::scopeNotificationSettings>( return td_api::make_object<td_api::scopeNotificationSettings>(
max(0, notification_settings->mute_until - G()->unix_time()), max(0, notification_settings->mute_until - G()->unix_time()),
get_notification_sound_ringtone_id(notification_settings->sound), notification_settings->show_preview, 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); notification_settings->disable_mention_notifications);
} }
@ -62,10 +69,11 @@ Result<ScopeNotificationSettings> get_scope_notification_settings(
} }
auto mute_until = get_mute_until(notification_settings->mute_for_); auto mute_until = get_mute_until(notification_settings->mute_for_);
return ScopeNotificationSettings(mute_until, get_notification_sound(false, notification_settings->sound_id_), return ScopeNotificationSettings(
notification_settings->show_preview_, notification_settings->mute_stories_, mute_until, get_notification_sound(false, notification_settings->sound_id_), notification_settings->show_preview_,
notification_settings->disable_pinned_message_notifications_, notification_settings->mute_stories_, get_notification_sound(false, notification_settings->story_sound_id_),
notification_settings->disable_mention_notifications_); !notification_settings->show_story_sender_, notification_settings->disable_pinned_message_notifications_,
notification_settings->disable_mention_notifications_);
} }
ScopeNotificationSettings get_scope_notification_settings(tl_object_ptr<telegram_api::peerNotifySettings> &&settings, ScopeNotificationSettings get_scope_notification_settings(tl_object_ptr<telegram_api::peerNotifySettings> &&settings,
@ -80,8 +88,15 @@ ScopeNotificationSettings get_scope_notification_settings(tl_object_ptr<telegram
} }
auto show_preview = settings->show_previews_; auto show_preview = settings->show_previews_;
auto mute_stories = settings->stories_muted_; auto mute_stories = settings->stories_muted_;
return {mute_until, get_notification_sound(settings.get()), show_preview, auto hide_story_sender = settings->stories_hide_sender_;
mute_stories, old_disable_pinned_message_notifications, old_disable_mention_notifications}; 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 } // namespace td

View File

@ -20,8 +20,10 @@ class ScopeNotificationSettings {
public: public:
int32 mute_until = 0; int32 mute_until = 0;
unique_ptr<NotificationSound> sound; unique_ptr<NotificationSound> sound;
unique_ptr<NotificationSound> story_sound;
bool show_preview = true; bool show_preview = true;
bool mute_stories = false; bool mute_stories = false;
bool hide_story_sender = false;
bool is_synchronized = false; bool is_synchronized = false;
// local settings // local settings
@ -31,12 +33,14 @@ class ScopeNotificationSettings {
ScopeNotificationSettings() = default; ScopeNotificationSettings() = default;
ScopeNotificationSettings(int32 mute_until, unique_ptr<NotificationSound> &&sound, bool show_preview, ScopeNotificationSettings(int32 mute_until, unique_ptr<NotificationSound> &&sound, bool show_preview,
bool mute_stories, bool disable_pinned_message_notifications, bool mute_stories, unique_ptr<NotificationSound> &&story_sound, bool hide_story_sender,
bool disable_mention_notifications) bool disable_pinned_message_notifications, bool disable_mention_notifications)
: mute_until(mute_until) : mute_until(mute_until)
, sound(std::move(sound)) , sound(std::move(sound))
, story_sound(std::move(story_sound))
, show_preview(show_preview) , show_preview(show_preview)
, mute_stories(mute_stories) , mute_stories(mute_stories)
, hide_story_sender(hide_story_sender)
, is_synchronized(true) , is_synchronized(true)
, disable_pinned_message_notifications(disable_pinned_message_notifications) , disable_pinned_message_notifications(disable_pinned_message_notifications)
, disable_mention_notifications(disable_mention_notifications) { , disable_mention_notifications(disable_mention_notifications) {

View File

@ -19,6 +19,7 @@ void store(const ScopeNotificationSettings &notification_settings, StorerT &stor
bool is_muted = notification_settings.mute_until != 0 && notification_settings.mute_until > G()->unix_time(); bool is_muted = notification_settings.mute_until != 0 && notification_settings.mute_until > G()->unix_time();
bool has_sound = notification_settings.sound != nullptr; bool has_sound = notification_settings.sound != nullptr;
bool has_ringtone_support = true; bool has_ringtone_support = true;
bool has_story_sound = notification_settings.story_sound != nullptr;
BEGIN_STORE_FLAGS(); BEGIN_STORE_FLAGS();
STORE_FLAG(is_muted); STORE_FLAG(is_muted);
STORE_FLAG(has_sound); STORE_FLAG(has_sound);
@ -29,6 +30,8 @@ void store(const ScopeNotificationSettings &notification_settings, StorerT &stor
STORE_FLAG(notification_settings.disable_mention_notifications); STORE_FLAG(notification_settings.disable_mention_notifications);
STORE_FLAG(has_ringtone_support); STORE_FLAG(has_ringtone_support);
STORE_FLAG(notification_settings.mute_stories); STORE_FLAG(notification_settings.mute_stories);
STORE_FLAG(has_story_sound);
STORE_FLAG(notification_settings.hide_story_sender);
END_STORE_FLAGS(); END_STORE_FLAGS();
if (is_muted) { if (is_muted) {
store(notification_settings.mute_until, storer); store(notification_settings.mute_until, storer);
@ -36,6 +39,9 @@ void store(const ScopeNotificationSettings &notification_settings, StorerT &stor
if (has_sound) { if (has_sound) {
store(notification_settings.sound, storer); store(notification_settings.sound, storer);
} }
if (has_story_sound) {
store(notification_settings.story_sound, storer);
}
} }
template <class ParserT> template <class ParserT>
@ -44,6 +50,7 @@ void parse(ScopeNotificationSettings &notification_settings, ParserT &parser) {
bool has_sound; bool has_sound;
bool silent_send_message_ignored; bool silent_send_message_ignored;
bool has_ringtone_support; bool has_ringtone_support;
bool has_story_sound;
BEGIN_PARSE_FLAGS(); BEGIN_PARSE_FLAGS();
PARSE_FLAG(is_muted); PARSE_FLAG(is_muted);
PARSE_FLAG(has_sound); PARSE_FLAG(has_sound);
@ -54,6 +61,8 @@ void parse(ScopeNotificationSettings &notification_settings, ParserT &parser) {
PARSE_FLAG(notification_settings.disable_mention_notifications); PARSE_FLAG(notification_settings.disable_mention_notifications);
PARSE_FLAG(has_ringtone_support); PARSE_FLAG(has_ringtone_support);
PARSE_FLAG(notification_settings.mute_stories); PARSE_FLAG(notification_settings.mute_stories);
PARSE_FLAG(has_story_sound);
PARSE_FLAG(notification_settings.hide_story_sender);
END_PARSE_FLAGS(); END_PARSE_FLAGS();
(void)silent_send_message_ignored; (void)silent_send_message_ignored;
if (is_muted) { if (is_muted) {
@ -68,6 +77,9 @@ void parse(ScopeNotificationSettings &notification_settings, ParserT &parser) {
notification_settings.sound = get_legacy_notification_sound(sound); notification_settings.sound = get_legacy_notification_sound(sound);
} }
} }
if (has_story_sound) {
parse_notification_sound(notification_settings.story_sound, parser);
}
} }
} // namespace td } // namespace td

View File

@ -5516,6 +5516,8 @@ class CliClient final : public Actor {
int64 sound_id; int64 sound_id;
string show_preview; string show_preview;
string mute_stories; string mute_stories;
int64 story_sound_id;
string hide_story_sender;
string disable_pinned_message_notifications; string disable_pinned_message_notifications;
string disable_mention_notifications; string disable_mention_notifications;
get_args(args, scope, mute_for, sound_id, show_preview, mute_stories, disable_pinned_message_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<td_api::setScopeNotificationSettings>( send_request(td_api::make_object<td_api::setScopeNotificationSettings>(
as_notification_settings_scope(scope), as_notification_settings_scope(scope),
td_api::make_object<td_api::scopeNotificationSettings>( td_api::make_object<td_api::scopeNotificationSettings>(
to_integer<int32>(mute_for), sound_id, as_bool(show_preview), as_bool(mute_stories), to_integer<int32>(mute_for), sound_id, as_bool(show_preview), as_bool(mute_stories), story_sound_id,
as_bool(disable_pinned_message_notifications), as_bool(disable_mention_notifications)))); as_bool(hide_story_sender), as_bool(disable_pinned_message_notifications),
as_bool(disable_mention_notifications))));
} else { } else {
auto settings = td_api::make_object<td_api::chatNotificationSettings>( auto settings = td_api::make_object<td_api::chatNotificationSettings>(
mute_for.empty(), to_integer<int32>(mute_for), sound_id == -1, sound_id, show_preview.empty(), mute_for.empty(), to_integer<int32>(mute_for), sound_id == -1, sound_id, show_preview.empty(),