From 854d48e54e6e6266afddfd0af1dbdc178660200a Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 1 Jan 2023 14:49:04 -0500 Subject: [PATCH] Unique saved hashtag/instance items This may happen when migrating to iCloud, if the same hashtag is saved on multiple devices. --- Tusker/Screens/Explore/ExploreViewController.swift | 3 ++- Tusker/Screens/Main/MainSidebarViewController.swift | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Tusker/Screens/Explore/ExploreViewController.swift b/Tusker/Screens/Explore/ExploreViewController.swift index 1bd25407..c6064ba8 100644 --- a/Tusker/Screens/Explore/ExploreViewController.swift +++ b/Tusker/Screens/Explore/ExploreViewController.swift @@ -206,6 +206,7 @@ class ExploreViewController: UIViewController, UICollectionViewDelegate, Collect for followed in followed where !saved.contains(where: { $0.name == followed.name }) { items.append(.savedHashtag(Hashtag(name: followed.name, url: followed.url))) } + items = items.uniques() items.sort(using: SemiCaseSensitiveComparator.keyPath(\.label)) return items } @@ -215,7 +216,7 @@ class ExploreViewController: UIViewController, UICollectionViewDelegate, Collect let req = SavedInstance.fetchRequest(account: mastodonController.accountInfo!) req.sortDescriptors = [NSSortDescriptor(key: "url.host", ascending: true)] do { - return try mastodonController.persistentContainer.viewContext.fetch(req) + return try mastodonController.persistentContainer.viewContext.fetch(req).uniques() } catch { return [] } diff --git a/Tusker/Screens/Main/MainSidebarViewController.swift b/Tusker/Screens/Main/MainSidebarViewController.swift index 8ed0a829..dab7647d 100644 --- a/Tusker/Screens/Main/MainSidebarViewController.swift +++ b/Tusker/Screens/Main/MainSidebarViewController.swift @@ -240,6 +240,7 @@ class MainSidebarViewController: UIViewController { for followed in followed where !saved.contains(where: { $0.name == followed.name }) { items.append(.savedHashtag(Hashtag(name: followed.name, url: followed.url))) } + items = items.uniques() items.sort(using: SemiCaseSensitiveComparator.keyPath(\.title)) return items } @@ -249,7 +250,7 @@ class MainSidebarViewController: UIViewController { let req = SavedInstance.fetchRequest(account: mastodonController.accountInfo!) req.sortDescriptors = [NSSortDescriptor(key: "url.host", ascending: true)] do { - return try mastodonController.persistentContainer.viewContext.fetch(req) + return try mastodonController.persistentContainer.viewContext.fetch(req).uniques() } catch { return [] }