From 21299c8eb86167f335a895c1903b5a8bf111a769 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 26 Nov 2022 17:33:07 -0500 Subject: [PATCH] Fix error when refreshing timeline with no items --- Tusker/Screens/Timeline/TimelineViewController.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Tusker/Screens/Timeline/TimelineViewController.swift b/Tusker/Screens/Timeline/TimelineViewController.swift index e6620bc7..8ca57ed8 100644 --- a/Tusker/Screens/Timeline/TimelineViewController.swift +++ b/Tusker/Screens/Timeline/TimelineViewController.swift @@ -315,7 +315,7 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro } else { // I'm not sure whether this should move into TimelineLikeController/TimelineLikeCollectionViewController let (_, presentItems) = await (controller.loadNewer(), try? loadInitial()) - if let presentItems { + if let presentItems, !presentItems.isEmpty { insertPresentItemsIfNecessary(presentItems) } } @@ -334,6 +334,9 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro private func insertPresentItemsIfNecessary(_ presentItems: [String]) { var snapshot = dataSource.snapshot() + guard snapshot.indexOfSection(.statuses) != nil else { + return + } let currentItems = snapshot.itemIdentifiers(inSection: .statuses) 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