Fix crash when hashtag search results include duplicate

This commit is contained in:
Shadowfacts 2024-08-21 14:10:59 -04:00
parent 9891b601a8
commit 4249ab30ca
1 changed files with 4 additions and 1 deletions

View File

@ -295,7 +295,10 @@ class SearchResultsViewController: UIViewController, CollectionViewController {
} }
if !results.hashtags.isEmpty && resultTypes.contains(.hashtags) { if !results.hashtags.isEmpty && resultTypes.contains(.hashtags) {
snapshot.appendSections([.hashtags]) snapshot.appendSections([.hashtags])
snapshot.appendItems(results.hashtags.map { .hashtag($0) }, toSection: .hashtags) // mastodon sometimes includes duplicate hashtags with the same name but different urls
// (e.g., containing %C3%B8 vs o)
let uniqueHashtags = results.hashtags.uniques(by: \.name)
snapshot.appendItems(uniqueHashtags.map { .hashtag($0) }, toSection: .hashtags)
} }
if !results.statuses.isEmpty && resultTypes.contains(.statuses) { if !results.statuses.isEmpty && resultTypes.contains(.statuses) {
snapshot.appendSections([.statuses]) snapshot.appendSections([.statuses])