Add disable_pinned_message_notifications option.

GitOrigin-RevId: 42c12c98abf2bbfa6c41e67f8b5b0c2f9a3536e9
This commit is contained in:
levlam 2019-12-30 00:35:19 +03:00
parent fd228ce404
commit ea3c65b3aa
3 changed files with 46 additions and 5 deletions

View File

@ -5221,11 +5221,13 @@ void MessagesManager::on_update_channel_max_unavailable_message_id(ChannelId cha
"on_update_channel_max_unavailable_message_id"); "on_update_channel_max_unavailable_message_id");
} }
void MessagesManager::on_update_include_sponsored_dialog_to_unread_count(bool include_sponsored_dialog) { void MessagesManager::on_update_include_sponsored_dialog_to_unread_count() {
if (td_->auth_manager_->is_bot()) { if (td_->auth_manager_->is_bot()) {
// just in case // just in case
return; return;
} }
bool include_sponsored_dialog = G()->shared_config().get_option_boolean("include_sponsored_chat_to_unread_count");
if (include_sponsored_dialog_to_unread_count_ == include_sponsored_dialog) { if (include_sponsored_dialog_to_unread_count_ == include_sponsored_dialog) {
return; return;
} }
@ -5256,6 +5258,30 @@ void MessagesManager::on_update_include_sponsored_dialog_to_unread_count(bool in
} }
} }
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) { bool MessagesManager::need_cancel_user_dialog_action(int32 action_id, MessageContentType message_content_type) {
if (message_content_type == MessageContentType::None) { if (message_content_type == MessageContentType::None) {
return true; return true;
@ -8696,6 +8722,8 @@ void MessagesManager::start_up() {
start_time_ = Time::now(); start_time_ = Time::now();
on_disable_pinned_message_notifications_changed();
include_sponsored_dialog_to_unread_count_ = include_sponsored_dialog_to_unread_count_ =
G()->shared_config().get_option_boolean("include_sponsored_chat_to_unread_count"); G()->shared_config().get_option_boolean("include_sponsored_chat_to_unread_count");
@ -21089,7 +21117,8 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
if (*need_update) { if (*need_update) {
if (message_content_type == MessageContentType::PinMessage && if (message_content_type == MessageContentType::PinMessage &&
!get_message_content_pinned_message_id(message->content.get()).is_valid()) { (disable_pinned_message_notifications_ ||
!get_message_content_pinned_message_id(message->content.get()).is_valid())) {
// treat message pin without pinned message as ordinary message // treat message pin without pinned message as ordinary message
message->contains_mention = false; message->contains_mention = false;
} }
@ -22178,6 +22207,10 @@ void MessagesManager::fix_new_dialog(Dialog *d, unique_ptr<Message> &&last_datab
} else { } else {
update_dialog_unmute_timeout(d, false, -1, false, d->notification_settings.mute_until); 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() &&
d->pinned_message_notification_message_id.is_valid()) {
set_dialog_pinned_message_notification(d, MessageId());
}
auto pending_it = pending_add_dialog_last_database_message_dependent_dialogs_.find(dialog_id); auto pending_it = pending_add_dialog_last_database_message_dependent_dialogs_.find(dialog_id);
if (pending_it != pending_add_dialog_last_database_message_dependent_dialogs_.end()) { if (pending_it != pending_add_dialog_last_database_message_dependent_dialogs_.end()) {

View File

@ -292,7 +292,9 @@ class MessagesManager : public Actor {
void on_update_channel_max_unavailable_message_id(ChannelId channel_id, MessageId max_unavailable_message_id); void on_update_channel_max_unavailable_message_id(ChannelId channel_id, MessageId max_unavailable_message_id);
void on_update_include_sponsored_dialog_to_unread_count(bool include_sponsored_dialog); 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<td_api::ChatAction> &&action, void on_user_dialog_action(DialogId dialog_id, UserId user_id, tl_object_ptr<td_api::ChatAction> &&action,
MessageContentType message_content_type = MessageContentType::None); MessageContentType message_content_type = MessageContentType::None);
@ -2175,6 +2177,8 @@ class MessagesManager : public Actor {
std::unordered_map<NotificationGroupId, DialogId, NotificationGroupIdHash> notification_group_id_to_dialog_id_; std::unordered_map<NotificationGroupId, DialogId, NotificationGroupIdHash> notification_group_id_to_dialog_id_;
bool disable_pinned_message_notifications_ = false;
bool include_sponsored_dialog_to_unread_count_ = false; bool include_sponsored_dialog_to_unread_count_ = false;
bool have_postponed_unread_message_count_update_ = false; bool have_postponed_unread_message_count_update_ = false;
bool have_postponed_unread_chat_count_update_ = false; bool have_postponed_unread_chat_count_update_ = false;

View File

@ -3543,8 +3543,7 @@ void Td::on_config_option_updated(const string &name) {
} else if (name == "favorite_stickers_limit") { } else if (name == "favorite_stickers_limit") {
stickers_manager_->on_update_favorite_stickers_limit(G()->shared_config().get_option_integer(name)); stickers_manager_->on_update_favorite_stickers_limit(G()->shared_config().get_option_integer(name));
} else if (name == "include_sponsored_chat_to_unread_count") { } else if (name == "include_sponsored_chat_to_unread_count") {
messages_manager_->on_update_include_sponsored_dialog_to_unread_count( messages_manager_->on_update_include_sponsored_dialog_to_unread_count();
G()->shared_config().get_option_boolean(name));
} else if (name == "my_id") { } else if (name == "my_id") {
G()->set_my_id(G()->shared_config().get_option_integer(name)); G()->set_my_id(G()->shared_config().get_option_integer(name));
} else if (name == "session_count") { } else if (name == "session_count") {
@ -3555,6 +3554,8 @@ void Td::on_config_option_updated(const string &name) {
send_closure(storage_manager_, &StorageManager::update_use_storage_optimizer); send_closure(storage_manager_, &StorageManager::update_use_storage_optimizer);
} else if (name == "rating_e_decay") { } else if (name == "rating_e_decay") {
return send_closure(top_dialog_manager_, &TopDialogManager::update_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") { } else if (name == "disable_top_chats") {
send_closure(top_dialog_manager_, &TopDialogManager::update_is_enabled, send_closure(top_dialog_manager_, &TopDialogManager::update_is_enabled,
!G()->shared_config().get_option_boolean(name)); !G()->shared_config().get_option_boolean(name));
@ -6326,6 +6327,9 @@ void Td::on_request(uint64 id, td_api::setOption &request) {
if (!is_bot && set_boolean_option("disable_contact_registered_notifications")) { if (!is_bot && set_boolean_option("disable_contact_registered_notifications")) {
return; return;
} }
if (!is_bot && set_boolean_option("disable_pinned_message_notifications")) {
return;
}
if (!is_bot && set_boolean_option("disable_top_chats")) { if (!is_bot && set_boolean_option("disable_top_chats")) {
return; return;
} }