From 4249ab30ca415a422915a717e2486939c217efed Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 21 Aug 2024 14:10:59 -0400 Subject: [PATCH] Fix crash when hashtag search results include duplicate --- Tusker/Screens/Search/SearchResultsViewController.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Tusker/Screens/Search/SearchResultsViewController.swift b/Tusker/Screens/Search/SearchResultsViewController.swift index 9d22138afb..3c09653850 100644 --- a/Tusker/Screens/Search/SearchResultsViewController.swift +++ b/Tusker/Screens/Search/SearchResultsViewController.swift @@ -295,7 +295,10 @@ class SearchResultsViewController: UIViewController, CollectionViewController { } if !results.hashtags.isEmpty && resultTypes.contains(.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) { snapshot.appendSections([.statuses])