From 9af485b2be9958b701b04f3f22315a324de11844 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Fri, 20 Sep 2024 09:23:36 +0200 Subject: [PATCH] Correctly updated grouped notifications --- .../NotificationsViewModel.swift | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Packages/Notifications/Sources/Notifications/NotificationsViewModel.swift b/Packages/Notifications/Sources/Notifications/NotificationsViewModel.swift index ed129f63..481f1098 100644 --- a/Packages/Notifications/Sources/Notifications/NotificationsViewModel.swift +++ b/Packages/Notifications/Sources/Notifications/NotificationsViewModel.swift @@ -198,13 +198,21 @@ import SwiftUI if event.notification.isConsolidable(selectedType: selectedType), !consolidatedNotifications.isEmpty { - // If the notification type can be consolidated, try to consolidate with the latest row - let latestConsolidatedNotification = consolidatedNotifications.removeFirst() - await consolidatedNotifications.insert( - contentsOf: ([event.notification] + latestConsolidatedNotification.notifications) - .consolidated(selectedType: selectedType), - at: 0 - ) + if let index = consolidatedNotifications.firstIndex(where: { $0.type == event.notification.supportedType && $0.status?.id == event.notification.status?.id }) { + let latestConsolidatedNotification = consolidatedNotifications.remove(at: index) + await consolidatedNotifications.insert( + contentsOf: ([event.notification] + latestConsolidatedNotification.notifications) + .consolidated(selectedType: selectedType), + at: 0 + ) + } else { + let latestConsolidatedNotification = consolidatedNotifications.removeFirst() + await consolidatedNotifications.insert( + contentsOf: ([event.notification] + latestConsolidatedNotification.notifications) + .consolidated(selectedType: selectedType), + at: 0 + ) + } } else { // Otherwise, just insert the new notification await consolidatedNotifications.insert(