diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 5fe57862..5f009c6f 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -19250,6 +19250,17 @@ bool MessagesManager::add_new_message_notification(Dialog *d, Message *m, bool f CHECK(d != nullptr); CHECK(m != nullptr); + if (!force) { + if (d->message_notification_group.group_id.is_valid()) { + send_closure_later(G()->notification_manager(), &NotificationManager::remove_temporary_notifications, + d->message_notification_group.group_id); + } + if (d->mention_notification_group.group_id.is_valid()) { + send_closure_later(G()->notification_manager(), &NotificationManager::remove_temporary_notifications, + d->mention_notification_group.group_id); + } + } + CHECK(!m->notification_id.is_valid()); if (is_message_notification_disabled(d, m)) { return false; @@ -22992,6 +23003,11 @@ void MessagesManager::delete_message_from_database(Dialog *d, MessageId message_ m->notification_id, true, false, Promise()); } } + } else if (message_id.get() > d->last_new_message_id.get()) { + send_closure_later(G()->notification_manager(), &NotificationManager::remove_temporary_notification_by_message_id, + d->message_notification_group.group_id, message_id, false); + send_closure_later(G()->notification_manager(), &NotificationManager::remove_temporary_notification_by_message_id, + d->mention_notification_group.group_id, message_id, false); } auto need_delete_message_files = m != nullptr && (d->dialog_id.get_type() == DialogType::User || @@ -24851,7 +24867,7 @@ void MessagesManager::on_get_channel_difference( } void MessagesManager::after_get_channel_difference(DialogId dialog_id, bool success) { - LOG(INFO) << "After " << (success ? "un" : "") << "successful get channel difference in " << dialog_id; + LOG(INFO) << "After " << (success ? "" : "un") << "successful get channel difference in " << dialog_id; LOG_CHECK(!running_get_channel_difference(dialog_id)) << '"' << active_get_channel_differencies_[dialog_id] << '"'; auto logevent_it = get_channel_difference_to_logevent_id_.find(dialog_id); diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index 0659fb09..b8bfa15f 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -2048,11 +2048,15 @@ void NotificationManager::remove_temporary_notifications(NotificationGroupId gro return; } - auto group_it = get_group_force(group_id); + auto group_it = get_group(group_id); if (group_it == groups_.end()) { return; } + if (get_temporary_notification_total_count(group_it->second) == 0) { + return; + } + auto &group = group_it->second; while (!group.pending_notifications.empty() && group.pending_notifications.back().type->is_temporary()) { VLOG(notifications) << "Remove temporary " << group.pending_notifications.back() << " from " << group_id; diff --git a/td/telegram/NotificationManager.h b/td/telegram/NotificationManager.h index 4f5ca7c2..d2e2dfbb 100644 --- a/td/telegram/NotificationManager.h +++ b/td/telegram/NotificationManager.h @@ -73,6 +73,8 @@ class NotificationManager : public Actor { void remove_notification(NotificationGroupId group_id, NotificationId notification_id, bool is_permanent, bool force_update, Promise &&promise); + void remove_temporary_notifications(NotificationGroupId group_id); + void remove_temporary_notification_by_message_id(NotificationGroupId group_id, MessageId message_id, bool force_update); @@ -226,8 +228,6 @@ class NotificationManager : public Actor { static int32 get_temporary_notification_total_count(const NotificationGroup &group); - void remove_temporary_notifications(NotificationGroupId group_id); - int32 load_message_notification_groups_from_database(int32 limit, bool send_update); void load_message_notifications_from_database(const NotificationGroupKey &group_key, NotificationGroup &group,