From ebfd8b3efdb521d282e6814ddce5f14f548ec370 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 30 Jan 2023 10:07:34 -0500 Subject: [PATCH] Fix bookmarks VC sometimes going haywire --- Tusker/Screens/Bookmarks/BookmarksViewController.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Tusker/Screens/Bookmarks/BookmarksViewController.swift b/Tusker/Screens/Bookmarks/BookmarksViewController.swift index 76e8c06c69..cd77c8a0b3 100644 --- a/Tusker/Screens/Bookmarks/BookmarksViewController.swift +++ b/Tusker/Screens/Bookmarks/BookmarksViewController.swift @@ -219,6 +219,11 @@ class BookmarksViewController: UIViewController, CollectionViewController, Refre } @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() func prepend(item: Item) { if let first = snapshot.itemIdentifiers.first { @@ -237,7 +242,7 @@ class BookmarksViewController: UIViewController, CollectionViewController, Refre if let updated = notification.userInfo?[NSUpdatedObjectsKey] as? Set { for case let status as StatusMO in updated { 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 { prepend(item: item) hasChanges = true