diff --git a/Mastodon/Protocol/Provider/DataSourceProvider+NotificationTableViewCellDelegate.swift b/Mastodon/Protocol/Provider/DataSourceProvider+NotificationTableViewCellDelegate.swift index 46b2e6801d..f513367282 100644 --- a/Mastodon/Protocol/Provider/DataSourceProvider+NotificationTableViewCellDelegate.swift +++ b/Mastodon/Protocol/Provider/DataSourceProvider+NotificationTableViewCellDelegate.swift @@ -120,6 +120,9 @@ extension NotificationTableViewCellDelegate where Self: DataSourceProvider & Aut notificationView: notificationView, query: .accept ) + if let self = self as? NotificationTimelineViewController { + self.didActOnFollowRequest(notification, approved: true) + } } } @@ -136,7 +139,7 @@ extension NotificationTableViewCellDelegate where Self: DataSourceProvider & Aut return } guard case let .notification(notification) = item else { - assertionFailure("only works for status data provider") + assertionFailure("only works for notification") return } @@ -146,6 +149,9 @@ extension NotificationTableViewCellDelegate where Self: DataSourceProvider & Aut notificationView: notificationView, query: .reject ) + if let self = self as? NotificationTimelineViewController { + self.didActOnFollowRequest(notification, approved: false) + } } } } diff --git a/Mastodon/Scene/Notification/NotificationTimeline/NotificationTimelineViewController.swift b/Mastodon/Scene/Notification/NotificationTimeline/NotificationTimelineViewController.swift index efab558130..cb18698ec1 100644 --- a/Mastodon/Scene/Notification/NotificationTimeline/NotificationTimelineViewController.swift +++ b/Mastodon/Scene/Notification/NotificationTimeline/NotificationTimelineViewController.swift @@ -47,6 +47,10 @@ class NotificationTimelineViewController: UIViewController, MediaPreviewableView } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } + + func didActOnFollowRequest(_ notification: MastodonNotification, approved: Bool) { + viewModel.didActOnFollowRequest(notification, approved: approved) + } } extension NotificationTimelineViewController { diff --git a/Mastodon/Scene/Notification/NotificationTimeline/NotificationTimelineViewModel.swift b/Mastodon/Scene/Notification/NotificationTimeline/NotificationTimelineViewModel.swift index 109c2cd715..f5e5574d0d 100644 --- a/Mastodon/Scene/Notification/NotificationTimeline/NotificationTimelineViewModel.swift +++ b/Mastodon/Scene/Notification/NotificationTimeline/NotificationTimelineViewModel.swift @@ -70,6 +70,21 @@ final class NotificationTimelineViewModel { await self.loadLatest() } } + + func didActOnFollowRequest(_ notification: MastodonNotification, approved: Bool) { + defer { + Task { + await loadLatest() + } + } + guard var currentSnapshot = diffableDataSource?.snapshot() else { return } + let identifier = NotificationListItem.notification(.notification(id: notification.id)) + if currentSnapshot.itemIdentifiers.contains(identifier) { + if !approved { + currentSnapshot.deleteItems([identifier]) + } + } + } } extension NotificationTimelineViewModel {