From 80645a089c5956bf106a52a9bf6154d6381d21c2 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 15 May 2023 23:42:56 -0400 Subject: [PATCH] Remove deleted statuses on notifications screen --- ...otificationsCollectionViewController.swift | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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