Unique saved hashtag/instance items

This may happen when migrating to iCloud, if the same hashtag is saved
on multiple devices.
This commit is contained in:
Shadowfacts 2023-01-01 14:49:04 -05:00
parent d4c560d7fc
commit 854d48e54e
2 changed files with 4 additions and 2 deletions

View File

@ -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 []
}

View File

@ -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 []
}