From ed9e4baae805cf9d818032ecc998e07bbcac2683 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 10 Jan 2019 03:47:33 +0300 Subject: [PATCH] Support per chat disable_pinned_message_notification setting. GitOrigin-RevId: 775384f42d6f31ac983e40836a88b63c0eab1962 --- td/generate/scheme/td_api.tl | 12 ++- td/generate/scheme/td_api.tlo | Bin 140068 -> 140260 bytes td/telegram/MessagesManager.cpp | 137 ++++++++++++++------------- td/telegram/MessagesManager.h | 6 +- td/telegram/NotificationManager.cpp | 2 +- td/telegram/NotificationSettings.cpp | 38 +++++--- td/telegram/NotificationSettings.h | 30 ++++-- td/telegram/NotificationSettings.hpp | 8 ++ td/telegram/Td.cpp | 5 - td/telegram/cli.cpp | 17 +++- 10 files changed, 153 insertions(+), 102 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index e147edf6..f79a51b0 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -523,11 +523,15 @@ notificationSettingsScopeGroupChats = NotificationSettingsScope; //@use_default_mute_for If true, mute_for is ignored and the value for the relevant type of chat is used instead @mute_for Time left before notifications will be unmuted, in seconds //@use_default_sound If true, sound is ignored and the value for the relevant type of chat is used instead @sound The name of an audio file to be used for notification sounds; only applies to iOS applications //@use_default_show_preview If true, show_preview is ignored and the value for the relevant type of chat is used instead @show_preview True, if message content should be displayed in notifications -chatNotificationSettings use_default_mute_for:Bool mute_for:int32 use_default_sound:Bool sound:string use_default_show_preview:Bool show_preview:Bool = ChatNotificationSettings; +//@use_default_disable_pinned_message_notification If true, disable_pinned_message_notification is ignored and the value for the relevant type of chat is used instead @disable_pinned_message_notification If true, notifications for incoming pinned messages will be created as for an ordinary unread message +chatNotificationSettings use_default_mute_for:Bool mute_for:int32 use_default_sound:Bool sound:string use_default_show_preview:Bool show_preview:Bool use_default_disable_pinned_message_notification:Bool disable_pinned_message_notification:Bool = ChatNotificationSettings; -//@description Contains information about notification settings for several chats @mute_for Time left before notifications will be unmuted, in seconds -//@sound The name of an audio file to be used for notification sounds; only applies to iOS applications @show_preview True, if message content should be displayed in notifications -scopeNotificationSettings mute_for:int32 sound:string show_preview:Bool = ScopeNotificationSettings; +//@description Contains information about notification settings for several chats +//@mute_for Time left before notifications will be unmuted, in seconds +//@sound The name of an audio file to be used for notification sounds; only applies to iOS applications +//@show_preview True, if message content should be displayed in notifications +//@disable_pinned_message_notification True, if notifications for incoming pinned messages will be created as for an ordinary unread message +scopeNotificationSettings mute_for:int32 sound:string show_preview:Bool disable_pinned_message_notification:Bool = ScopeNotificationSettings; //@description Contains information about a message draft @reply_to_message_id Identifier of the message to reply to; 0 if none @input_message_text Content of the message draft; this should always be of type inputMessageText diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 624a03c0a9bc0a88ba0ed0f5945d4cfbcb65781f..6245b1e129c469d9a8869f57397bd1eea1a12e4b 100644 GIT binary patch delta 341 zcmZ2-jN{31jtw_hSEA*!n*mSiHhVjVJ7L#6Qp94SwPa8KiDpj zU;`^mo~{tWD8bFZ0OH*|Cgj65d2iVN$qo@55S2a=Q;x8KjVPYZD9j|q31WlPF;9LQ zraj$6meB>Q7$m&?fGpz)GqApCo{S39*Mu;Zuz(~$yzMTbjBDz^-05E~Ga7(d+cmB* Wh8Tl&Y;Ry^dczG7Ef8iZ5dZ+|5K7Vj diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index c38b28ff..1dcb59e2 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -5260,30 +5260,6 @@ void MessagesManager::on_update_include_sponsored_dialog_to_unread_count() { } } -void MessagesManager::on_disable_pinned_message_notifications_changed() { - if (td_->auth_manager_->is_bot()) { - // just in case - return; - } - - bool disable_pinned_message_notifications = - G()->shared_config().get_option_boolean("disable_pinned_message_notifications"); - if (disable_pinned_message_notifications_ == disable_pinned_message_notifications) { - return; - } - - disable_pinned_message_notifications_ = disable_pinned_message_notifications; - - if (disable_pinned_message_notifications_) { - for (auto &dialog : dialogs_) { - Dialog *d = dialog.second.get(); - if (d->mention_notification_group.group_id.is_valid() && d->pinned_message_notification_message_id.is_valid()) { - set_dialog_pinned_message_notification(d, MessageId()); - } - } - } -} - bool MessagesManager::need_cancel_user_dialog_action(int32 action_id, MessageContentType message_content_type) { if (message_content_type == MessageContentType::None) { return true; @@ -5745,15 +5721,18 @@ void MessagesManager::save_scope_notification_settings(NotificationSettingsScope bool MessagesManager::update_dialog_notification_settings(DialogId dialog_id, DialogNotificationSettings *current_settings, const DialogNotificationSettings &new_settings) { - bool need_update = current_settings->mute_until != new_settings.mute_until || - current_settings->sound != new_settings.sound || - current_settings->show_preview != new_settings.show_preview || - current_settings->use_default_mute_until != new_settings.use_default_mute_until || - current_settings->use_default_sound != new_settings.use_default_sound || - current_settings->use_default_show_preview != new_settings.use_default_show_preview; - bool need_update_default_disable_notification = - current_settings->silent_send_message != new_settings.silent_send_message; - bool is_changed = need_update || need_update_default_disable_notification || + bool need_update_server = current_settings->mute_until != new_settings.mute_until || + current_settings->sound != new_settings.sound || + current_settings->show_preview != new_settings.show_preview || + current_settings->use_default_mute_until != new_settings.use_default_mute_until || + current_settings->use_default_sound != new_settings.use_default_sound || + current_settings->use_default_show_preview != new_settings.use_default_show_preview; + bool need_update_local = + current_settings->use_default_disable_pinned_message_notification != + new_settings.use_default_disable_pinned_message_notification || + current_settings->disable_pinned_message_notification != new_settings.disable_pinned_message_notification; + + bool is_changed = need_update_server || need_update_local || current_settings->is_synchronized != new_settings.is_synchronized || current_settings->is_use_default_fixed != new_settings.is_use_default_fixed; @@ -5772,41 +5751,54 @@ bool MessagesManager::update_dialog_notification_settings(DialogId dialog_id, if (!was_muted && is_dialog_muted(d)) { remove_all_dialog_notifications(dialog_id, d->message_notification_group, "save_scope_notification_settings"); } + if (is_dialog_pinned_message_notification_disabled(d) && d->mention_notification_group.group_id.is_valid() && + d->pinned_message_notification_message_id.is_valid()) { + set_dialog_pinned_message_notification(d, MessageId()); + } - if (need_update) { + if (need_update_server || need_update_local) { send_closure(G()->td(), &Td::send_update, make_tl_object( dialog_id.get(), get_chat_notification_settings_object(current_settings))); } - if (need_update_default_disable_notification) { - send_closure(G()->td(), &Td::send_update, - make_tl_object(dialog_id.get(), - current_settings->silent_send_message)); - } } - return is_changed; + return need_update_server; } bool MessagesManager::update_scope_notification_settings(NotificationSettingsScope scope, ScopeNotificationSettings *current_settings, const ScopeNotificationSettings &new_settings) { - bool need_update = current_settings->mute_until != new_settings.mute_until || - current_settings->sound != new_settings.sound || - current_settings->show_preview != new_settings.show_preview; - bool is_changed = need_update || current_settings->is_synchronized != new_settings.is_synchronized; + bool need_update_server = current_settings->mute_until != new_settings.mute_until || + current_settings->sound != new_settings.sound || + current_settings->show_preview != new_settings.show_preview; + bool need_update_local = + current_settings->disable_pinned_message_notification != new_settings.disable_pinned_message_notification; + bool is_changed = + need_update_server || need_update_local || current_settings->is_synchronized != new_settings.is_synchronized; if (is_changed) { save_scope_notification_settings(scope, new_settings); update_scope_unmute_timeout(scope, current_settings->mute_until, new_settings.mute_until); + if (!current_settings->disable_pinned_message_notification && new_settings.disable_pinned_message_notification) { + VLOG(notifications) << "Remove pinned message notifications in " << scope; + for (auto &dialog : dialogs_) { + Dialog *d = dialog.second.get(); + if (d->mention_notification_group.group_id.is_valid() && d->pinned_message_notification_message_id.is_valid() && + get_dialog_notification_setting_scope(d->dialog_id) == scope) { + set_dialog_pinned_message_notification(d, MessageId()); + } + } + } + LOG(INFO) << "Update notification settings in " << scope << " from " << *current_settings << " to " << new_settings; *current_settings = new_settings; - if (need_update) { + if (need_update_server || need_update_local) { send_closure(G()->td(), &Td::send_update, get_update_scope_notification_settings_object(scope)); } } - return is_changed; + return need_update_server; } void MessagesManager::update_dialog_unmute_timeout(Dialog *d, bool old_use_default, int32 old_mute_until, @@ -5971,16 +5963,18 @@ void MessagesManager::on_update_dialog_notify_settings( LOG(INFO) << "Receive notification settings for " << dialog_id << ": " << to_string(peer_notify_settings); - const DialogNotificationSettings notification_settings = - td::get_dialog_notification_settings(std::move(peer_notify_settings)); - if (!notification_settings.is_synchronized) { - return; - } - DialogNotificationSettings *current_settings = get_dialog_notification_settings(dialog_id, true); if (current_settings == nullptr) { return; } + + const DialogNotificationSettings notification_settings = td::get_dialog_notification_settings( + std::move(peer_notify_settings), current_settings->use_default_disable_pinned_message_notification, + current_settings->disable_pinned_message_notification); + if (!notification_settings.is_synchronized) { + return; + } + update_dialog_notification_settings(dialog_id, current_settings, notification_settings); } @@ -5990,13 +5984,16 @@ void MessagesManager::on_update_scope_notify_settings( return; } - const ScopeNotificationSettings notification_settings = - td::get_scope_notification_settings(std::move(peer_notify_settings)); + auto old_notification_settings = get_scope_notification_settings(scope); + CHECK(old_notification_settings != nullptr); + + const ScopeNotificationSettings notification_settings = td::get_scope_notification_settings( + std::move(peer_notify_settings), old_notification_settings->disable_pinned_message_notification); if (!notification_settings.is_synchronized) { return; } - update_scope_notification_settings(scope, get_scope_notification_settings(scope), notification_settings); + update_scope_notification_settings(scope, old_notification_settings, notification_settings); } bool MessagesManager::update_dialog_silent_send_message(Dialog *d, bool silent_send_message) { @@ -8750,8 +8747,6 @@ void MessagesManager::init() { start_time_ = Time::now(); - on_disable_pinned_message_notifications_changed(); - include_sponsored_dialog_to_unread_count_ = G()->shared_config().get_option_boolean("include_sponsored_chat_to_unread_count"); @@ -8851,9 +8846,6 @@ void MessagesManager::init() { if (!notification_settings_string.empty()) { ScopeNotificationSettings notification_settings; log_event_parse(notification_settings, notification_settings_string).ensure(); - if (!notification_settings.is_synchronized) { - continue; - } auto current_settings = get_scope_notification_settings(scope); CHECK(current_settings != nullptr); @@ -12341,6 +12333,16 @@ bool MessagesManager::is_dialog_muted(const Dialog *d) const { return get_dialog_mute_until(d) != 0; } +bool MessagesManager::is_dialog_pinned_message_notification_disabled(const Dialog *d) const { + CHECK(d != nullptr); + if (d->notification_settings.use_default_disable_pinned_message_notification) { + auto scope = get_dialog_notification_setting_scope(d->dialog_id); + return get_scope_notification_settings(scope)->disable_pinned_message_notification; + } + + return d->notification_settings.disable_pinned_message_notification; +} + void MessagesManager::create_dialog(DialogId dialog_id, bool force, Promise &&promise) { if (!have_input_peer(dialog_id, AccessRights::Read)) { if (!have_dialog_info_force(dialog_id)) { @@ -12958,7 +12960,9 @@ Status MessagesManager::set_dialog_notification_settings( DialogNotificationSettings new_settings( notification_settings->use_default_mute_for_, mute_until, notification_settings->use_default_sound_, std::move(notification_settings->sound_), notification_settings->use_default_show_preview_, - notification_settings->show_preview_, current_settings->silent_send_message); + notification_settings->show_preview_, current_settings->silent_send_message, + notification_settings->use_default_disable_pinned_message_notification_, + notification_settings->disable_pinned_message_notification_); if (update_dialog_notification_settings(dialog_id, current_settings, new_settings)) { update_dialog_notification_settings_on_server(dialog_id, false); } @@ -12987,7 +12991,8 @@ Status MessagesManager::set_scope_notification_settings( } ScopeNotificationSettings new_settings(mute_until, std::move(notification_settings->sound_), - notification_settings->show_preview_); + notification_settings->show_preview_, + notification_settings->disable_pinned_message_notification_); if (update_scope_notification_settings(scope, get_scope_notification_settings(scope), new_settings)) { update_scope_notification_settings_on_server(scope, 0); @@ -21192,7 +21197,7 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq if (*need_update) { if (message_content_type == MessageContentType::PinMessage && - (disable_pinned_message_notifications_ || + (is_dialog_pinned_message_notification_disabled(d) || !get_message_content_pinned_message_id(message->content.get()).is_valid())) { // treat message pin without pinned message as ordinary message message->contains_mention = false; @@ -21530,7 +21535,8 @@ void MessagesManager::delete_all_dialog_messages_from_database(Dialog *d, Messag } } */ - G()->td_db()->get_messages_db_async()->delete_all_dialog_messages(dialog_id, max_message_id, Auto()); // TODO Promise + G()->td_db()->get_messages_db_async()->delete_all_dialog_messages(dialog_id, max_message_id, + Auto()); // TODO Promise } class MessagesManager::DeleteMessageLogEvent { @@ -22289,8 +22295,9 @@ void MessagesManager::fix_new_dialog(Dialog *d, unique_ptr &&last_datab } else { update_dialog_unmute_timeout(d, false, -1, false, d->notification_settings.mute_until); } - if (disable_pinned_message_notifications_ && d->mention_notification_group.group_id.is_valid() && + if (is_dialog_pinned_message_notification_disabled(d) && d->mention_notification_group.group_id.is_valid() && d->pinned_message_notification_message_id.is_valid()) { + VLOG(notifications) << "Remove disabled pinned message notification in " << dialog_id; set_dialog_pinned_message_notification(d, MessageId()); } diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index f690b6f6..d6c06396 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -294,8 +294,6 @@ class MessagesManager : public Actor { void on_update_include_sponsored_dialog_to_unread_count(); - void on_disable_pinned_message_notifications_changed(); - void on_user_dialog_action(DialogId dialog_id, UserId user_id, tl_object_ptr &&action, MessageContentType message_content_type = MessageContentType::None); @@ -1217,6 +1215,8 @@ class MessagesManager : public Actor { bool is_dialog_muted(const Dialog *d) const; + bool is_dialog_pinned_message_notification_disabled(const Dialog *d) const; + void open_dialog(Dialog *d); void close_dialog(Dialog *d); @@ -2181,8 +2181,6 @@ class MessagesManager : public Actor { std::unordered_map notification_group_id_to_dialog_id_; - bool disable_pinned_message_notifications_ = false; - bool include_sponsored_dialog_to_unread_count_ = false; bool have_postponed_unread_message_count_update_ = false; bool have_postponed_unread_chat_count_update_ = false; diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index 261af61f..315c403e 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -293,7 +293,7 @@ int32 NotificationManager::load_message_notification_groups_from_database(int32 auto group_it = get_group_force(group_key.group_id, send_update); CHECK(group_it != groups_.end()); CHECK(group_it->first.dialog_id.is_valid()); - if (group_it->first.last_notification_date > 0) { + if (!(last_loaded_notification_group_key_ < group_it->first)) { result++; } } diff --git a/td/telegram/NotificationSettings.cpp b/td/telegram/NotificationSettings.cpp index 64a7806d..7c42cfdf 100644 --- a/td/telegram/NotificationSettings.cpp +++ b/td/telegram/NotificationSettings.cpp @@ -15,9 +15,11 @@ namespace td { 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 - << ", " << notification_settings.use_default_mute_until << ", " + << ", " << notification_settings.disable_pinned_message_notification << ", " + << notification_settings.use_default_mute_until << ", " << notification_settings.use_default_sound << ", " << notification_settings.use_default_show_preview << ", " + << notification_settings.use_default_disable_pinned_message_notification << ", " << notification_settings.is_synchronized << "]"; } @@ -35,7 +37,8 @@ StringBuilder &operator<<(StringBuilder &string_builder, NotificationSettingsSco 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.is_synchronized << "]"; + << notification_settings.show_preview << ", " << notification_settings.is_synchronized << ", " + << notification_settings.disable_pinned_message_notification << "]"; } td_api::object_ptr get_notification_settings_scope_object( @@ -53,17 +56,21 @@ td_api::object_ptr get_notification_settings_ td_api::object_ptr get_chat_notification_settings_object( const DialogNotificationSettings *notification_settings) { + CHECK(notification_settings != nullptr); return td_api::make_object( notification_settings->use_default_mute_until, max(0, notification_settings->mute_until - G()->unix_time()), notification_settings->use_default_sound, notification_settings->sound, - notification_settings->use_default_show_preview, notification_settings->show_preview); + notification_settings->use_default_show_preview, notification_settings->show_preview, + notification_settings->use_default_disable_pinned_message_notification, + notification_settings->disable_pinned_message_notification); } td_api::object_ptr get_scope_notification_settings_object( const ScopeNotificationSettings *notification_settings) { + CHECK(notification_settings != nullptr); return td_api::make_object( max(0, notification_settings->mute_until - G()->unix_time()), notification_settings->sound, - notification_settings->show_preview); + notification_settings->show_preview, notification_settings->disable_pinned_message_notification); } telegram_api::object_ptr get_input_notify_peer(NotificationSettingsScope scope) { @@ -91,21 +98,28 @@ NotificationSettingsScope get_notification_settings_scope( } } -DialogNotificationSettings get_dialog_notification_settings( - tl_object_ptr &&settings) { +DialogNotificationSettings get_dialog_notification_settings(tl_object_ptr &&settings, + bool old_use_default_disable_pinned_message_notification, + bool old_disable_pinned_message_notification) { bool use_default_mute_until = (settings->flags_ & telegram_api::peerNotifySettings::MUTE_UNTIL_MASK) == 0; bool use_default_sound = (settings->flags_ & telegram_api::peerNotifySettings::SOUND_MASK) == 0; bool use_default_show_preview = (settings->flags_ & telegram_api::peerNotifySettings::SHOW_PREVIEWS_MASK) == 0; auto mute_until = use_default_mute_until || settings->mute_until_ <= G()->unix_time() ? 0 : settings->mute_until_; bool silent_send_message = (settings->flags_ & telegram_api::peerNotifySettings::SILENT_MASK) == 0 ? false : settings->silent_; - return {use_default_mute_until, mute_until, - use_default_sound, std::move(settings->sound_), - use_default_show_preview, settings->show_previews_, - silent_send_message}; + return {use_default_mute_until, + mute_until, + use_default_sound, + std::move(settings->sound_), + use_default_show_preview, + settings->show_previews_, + silent_send_message, + old_use_default_disable_pinned_message_notification, + old_disable_pinned_message_notification}; } -ScopeNotificationSettings get_scope_notification_settings(tl_object_ptr &&settings) { +ScopeNotificationSettings get_scope_notification_settings(tl_object_ptr &&settings, + bool old_disable_pinned_message_notification) { auto mute_until = (settings->flags_ & telegram_api::peerNotifySettings::MUTE_UNTIL_MASK) == 0 || settings->mute_until_ <= G()->unix_time() ? 0 @@ -114,7 +128,7 @@ ScopeNotificationSettings get_scope_notification_settings(tl_object_ptrflags_ & telegram_api::peerNotifySettings::SOUND_MASK) == 0 ? "default" : std::move(settings->sound_); auto show_preview = (settings->flags_ & telegram_api::peerNotifySettings::SHOW_PREVIEWS_MASK) == 0 ? false : settings->show_previews_; - return {mute_until, std::move(sound), show_preview}; + return {mute_until, std::move(sound), show_preview, old_disable_pinned_message_notification}; } } // namespace td diff --git a/td/telegram/NotificationSettings.h b/td/telegram/NotificationSettings.h index 219940dc..d105fe57 100644 --- a/td/telegram/NotificationSettings.h +++ b/td/telegram/NotificationSettings.h @@ -26,10 +26,16 @@ class DialogNotificationSettings { bool is_use_default_fixed = true; bool is_synchronized = false; + // local settings + bool use_default_disable_pinned_message_notification = true; + bool disable_pinned_message_notification = false; + DialogNotificationSettings() = default; DialogNotificationSettings(bool use_default_mute_until, int32 mute_until, bool use_default_sound, string sound, - bool use_default_show_preview, bool show_preview, bool silent_send_message) + bool use_default_show_preview, bool show_preview, bool silent_send_message, + bool use_default_disable_pinned_message_notification, + bool disable_pinned_message_notification) : mute_until(mute_until) , sound(std::move(sound)) , show_preview(show_preview) @@ -37,7 +43,9 @@ class DialogNotificationSettings { , use_default_mute_until(use_default_mute_until) , use_default_sound(use_default_sound) , use_default_show_preview(use_default_show_preview) - , is_synchronized(true) { + , is_synchronized(true) + , use_default_disable_pinned_message_notification(use_default_disable_pinned_message_notification) + , disable_pinned_message_notification(disable_pinned_message_notification) { } }; @@ -50,10 +58,17 @@ class ScopeNotificationSettings { bool show_preview = true; bool is_synchronized = false; + // local settings + bool disable_pinned_message_notification = false; + ScopeNotificationSettings() = default; - ScopeNotificationSettings(int32 mute_until, string sound, bool show_preview) - : mute_until(mute_until), sound(std::move(sound)), show_preview(show_preview), is_synchronized(true) { + ScopeNotificationSettings(int32 mute_until, string sound, bool show_preview, bool disable_pinned_message_notification) + : mute_until(mute_until) + , sound(std::move(sound)) + , show_preview(show_preview) + , is_synchronized(true) + , disable_pinned_message_notification(disable_pinned_message_notification) { } }; @@ -77,8 +92,11 @@ telegram_api::object_ptr get_input_notify_peer(No NotificationSettingsScope get_notification_settings_scope( const td_api::object_ptr &scope); -DialogNotificationSettings get_dialog_notification_settings(tl_object_ptr &&settings); +DialogNotificationSettings get_dialog_notification_settings(tl_object_ptr &&settings, + bool old_use_default_disable_pinned_message_notification, + bool old_disable_pinned_message_notification); -ScopeNotificationSettings get_scope_notification_settings(tl_object_ptr &&settings); +ScopeNotificationSettings get_scope_notification_settings(tl_object_ptr &&settings, + bool old_disable_pinned_message_notification); } // namespace td diff --git a/td/telegram/NotificationSettings.hpp b/td/telegram/NotificationSettings.hpp index 880dca5d..86611674 100644 --- a/td/telegram/NotificationSettings.hpp +++ b/td/telegram/NotificationSettings.hpp @@ -28,6 +28,8 @@ void store(const DialogNotificationSettings ¬ification_settings, StorerT &sto STORE_FLAG(notification_settings.use_default_sound); STORE_FLAG(notification_settings.use_default_show_preview); STORE_FLAG(notification_settings.is_use_default_fixed); + STORE_FLAG(!notification_settings.use_default_disable_pinned_message_notification); + STORE_FLAG(notification_settings.disable_pinned_message_notification); END_STORE_FLAGS(); if (is_muted) { store(notification_settings.mute_until, storer); @@ -41,6 +43,7 @@ template void parse(DialogNotificationSettings ¬ification_settings, ParserT &parser) { bool is_muted; bool has_sound; + bool use_disable_pinned_message_notification; BEGIN_PARSE_FLAGS(); PARSE_FLAG(is_muted); PARSE_FLAG(has_sound); @@ -51,7 +54,10 @@ void parse(DialogNotificationSettings ¬ification_settings, ParserT &parser) { PARSE_FLAG(notification_settings.use_default_sound); PARSE_FLAG(notification_settings.use_default_show_preview); PARSE_FLAG(notification_settings.is_use_default_fixed); + PARSE_FLAG(use_disable_pinned_message_notification); + PARSE_FLAG(notification_settings.disable_pinned_message_notification); END_PARSE_FLAGS(); + notification_settings.use_default_disable_pinned_message_notification = !use_disable_pinned_message_notification; if (is_muted) { parse(notification_settings.mute_until, parser); } @@ -70,6 +76,7 @@ void store(const ScopeNotificationSettings ¬ification_settings, StorerT &stor STORE_FLAG(notification_settings.show_preview); STORE_FLAG(false); STORE_FLAG(notification_settings.is_synchronized); + STORE_FLAG(notification_settings.disable_pinned_message_notification); END_STORE_FLAGS(); if (is_muted) { store(notification_settings.mute_until, storer); @@ -90,6 +97,7 @@ void parse(ScopeNotificationSettings ¬ification_settings, ParserT &parser) { PARSE_FLAG(notification_settings.show_preview); PARSE_FLAG(silent_send_message_ignored); PARSE_FLAG(notification_settings.is_synchronized); + PARSE_FLAG(notification_settings.disable_pinned_message_notification); END_PARSE_FLAGS(); (void)silent_send_message_ignored; if (is_muted) { diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 0e952e35..3750c0fa 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -3554,8 +3554,6 @@ void Td::on_config_option_updated(const string &name) { send_closure(storage_manager_, &StorageManager::update_use_storage_optimizer); } else if (name == "rating_e_decay") { return send_closure(top_dialog_manager_, &TopDialogManager::update_rating_e_decay); - } else if (name == "disable_pinned_message_notifications") { - send_closure(messages_manager_actor_, &MessagesManager::on_disable_pinned_message_notifications_changed); } else if (name == "disable_top_chats") { send_closure(top_dialog_manager_, &TopDialogManager::update_is_enabled, !G()->shared_config().get_option_boolean(name)); @@ -6340,9 +6338,6 @@ void Td::on_request(uint64 id, td_api::setOption &request) { if (!is_bot && set_boolean_option("disable_contact_registered_notifications")) { return; } - if (!is_bot && set_boolean_option("disable_pinned_message_notifications")) { - return; - } if (!is_bot && set_boolean_option("disable_top_chats")) { return; } diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index f23c8fe6..195124c7 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3379,14 +3379,18 @@ class CliClient final : public Actor { string mute_for; string sound; string show_preview; + string disable_pinned_message_notification; std::tie(mute_for, settings) = split(settings, ','); - std::tie(sound, show_preview) = split(settings, ','); + std::tie(sound, settings) = split(settings, ','); + std::tie(show_preview, disable_pinned_message_notification) = split(settings, ','); send_request(make_tl_object( as_chat_id(chat_id), make_tl_object(mute_for.empty(), to_integer(mute_for), sound.empty(), - sound, show_preview.empty(), as_bool(show_preview)))); + sound, show_preview.empty(), as_bool(show_preview), + disable_pinned_message_notification.empty(), + as_bool(disable_pinned_message_notification)))); } else if (op == "ssns") { string scope; string settings; @@ -3396,13 +3400,16 @@ class CliClient final : public Actor { string mute_for; string sound; string show_preview; + string disable_pinned_message_notification; std::tie(mute_for, settings) = split(settings, ','); - std::tie(sound, show_preview) = split(settings, ','); + std::tie(sound, settings) = split(settings, ','); + std::tie(show_preview, disable_pinned_message_notification) = split(settings, ','); send_request(make_tl_object( - get_notification_settings_scope(scope), make_tl_object( - to_integer(mute_for), sound, as_bool(show_preview)))); + get_notification_settings_scope(scope), + make_tl_object(to_integer(mute_for), sound, as_bool(show_preview), + as_bool(disable_pinned_message_notification)))); } else if (op == "rans") { send_request(make_tl_object()); } else if (op == "rn") {