Remove expired notifications before recalculating last_group_key.

GitOrigin-RevId: 31723b071ffe0ebb0432aa7427f4537c51434a05
This commit is contained in:
levlam 2019-12-30 00:20:25 +03:00
parent 1411f33725
commit 8e6623d3ea

View File

@ -621,6 +621,10 @@ void NotificationManager::add_notifications_to_group_begin(NotificationGroups::i
vector<Notification> notifications) { vector<Notification> notifications) {
CHECK(group_it != groups_.end()); CHECK(group_it != groups_.end());
td::remove_if(notifications, [dialog_id = group_it->first.dialog_id](const Notification &notification) {
return notification.type->get_notification_type_object(dialog_id) == nullptr;
});
if (notifications.empty()) { if (notifications.empty()) {
return; return;
} }
@ -676,11 +680,8 @@ void NotificationManager::add_notifications_to_group_begin(NotificationGroups::i
added_notifications.reserve(notifications.size()); added_notifications.reserve(notifications.size());
for (auto &notification : notifications) { for (auto &notification : notifications) {
added_notifications.push_back(get_notification_object(group_key.dialog_id, notification)); added_notifications.push_back(get_notification_object(group_key.dialog_id, notification));
if (added_notifications.back()->type_ == nullptr) { CHECK(added_notifications.back()->type_ != nullptr);
added_notifications.pop_back(); new_notifications.push_back(std::move(notification));
} else {
new_notifications.push_back(std::move(notification));
}
} }
notifications = std::move(new_notifications); notifications = std::move(new_notifications);
@ -1384,14 +1385,12 @@ bool NotificationManager::do_flush_pending_notifications(NotificationGroupKey &g
Notification notification(pending_notification.notification_id, pending_notification.date, Notification notification(pending_notification.notification_id, pending_notification.date,
pending_notification.initial_is_silent, std::move(pending_notification.type)); pending_notification.initial_is_silent, std::move(pending_notification.type));
added_notifications.push_back(get_notification_object(group_key.dialog_id, notification)); added_notifications.push_back(get_notification_object(group_key.dialog_id, notification));
if (added_notifications.back()->type_ == nullptr) { CHECK(added_notifications.back()->type_ != nullptr);
added_notifications.pop_back();
} else { if (!notification.type->can_be_delayed()) {
if (!notification.type->can_be_delayed()) { force_update = true;
force_update = true;
}
group.notifications.push_back(std::move(notification));
} }
group.notifications.push_back(std::move(notification));
} }
group.total_count += narrow_cast<int32>(added_notifications.size()); group.total_count += narrow_cast<int32>(added_notifications.size());
if (added_notifications.size() > max_notification_group_size_) { if (added_notifications.size() > max_notification_group_size_) {
@ -1477,6 +1476,11 @@ void NotificationManager::flush_pending_notifications(NotificationGroupId group_
return; return;
} }
td::remove_if(group_it->second.pending_notifications,
[dialog_id = group_it->first.dialog_id](const PendingNotification &pending_notification) {
return pending_notification.type->get_notification_type_object(dialog_id) == nullptr;
});
if (group_it->second.pending_notifications.empty()) { if (group_it->second.pending_notifications.empty()) {
return; return;
} }