Fix bookmarks VC sometimes going haywire

This commit is contained in:
Shadowfacts 2023-01-30 10:07:34 -05:00
parent 509acbde19
commit ebfd8b3efd
1 changed files with 6 additions and 1 deletions

View File

@ -219,6 +219,11 @@ class BookmarksViewController: UIViewController, CollectionViewController, Refre
} }
@objc private func managedObjectsDidChange(_ notification: Foundation.Notification) { @objc private func managedObjectsDidChange(_ notification: Foundation.Notification) {
// only perform local updates while the vc is idle
// otherwise loading the bookmarks ends up inserting them out of order
guard case .loaded = state else {
return
}
var snapshot = dataSource.snapshot() var snapshot = dataSource.snapshot()
func prepend(item: Item) { func prepend(item: Item) {
if let first = snapshot.itemIdentifiers.first { if let first = snapshot.itemIdentifiers.first {
@ -237,7 +242,7 @@ class BookmarksViewController: UIViewController, CollectionViewController, Refre
if let updated = notification.userInfo?[NSUpdatedObjectsKey] as? Set<NSManagedObject> { if let updated = notification.userInfo?[NSUpdatedObjectsKey] as? Set<NSManagedObject> {
for case let status as StatusMO in updated { for case let status as StatusMO in updated {
let item = Item.status(id: status.id, state: .unknown, addedLocally: true) let item = Item.status(id: status.id, state: .unknown, addedLocally: true)
var exists = snapshot.itemIdentifiers.contains(item) let exists = snapshot.itemIdentifiers.contains(item)
if status.bookmarked == true && !exists { if status.bookmarked == true && !exists {
prepend(item: item) prepend(item: item)
hasChanges = true hasChanges = true