From 46b455c3d1ff4ea8686501aed45e5b5a2e38b597 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 1 Apr 2024 21:52:47 -0400 Subject: [PATCH] Fix crash when there are multiple follow notifications for the same account Only reproducible on Pixelfed --- .../ActionNotificationGroupCollectionViewCell.swift | 8 +++++--- .../FollowNotificationGroupCollectionViewCell.swift | 6 +++++- .../NotificationsCollectionViewController.swift | 8 ++++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Tusker/Screens/Notifications/ActionNotificationGroupCollectionViewCell.swift b/Tusker/Screens/Notifications/ActionNotificationGroupCollectionViewCell.swift index 3573114c..3eb7c46c 100644 --- a/Tusker/Screens/Notifications/ActionNotificationGroupCollectionViewCell.swift +++ b/Tusker/Screens/Notifications/ActionNotificationGroupCollectionViewCell.swift @@ -135,9 +135,11 @@ class ActionNotificationGroupCollectionViewCell: UICollectionViewListCell { updateTimestamp() - let people = group.notifications.compactMap { - mastodonController.persistentContainer.account(for: $0.account.id) - } + let people = group.notifications + .uniques(by: \.account.id) + .compactMap { + mastodonController.persistentContainer.account(for: $0.account.id) + } let visibleAvatars = Array(people.lazy.compactMap(\.avatar).prefix(10)) for (index, avatarURL) in visibleAvatars.enumerated() { diff --git a/Tusker/Screens/Notifications/FollowNotificationGroupCollectionViewCell.swift b/Tusker/Screens/Notifications/FollowNotificationGroupCollectionViewCell.swift index d8013ff9..118ebf99 100644 --- a/Tusker/Screens/Notifications/FollowNotificationGroupCollectionViewCell.swift +++ b/Tusker/Screens/Notifications/FollowNotificationGroupCollectionViewCell.swift @@ -109,7 +109,11 @@ class FollowNotificationGroupCollectionViewCell: UICollectionViewListCell { } self.group = group - let people = group.notifications.compactMap { mastodonController.persistentContainer.account(for: $0.account.id) } + let people = group.notifications + .uniques(by: \.account.id) + .compactMap { + mastodonController.persistentContainer.account(for: $0.account.id) + } actionLabel.setEmojis(pairs: people.map { ($0.displayOrUserName, $0.emojis) diff --git a/Tusker/Screens/Notifications/NotificationsCollectionViewController.swift b/Tusker/Screens/Notifications/NotificationsCollectionViewController.swift index b9129385..14ac89c8 100644 --- a/Tusker/Screens/Notifications/NotificationsCollectionViewController.swift +++ b/Tusker/Screens/Notifications/NotificationsCollectionViewController.swift @@ -627,11 +627,11 @@ extension NotificationsCollectionViewController: UICollectionViewDelegate { case .favourite, .reblog: let type = group.kind == .favourite ? StatusActionAccountListViewController.ActionType.favorite : .reblog let statusID = group.notifications.first!.status!.id - let accountIDs = group.notifications.map(\.account.id) + let accountIDs = group.notifications.map(\.account.id).uniques() let vc = StatusActionAccountListViewController(actionType: type, statusID: statusID, statusState: .unknown, accountIDs: accountIDs, mastodonController: mastodonController) show(vc) case .follow: - let accountIDs = group.notifications.map(\.account.id) + let accountIDs = group.notifications.map(\.account.id).uniques() switch accountIDs.count { case 0: collectionView.deselectItem(at: indexPath, animated: true) @@ -670,11 +670,11 @@ extension NotificationsCollectionViewController: UICollectionViewDelegate { return UIContextMenuConfiguration(previewProvider: { let type = group.kind == .favourite ? StatusActionAccountListViewController.ActionType.favorite : .reblog let statusID = group.notifications.first!.status!.id - let accountIDs = group.notifications.map(\.account.id) + let accountIDs = group.notifications.map(\.account.id).uniques() return StatusActionAccountListViewController(actionType: type, statusID: statusID, statusState: .unknown, accountIDs: accountIDs, mastodonController: self.mastodonController) }) case .follow: - let accountIDs = group.notifications.map(\.account.id) + let accountIDs = group.notifications.map(\.account.id).uniques() return UIContextMenuConfiguration { if accountIDs.count == 1 { return ProfileViewController(accountID: accountIDs.first!, mastodonController: self.mastodonController)