From 999118798c01976725aa674920b6d882cfcaa2c0 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 5 Nov 2022 14:33:40 -0400 Subject: [PATCH] Fix inserting pinned items that already exist when refreshing profile --- .../Profile/ProfileStatusesViewController.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Tusker/Screens/Profile/ProfileStatusesViewController.swift b/Tusker/Screens/Profile/ProfileStatusesViewController.swift index de377ebd..4a6d49e8 100644 --- a/Tusker/Screens/Profile/ProfileStatusesViewController.swift +++ b/Tusker/Screens/Profile/ProfileStatusesViewController.swift @@ -222,7 +222,17 @@ class ProfileStatusesViewController: UIViewController, TimelineLikeCollectionVie } var snapshot = dataSource.snapshot() - let items = statuses.map { Item.status(id: $0.id, state: .unknown, pinned: true) } + let existingPinned = snapshot.itemIdentifiers(inSection: .pinned) + let items = statuses.map { + let item = Item.status(id: $0.id, state: .unknown, pinned: true) + // try to keep the existing status state + if let existing = existingPinned.first(where: { $0 == item }) { + return existing + } else { + return item + } + } + snapshot.deleteItems(snapshot.itemIdentifiers(inSection: .pinned)) snapshot.appendItems(items, toSection: .pinned) await apply(snapshot, animatingDifferences: true) }