From 37311e5f17ba136bb56425ffed30ad8ccab62bc9 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 28 Oct 2023 14:03:08 -0500 Subject: [PATCH] Fix potential crash due to race condition in timeline gap filling --- Tusker/Screens/Timeline/TimelineViewController.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Tusker/Screens/Timeline/TimelineViewController.swift b/Tusker/Screens/Timeline/TimelineViewController.swift index 2f7ec098..d28587c6 100644 --- a/Tusker/Screens/Timeline/TimelineViewController.swift +++ b/Tusker/Screens/Timeline/TimelineViewController.swift @@ -1166,7 +1166,10 @@ extension TimelineViewController { let addedItems: Bool let statusItems = snapshot.itemIdentifiers(inSection: .statuses) - let gapIndex = statusItems.firstIndex(of: .gap)! + guard let gapIndex = statusItems.firstIndex(of: .gap) else { + // Not sure how this is reachable (maybe the gap cell was tapped twice and the requests raced?) but w/e + return + } switch direction { case .above: @@ -1293,6 +1296,9 @@ extension TimelineViewController: UICollectionViewDelegate { selected(status: status.reblog?.id ?? id, state: collapseState.copy()) } case .gap: + guard controller.state == .idle else { + return + } let cell = collectionView.cellForItem(at: indexPath) as! TimelineGapCollectionViewCell cell.showsIndicator = true Task {