Fix inserting pinned items that already exist when refreshing profile

This commit is contained in:
Shadowfacts 2022-11-05 14:33:40 -04:00
parent 84cf755332
commit 999118798c
1 changed files with 11 additions and 1 deletions

View File

@ -222,7 +222,17 @@ class ProfileStatusesViewController: UIViewController, TimelineLikeCollectionVie
} }
var snapshot = dataSource.snapshot() 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) snapshot.appendItems(items, toSection: .pinned)
await apply(snapshot, animatingDifferences: true) await apply(snapshot, animatingDifferences: true)
} }