From a3e5b29cfc16a173f480a8f8f308af5bce9bada5 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Thu, 22 Dec 2022 17:57:17 -0500 Subject: [PATCH] Fix crash inserting present items when currentItems includes posts from since-unfollowed users --- .../Timeline/TimelineViewController.swift | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Tusker/Screens/Timeline/TimelineViewController.swift b/Tusker/Screens/Timeline/TimelineViewController.swift index 9a081ca4..46b7d157 100644 --- a/Tusker/Screens/Timeline/TimelineViewController.swift +++ b/Tusker/Screens/Timeline/TimelineViewController.swift @@ -467,9 +467,19 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro return } let currentItems = snapshot.itemIdentifiers(inSection: .statuses) - if case .status(id: let firstID, _, _) = currentItems.first, - // if there's no overlap between presentItems and the existing items in the data source, prompt the user - !presentItems.contains(firstID) { + 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 + // 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