From 9615604ecfe02ee72d395953a5b9570d1c144367 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 30 Nov 2018 01:57:24 +0300 Subject: [PATCH] Fix race in get_message_notification_group_force. GitOrigin-RevId: 7c75103e168f41b1964504f53d69cee85210d601 --- td/telegram/MessagesManager.cpp | 6 +++++- td/telegram/MessagesManager.h | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 34f5c86f..0c95857e 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -17605,7 +17605,8 @@ MessagesManager::MessageNotificationGroup MessagesManager::get_message_notificat result.dialog_id = d->dialog_id; result.total_count = get_dialog_pending_notification_count(d); result.notifications = get_message_notifications_from_database( - d, NotificationId::max(), td_->notification_manager_->get_max_notification_group_size()); + d, d->first_new_notification_id.is_valid() ? d->first_new_notification_id : NotificationId::max(), + td_->notification_manager_->get_max_notification_group_size()); int32 last_notification_date = 0; NotificationId last_notification_id; @@ -17857,6 +17858,9 @@ bool MessagesManager::add_new_message_notification(Dialog *d, Message *m, bool f add_notification_id_to_message_id_correspondence(d, m->notification_id, m->message_id); } bool is_changed = set_dialog_last_notification(d, m->date, m->notification_id, "add_new_message_notification"); + if (!d->first_new_notification_id.is_valid()) { + d->first_new_notification_id = m->notification_id; + } CHECK(is_changed); VLOG(notifications) << "Create " << m->notification_id << " with " << m->message_id << " in " << d->dialog_id; send_closure_later(G()->notification_manager(), &NotificationManager::add_notification, diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 51f6e26a..8ab43bcc 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -883,9 +883,10 @@ class MessagesManager : public Actor { MessageId max_added_message_id; NotificationGroupId message_notification_group_id; - int32 last_notification_date = 0; - NotificationId last_notification_id; - NotificationId max_removed_notification_id; + int32 last_notification_date = 0; // last known date of last notification in the dialog + NotificationId last_notification_id; // last known identifier of last notification in the dialog + NotificationId max_removed_notification_id; // notification identifier, up to which all notifications are removed + NotificationId first_new_notification_id; // identifier of first added notification in that library launch bool has_contact_registered_message = false;