Fix crash inserting present items when currentItems includes posts from since-unfollowed users

This commit is contained in:
Shadowfacts 2022-12-22 17:57:17 -05:00
parent 46cecde014
commit a3e5b29cfc
1 changed files with 13 additions and 3 deletions

View File

@ -467,9 +467,19 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
return
}
let currentItems = snapshot.itemIdentifiers(inSection: .statuses)
if case .status(id: let firstID, _, _) = currentItems.first,
func currentItemsContains(id: String) -> Bool {
return currentItems.contains { item in
switch item {
case .status(id: id, collapseState: _, filterState: _):
return true
default:
return false
}
}
}
// if there's no overlap between presentItems and the existing items in the data source, prompt the user
!presentItems.contains(firstID) {
// we can't be clever here by just checking the first id in currentItems against presentItems, since that may belong to a since-unfollowed user
if !presentItems.contains(where: { currentItemsContains(id: $0) }) {
let applySnapshotBeforeScrolling: Bool
// remove any existing gap, if there is one