From 2252b6d09ef5d82129d5c95938d4b11d7ec2ecd6 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Thu, 23 Feb 2023 10:02:05 -0500 Subject: [PATCH] Fix crash duplicate main status and crash when conversation context is preloaded For expand thread cells, the main status needs to be the one above the selected cell --- .../Conversation/ConversationCollectionViewController.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Tusker/Screens/Conversation/ConversationCollectionViewController.swift b/Tusker/Screens/Conversation/ConversationCollectionViewController.swift index f0274978..3431f273 100644 --- a/Tusker/Screens/Conversation/ConversationCollectionViewController.swift +++ b/Tusker/Screens/Conversation/ConversationCollectionViewController.swift @@ -336,8 +336,9 @@ extension ConversationCollectionViewController: UICollectionViewDelegate { selected(status: id, state: state.copy()) } case .expandThread(childThreads: let childThreads, inline: _): - if case .status(id: _, node: let node, state: let state, _, _) = dataSource.itemIdentifier(for: IndexPath(row: indexPath.row - 1, section: indexPath.section)) { - let tree = ConversationTree(ancestors: buildNewAncestors(above: indexPath), mainStatus: node) + let indexPathBeforeExpandThread = IndexPath(row: indexPath.row - 1, section: indexPath.section) + if case .status(id: _, node: let node, state: let state, _, _) = dataSource.itemIdentifier(for: indexPathBeforeExpandThread) { + let tree = ConversationTree(ancestors: buildNewAncestors(above: indexPathBeforeExpandThread), mainStatus: node) let conv = ConversationViewController(preloadedTree: tree, state: state.copy(), mastodonController: mastodonController) conv.statusIDToScrollToOnLoad = childThreads.first!.status.id conv.showStatusesAutomatically = showStatusesAutomatically