Fix error when refreshing timeline with no items

This commit is contained in:
Shadowfacts 2022-11-26 17:33:07 -05:00
parent 527706154a
commit 21299c8eb8
1 changed files with 4 additions and 1 deletions

View File

@ -315,7 +315,7 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
} else { } else {
// I'm not sure whether this should move into TimelineLikeController/TimelineLikeCollectionViewController // I'm not sure whether this should move into TimelineLikeController/TimelineLikeCollectionViewController
let (_, presentItems) = await (controller.loadNewer(), try? loadInitial()) let (_, presentItems) = await (controller.loadNewer(), try? loadInitial())
if let presentItems { if let presentItems, !presentItems.isEmpty {
insertPresentItemsIfNecessary(presentItems) insertPresentItemsIfNecessary(presentItems)
} }
} }
@ -334,6 +334,9 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
private func insertPresentItemsIfNecessary(_ presentItems: [String]) { private func insertPresentItemsIfNecessary(_ presentItems: [String]) {
var snapshot = dataSource.snapshot() var snapshot = dataSource.snapshot()
guard snapshot.indexOfSection(.statuses) != nil else {
return
}
let currentItems = snapshot.itemIdentifiers(inSection: .statuses) let currentItems = snapshot.itemIdentifiers(inSection: .statuses)
if case .status(id: let firstID, state: _) = currentItems.first, if case .status(id: let firstID, state: _) = currentItems.first,
// if there's no overlap between presentItems and the existing items in the data source, insert the present items and prompt the user // if there's no overlap between presentItems and the existing items in the data source, insert the present items and prompt the user