diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 59f9710d..44fa89f5 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -8217,6 +8217,12 @@ void MessagesManager::set_dialog_last_read_inbox_message_id(Dialog *d, MessageId if (message_id != MessageId::min()) { d->last_read_inbox_message_id = message_id; d->is_last_read_inbox_message_id_inited = true; + + if (d->last_read_inbox_message_id.is_valid() && d->message_notification_group_id.is_valid()) { + send_closure_later(G()->notification_manager(), &NotificationManager::remove_notification_group, + d->message_notification_group_id, NotificationId(), d->last_read_inbox_message_id, + get_dialog_pending_notification_count(d), Promise()); + } } int32 old_unread_count = d->server_unread_count + d->local_unread_count; d->server_unread_count = server_unread_count; @@ -17387,6 +17393,7 @@ void MessagesManager::send_update_new_message(const Dialog *d, const Message *m) } NotificationGroupId MessagesManager::get_dialog_message_notification_group_id(Dialog *d) { + CHECK(d != nullptr); if (!d->message_notification_group_id.is_valid()) { d->message_notification_group_id = td_->notification_manager_->get_next_notification_group_id(); VLOG(notifications) << "Assign " << d->message_notification_group_id << " to " << d->dialog_id; @@ -17397,6 +17404,17 @@ NotificationGroupId MessagesManager::get_dialog_message_notification_group_id(Di return d->message_notification_group_id; } +int32 MessagesManager::get_dialog_pending_notification_count(Dialog *d) { + CHECK(d != nullptr); + if (is_dialog_muted(d)) { + // TODO pinned message? + // TODO hidden notifications? + return d->unread_mention_count; + } + + return d->server_unread_count + d->local_unread_count; // TODO remove/add some messages with unread mentions +} + void MessagesManager::add_new_message_notification(Dialog *d, Message *m, bool force) { CHECK(d != nullptr); CHECK(m != nullptr); diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index fe9a04ed..15860447 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -1455,6 +1455,8 @@ class MessagesManager : public Actor { NotificationGroupId get_dialog_message_notification_group_id(Dialog *d); + int32 get_dialog_pending_notification_count(Dialog *d); + void add_new_message_notification(Dialog *d, Message *m, bool force); void flush_pending_new_message_notifications(DialogId dialog_id);