diff --git a/Tusker/Screens/Notifications/NotificationsCollectionViewController.swift b/Tusker/Screens/Notifications/NotificationsCollectionViewController.swift index 963aa701..55630544 100644 --- a/Tusker/Screens/Notifications/NotificationsCollectionViewController.swift +++ b/Tusker/Screens/Notifications/NotificationsCollectionViewController.swift @@ -120,6 +120,8 @@ class NotificationsCollectionViewController: UIViewController, TimelineLikeColle filterer.filtersChanged = { [unowned self] actionsChanged in self.reapplyFilters(actionsChanged: actionsChanged) } + + NotificationCenter.default.addObserver(self, selector: #selector(handleStatusDeleted), name: .statusDeleted, object: nil) } private func createDataSource() -> UICollectionViewDiffableDataSource { @@ -253,6 +255,24 @@ class NotificationsCollectionViewController: UIViewController, TimelineLikeColle dataSource.apply(snapshot) } + @objc private func handleStatusDeleted(_ notification: Foundation.Notification) { + guard let userInfo = notification.userInfo, + let accountID = mastodonController.accountInfo?.id, + userInfo["accountID"] as? String == accountID, + let statusIDs = userInfo["statusIDs"] as? [String] else { + return + } + var snapshot = dataSource.snapshot() + let items = snapshot.itemIdentifiers(inSection: .notifications) + let toDelete = statusIDs.flatMap { id in + items.lazy.filter { $0.group?.notifications.first?.status?.id == id } + } + if !toDelete.isEmpty { + snapshot.deleteItems(toDelete) + dataSource.apply(snapshot, animatingDifferences: true) + } + } + private func dismissNotificationsInGroup(at indexPath: IndexPath) async { guard case .group(let group, let collapseState, let filterState) = dataSource.itemIdentifier(for: indexPath) else { return