Skip to content

Commit

Permalink
Update notification view after approving or rejecting a follow request
Browse files Browse the repository at this point in the history
Fixes #1342 [BUG] Follow requests no longer working
  • Loading branch information
whattherestimefor committed Jan 22, 2025
1 parent 76283cf commit e91d6e3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand All @@ -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
}

Expand All @@ -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)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e91d6e3

Please sign in to comment.