Add scopeNotificationSettings.use_default_mute_stories.

This commit is contained in:
levlam 2023-07-06 18:42:44 +03:00
parent 25c73f32f5
commit b1cb40b22f
6 changed files with 30 additions and 14 deletions

View File

@ -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

View File

@ -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<>());
}

View File

@ -16,7 +16,6 @@ telegram_api::object_ptr<telegram_api::inputPeerNotifySettings>
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<telegram_api::inputPeerNotifySettings>(
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 &notification_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<td_api::scopeNotificationSettings> get_scope_notification_set
return td_api::make_object<td_api::scopeNotificationSettings>(
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<ScopeNotificationSettings> 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_ptr<telegram
mute_until = 0;
}
auto show_preview = settings->show_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,

View File

@ -22,6 +22,7 @@ class ScopeNotificationSettings {
unique_ptr<NotificationSound> sound;
unique_ptr<NotificationSound> 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<NotificationSound> &&sound, bool show_preview,
bool mute_stories, unique_ptr<NotificationSound> &&story_sound, bool hide_story_sender,
bool use_default_mute_stories, bool mute_stories,
unique_ptr<NotificationSound> &&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)

View File

@ -20,6 +20,7 @@ void store(const ScopeNotificationSettings &notification_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 &notification_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 &notification_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 &notification_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 &notification_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

View File

@ -5534,9 +5534,9 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::setScopeNotificationSettings>(
as_notification_settings_scope(scope),
td_api::make_object<td_api::scopeNotificationSettings>(
to_integer<int32>(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<int32>(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<td_api::chatNotificationSettings>(
mute_for.empty(), to_integer<int32>(mute_for), sound_id == -1, sound_id, show_preview.empty(),