From e3e55de55b512ad2a2818f15acacc7603d2a7d0b Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 4 Dec 2022 12:11:52 -0500 Subject: [PATCH] Fix hide filter action not working on profiles --- Tusker/Filterer.swift | 9 +++++++++ .../Profile/ProfileStatusesViewController.swift | 16 +++++++++++++--- .../Timeline/TimelineViewController.swift | 5 ++--- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Tusker/Filterer.swift b/Tusker/Filterer.swift index 10fa3ff9..55bcee00 100644 --- a/Tusker/Filterer.swift +++ b/Tusker/Filterer.swift @@ -131,6 +131,15 @@ class Filterer { state.state = .known(result, generation: generation) } + func isKnownHide(state: FilterState) -> Bool { + switch state.state { + case .known(.hide, generation: let gen) where gen >= generation: + return true + default: + return false + } + } + private func doResolve(status: StatusMO) -> (Result, NSAttributedString?) { if !hasSetup { setupFilters(filters: mastodonController.filters) diff --git a/Tusker/Screens/Profile/ProfileStatusesViewController.swift b/Tusker/Screens/Profile/ProfileStatusesViewController.swift index 225a9aec..550e31ac 100644 --- a/Tusker/Screens/Profile/ProfileStatusesViewController.swift +++ b/Tusker/Screens/Profile/ProfileStatusesViewController.swift @@ -70,8 +70,11 @@ class ProfileStatusesViewController: UIViewController, TimelineLikeCollectionVie if item.hideSeparators { config.topSeparatorVisibility = .hidden config.bottomSeparatorVisibility = .hidden - } - if case .status(_, _, _, _) = item { + } else if case .status(id: _, collapseState: _, filterState: let filterState, pinned: _) = item, + filterer.isKnownHide(state: filterState) { + config.topSeparatorVisibility = .hidden + config.bottomSeparatorVisibility = .hidden + } else if case .status(_, _, _, _) = item { config.topSeparatorInsets = TimelineStatusCollectionViewCell.separatorInsets config.bottomSeparatorInsets = TimelineStatusCollectionViewCell.separatorInsets } @@ -123,6 +126,8 @@ class ProfileStatusesViewController: UIViewController, TimelineLikeCollectionVie cell.showPinned = item.4 cell.updateUI(statusID: item.0, state: item.1, filterResult: item.2, precomputedContent: item.3) } + let zeroHeightCell = UICollectionView.CellRegistration { _, _, _ in + } return UICollectionViewDiffableDataSource(collectionView: collectionView) { [unowned self] collectionView, indexPath, itemIdentifier in switch itemIdentifier { case .header(let id): @@ -149,7 +154,12 @@ class ProfileStatusesViewController: UIViewController, TimelineLikeCollectionVie } case .status(id: let id, collapseState: let collapseState, filterState: let filterState, pinned: let pinned): let (result, precomputedContent) = filterResult(state: filterState, statusID: id) - return collectionView.dequeueConfiguredReusableCell(using: statusCell, for: indexPath, item: (id, collapseState, result, precomputedContent, pinned)) + switch result { + case .allow, .warn(_): + return collectionView.dequeueConfiguredReusableCell(using: statusCell, for: indexPath, item: (id, collapseState, result, precomputedContent, pinned)) + case .hide: + return collectionView.dequeueConfiguredReusableCell(using: zeroHeightCell, for: indexPath, item: ()) + } case .loadingIndicator: return loadingIndicatorCell(for: indexPath) case .confirmLoadMore: diff --git a/Tusker/Screens/Timeline/TimelineViewController.swift b/Tusker/Screens/Timeline/TimelineViewController.swift index 5a0f54b0..4569b625 100644 --- a/Tusker/Screens/Timeline/TimelineViewController.swift +++ b/Tusker/Screens/Timeline/TimelineViewController.swift @@ -70,9 +70,8 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro if item.hideSeparators { config.topSeparatorVisibility = .hidden config.bottomSeparatorVisibility = .hidden - } else if case .status(id: let id, collapseState: _, filterState: let filterState) = item, - case (.hide, _) = filterResult(state: filterState, statusID: id) { - // this runs after the cell is setup, so the filter state is already known and this check is cheap + } else if case .status(id: _, collapseState: _, filterState: let filterState) = item, + filterer.isKnownHide(state: filterState) { config.topSeparatorVisibility = .hidden config.bottomSeparatorVisibility = .hidden } else {