From 173ba39ad0f18ad2adb4b431388bd6d0ffd270e0 Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 24 Nov 2018 23:36:08 +0300 Subject: [PATCH] Flush groups in reverse order to not exceed max_notification_group_count_. GitOrigin-RevId: 8f1b03b389f7ef5b2b233591e6465ee13dc4fe5d --- td/telegram/NotificationManager.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index 3ceb1e3e..0cc1defc 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -714,13 +714,14 @@ void NotificationManager::edit_notification(NotificationGroupId group_id, Notifi notification.type = std::move(type); if (i + max_notification_group_size_ >= group.notifications.size()) { add_update_notification(group_it->first.group_id, group_it->first.dialog_id, notification); - return; } + return; } } for (auto ¬ification : group.pending_notifications) { if (notification.notification_id == notification_id) { notification.type = std::move(type); + return; } } } @@ -1104,15 +1105,20 @@ void NotificationManager::after_get_difference_impl() { } VLOG(notifications) << "After get difference"; - vector ready_group_ids; + vector ready_group_keys; for (auto &it : pending_updates_) { if (running_get_chat_difference_.count(it.first) == 0) { - ready_group_ids.push_back(it.first); + auto group_it = get_group(NotificationGroupId(it.first)); + CHECK(group_it != groups_.end()); + ready_group_keys.push_back(group_it->first); } } - for (auto group_id : ready_group_ids) { - flush_pending_updates_timeout_.cancel_timeout(group_id); - flush_pending_updates(group_id, "after_get_difference"); + + // flush groups in reverse order to not exceed max_notification_group_count_ + std::sort(ready_group_keys.begin(), ready_group_keys.end()); + for (auto group_key : reversed(ready_group_keys)) { + flush_pending_updates_timeout_.cancel_timeout(group_key.group_id.get()); + flush_pending_updates(group_key.group_id.get(), "after_get_difference"); } }