Fix crash when TimelinePosition's center status ID isn't in the list of IDs

This commit is contained in:
Shadowfacts 2023-01-19 21:46:57 -05:00
parent c03fc86300
commit 468a559127
1 changed files with 3 additions and 2 deletions

View File

@ -432,8 +432,9 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
}
// update the timeline position in case some statuses couldn't be loaded
if let center = position.centerStatusID {
let nearestLoadedStatusToCenter = position.statusIDs[position.statusIDs.firstIndex(of: center)!...].first(where: { id in
if let center = position.centerStatusID,
let centerIndex = position.statusIDs.firstIndex(of: center) {
let nearestLoadedStatusToCenter = position.statusIDs[centerIndex...].first(where: { id in
// was already loaded or was just now loaded
!unloaded.contains(id) || statuses.contains(where: { $0.id == id })
})