From 1e47fb8dbeb373d20fbb0cdd50b8d1f8cc7d84ac Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 30 Sep 2026 20:32:42 -0700 Subject: [PATCH] Use curly single quote instead of foot mark in comments. --- .../MainFeedCollectionViewController.swift | 14 +- .../MainTimelineModernViewController.swift | 21 +-- iOS/SceneCoordinator.swift | 153 +++++++++++++----- 3 files changed, 128 insertions(+), 60 deletions(-) diff --git a/iOS/MainFeed/MainFeedCollectionViewController.swift b/iOS/MainFeed/MainFeedCollectionViewController.swift index 6aef9e76e..bd8150880 100644 --- a/iOS/MainFeed/MainFeedCollectionViewController.swift +++ b/iOS/MainFeed/MainFeedCollectionViewController.swift @@ -38,7 +38,7 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab private let keyboardManager = KeyboardManager(type: .sidebar) override var keyCommands: [UIKeyCommand]? { - // If the first responder is the WKWebView (PreloadedWebView) we don't want to supply any keyboard + // If the first responder is the WKWebView (PreloadedWebView) we don’t want to supply any keyboard // commands that the system is looking for by going up the responder chain. They will interfere with // the WKWebViews built in hardware keyboard shortcuts, specifically the up and down arrow keys. guard let current = UIResponder.currentFirstResponder, !(current is PreloadedWebView) else { @@ -427,7 +427,7 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab completions.append(completion) } - // A newer full snapshot supersedes a queued one. The superseded update's + // A newer full snapshot supersedes a queued one. The superseded update’s // completions still run — after a snapshot at least as new as the one they requested. if update.isFull, let index = queuedSidebarUpdates.firstIndex(where: { $0.update.isFull }) { completions = queuedSidebarUpdates[index].completions + completions @@ -517,7 +517,7 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab becomeFirstResponder() } - // Fires on every tap — even on the already-selected feed, which doesn't get didSelectItemAt. + // Fires on every tap — even on the already-selected feed, which doesn’t get didSelectItemAt. override func collectionView(_ collectionView: UICollectionView, performPrimaryActionForItemAt indexPath: IndexPath) { becomeFirstResponder() coordinator.selectSidebarItem(indexPath: indexPath, animations: [.navigation, .select, .scroll]) @@ -939,7 +939,7 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab @objc func refreshAccounts(_ sender: Any) { collectionView.refreshControl?.endRefreshing() - // This is a hack to make sure that an error dialog doesn't interfere with dismissing the refreshControl. + // This is a hack to make sure that an error dialog doesn’t interfere with dismissing the refreshControl. // If the error dialog appears too closely to the call to endRefreshing, then the refreshControl never disappears. DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { appDelegate.manualRefresh(errorHandler: ErrorHandler.present(self)) @@ -1269,7 +1269,7 @@ extension MainFeedCollectionViewController { let action = UIAlertAction(title: title, style: .default) { [weak self] _ in MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView, cancelCompletion: cancel) { [weak self] in - self?.coordinator.markAllAsRead(Array(articles)) + self?.coordinator.markAllAsRead(Array(articles), in: feed) completion(true) } } @@ -1354,7 +1354,7 @@ extension MainFeedCollectionViewController { let action = UIAction(title: title, image: Assets.Images.markAllAsRead) { [weak self] _ in MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView) { [weak self] in let articles = sidebarItem.fetchUnreadArticles() - self?.coordinator.markAllAsRead(Array(articles)) + self?.coordinator.markAllAsRead(Array(articles), in: sidebarItem) } } @@ -1370,7 +1370,7 @@ extension MainFeedCollectionViewController { let title = NSString.localizedStringWithFormat(localizedMenuText as NSString, account.nameForDisplay) as String let action = UIAction(title: title, image: Assets.Images.markAllAsRead) { [weak self] _ in MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView) { [weak self] in - // If you don't have this delay the screen flashes when it executes this code + // If you don’t have this delay the screen flashes when it executes this code DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { let articles = account.fetchArticles(.unread()) self?.coordinator.markAllAsRead(Array(articles)) diff --git a/iOS/MainTimeline/MainTimelineModernViewController.swift b/iOS/MainTimeline/MainTimelineModernViewController.swift index 46a18bcee..b85c702db 100644 --- a/iOS/MainTimeline/MainTimelineModernViewController.swift +++ b/iOS/MainTimeline/MainTimelineModernViewController.swift @@ -136,7 +136,7 @@ final class MainTimelineModernViewController: UIViewController, UndoableCommandR weak var coordinator: SceneCoordinator? var undoableCommands = [UndoableCommand]() override var keyCommands: [UIKeyCommand]? { - // If the first responder is the WKWebView (PreloadedWebView) we don't want to supply any keyboard + // If the first responder is the WKWebView (PreloadedWebView) we don’t want to supply any keyboard // commands that the system is looking for by going up the responder chain. They will interfere with // the WKWebViews built in hardware keyboard shortcuts, specifically the up and down arrow keys. guard let current = UIResponder.currentFirstResponder, !(current is PreloadedWebView) else { return nil } @@ -230,6 +230,9 @@ final class MainTimelineModernViewController: UIViewController, UndoableCommandR updateNavigationBarTitle(coordinator?.timelineFeed?.nameForDisplay ?? "") coordinator?.updateNavigationBarSubtitles(nil) updateToolbarProgressView() + + // Articles can change while this view is off screen, so always show what the model holds. + applyChanges(animated: false) } override func viewDidAppear(_ animated: Bool) { @@ -420,7 +423,7 @@ final class MainTimelineModernViewController: UIViewController, UndoableCommandR @objc func refreshAccounts(_ sender: Any) { collectionView?.refreshControl?.endRefreshing() - // This is a hack to make sure that an error dialog doesn't interfere with dismissing the refreshControl. + // This is a hack to make sure that an error dialog doesn’t interfere with dismissing the refreshControl. // If the error dialog appears too closely to the call to endRefreshing, then the refreshControl never disappears. DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { appDelegate.manualRefresh(errorHandler: ErrorHandler.present(self)) @@ -730,7 +733,7 @@ private extension MainTimelineModernViewController { let starAction = UIContextualAction(style: .normal, title: starTitle) { [weak self] _, _, completion in // Post the accessibility announcement immediately so VoiceOver - // doesn't lag behind user actions. + // doesn’t lag behind user actions. let announcement = article.status.starred ? NSLocalizedString("Unstarred", comment: "Accessibility announcement") : NSLocalizedString("Starred", comment: "Starred") @@ -739,7 +742,7 @@ private extension MainTimelineModernViewController { /// The call to `toggleStar` is delayed in order to allow /// the swipe animation to complete. Calling `toggleStar` with no /// delay results UICollectionView internal inconsistency: unexpected - /// removal of the current swipe occurrence's mask view error. + /// removal of the current swipe occurrence’s mask view error. DispatchQueue.main.asyncAfter(deadline: .now() + 0.85) { self?.toggleStar(article) } @@ -824,7 +827,7 @@ private extension MainTimelineModernViewController { let readAction = UIContextualAction(style: .normal, title: readTitle) { [weak self] _, _, completion in // Post the accessibility announcement immediately so VoiceOver - // doesn't lag behind user actions. + // doesn’t lag behind user actions. let announcement = article.status.read ? NSLocalizedString("Marked as Unread", comment: "Accessibility announcement") : NSLocalizedString("Marked as Read", comment: "Accessibility announcement") @@ -833,7 +836,7 @@ private extension MainTimelineModernViewController { /// The call to `toggleRead` is delayed in order to allow /// the swipe animation to complete. Calling `toggleRead` with no /// delay results UICollectionView internal inconsistency: unexpected - /// removal of the current swipe occurrence's mask view error. + /// removal of the current swipe occurrence’s mask view error. DispatchQueue.main.asyncAfter(wallDeadline: .now() + 0.85) { self?.toggleRead(article) } @@ -1162,7 +1165,7 @@ extension MainTimelineModernViewController { let action = UIAction(title: title, image: image) { [weak self] _ in // Post the accessibility announcement immediately so VoiceOver - // doesn't lag behind user actions. + // doesn’t lag behind user actions. let announcement = article.status.read ? NSLocalizedString("Marked as Unread", comment: "Accessibility announcement") : NSLocalizedString("Marked as Read", comment: "Accessibility announcement") @@ -1190,7 +1193,7 @@ extension MainTimelineModernViewController { let action = UIAction(title: title, image: image) { [weak self] _ in // Post the accessibility announcement immediately so VoiceOver - // doesn't lag behind user actions. + // doesn’t lag behind user actions. let announcement = article.status.starred ? NSLocalizedString("Unstarred", comment: "Accessibility announcement") : NSLocalizedString("Starred", comment: "Starred") @@ -1327,7 +1330,7 @@ extension MainTimelineModernViewController { func markAllAsRead(_ articles: ArticleArray) { assert(coordinator != nil) - coordinator?.markAllAsRead(articles) + coordinator?.markAllAsReadInTimeline(articles) } func markAllInFeedAsReadAction(_ article: Article, indexPath: IndexPath) -> UIAction? { diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 701a8297f..be96f6811 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -129,7 +129,7 @@ struct SidebarItemNode: Hashable, Sendable { return rootSplitViewController.isCollapsed } - // In collapsed mode, the article view is in the window only while it's on top of the navigation stack. + // In collapsed mode, the article view is in the window only while it’s on top of the navigation stack. var isArticleViewControllerShowing: Bool { articleViewController?.viewIfLoaded?.window != nil } @@ -430,7 +430,7 @@ struct SidebarItemNode: Hashable, Sendable { rebuildBackingStores(initialLoad: true) - // You can't assign the Feeds Read Filter until we've built the backing stores at least once or there is nothing + // You can’t assign the Feeds Read Filter until we’ve built the backing stores at least once or there is nothing // for state restoration to work with while we are waiting for the unread counts to initialize. treeControllerDelegate.isReadFiltered = stateInfo.hideReadFeeds @@ -484,7 +484,7 @@ struct SidebarItemNode: Hashable, Sendable { return } - // Add Feed just presents a sheet — unlike the activities below, it doesn't navigate, + // Add Feed just presents a sheet — unlike the activities below, it doesn’t navigate, // so it must not clear the current selection. // if activityType == .addFeedIntent { @@ -671,7 +671,7 @@ struct SidebarItemNode: Hashable, Sendable { } @objc func willEnterForeground(_ note: Notification) { - // Don't interfere with any fetch requests that we may have initiated before the app was returned to the foreground. + // Don’t interfere with any fetch requests that we may have initiated before the app was returned to the foreground. // For example if you select Next Unread from the Home Screen Quick actions, you can start a request before we are // in the foreground. if !fetchRequestQueue.isAnyCurrentRequest { @@ -716,7 +716,7 @@ struct SidebarItemNode: Hashable, Sendable { /// - Where the unread count for the timeline is > 0, this is displayed on both iPhone and iPad. /// - If the timeline count is 0, the iPhone follows the same logic as `MainFeedViewController` /// - Specific to iPad, if the unread count is 0, the iPad will not display a subtitle. The refresh text - /// will generally be visible in the sidebar and there's no need to display it twice. + /// will generally be visible in the sidebar and there’s no need to display it twice. /// /// - Parameter note: Optional `Notification` @objc func updateNavigationBarSubtitles(_ note: Notification?) { @@ -866,11 +866,54 @@ struct SidebarItemNode: Hashable, Sendable { if isReadFeedsFiltered { rebuildBackingStores() } - if isReadArticlesFiltered && (AppDefaults.shared.refreshClearsReadArticles || !conditional) { - refreshTimeline(resetScroll: false) + if AppDefaults.shared.refreshClearsReadArticles || !conditional { + removeArticlesHiddenByReadFilter() } } + func removeArticlesHiddenByReadFilter() { + removeReadArticles { _ in true } + } + + // Marking one feed read shouldn’t make another feed’s already-read rows disappear. + func removeArticlesHiddenByReadFilter(among articleIDs: Set) { + removeReadArticles { articleIDs.contains($0.articleID) } + } + + // Cleanup dropped these articles, so fetching is the only way to get the rows back. + func restoreArticlesToTimeline() { + guard isReadArticlesFiltered else { + return + } + + queueFetchAndMergeArticles() + } + + private func removeReadArticles(where isEligible: @escaping (Article) -> Bool) { + let sidebarItemID = timelineFeed?.sidebarItemID + + // A snapshot applied during a UIKit transition gets dropped, so wait it out. + Task { @MainActor in + // If the timeline moved on while we waited, it’s not the one the user acted on. + guard sidebarItemID == self.timelineFeed?.sidebarItemID, self.isReadArticlesFiltered else { + return + } + + // Keep the open article — don’t pull the row out from under what the user is reading. + let remainingArticles = self.articles.filter { article in + !article.status.read || !isEligible(article) || self.isCurrentArticle(article) + } + self.replaceArticles(with: remainingArticles, animated: true) + } + } + + private func isCurrentArticle(_ article: Article) -> Bool { + guard let currentArticle else { + return false + } + return article.articleID == currentArticle.articleID && article.accountID == currentArticle.accountID + } + func toggleReadFeedsFilter() { Self.logger.debug("SceneCoordinator: toggleReadFeedsFilter") @@ -919,7 +962,7 @@ struct SidebarItemNode: Hashable, Sendable { } func articleFor(_ articleID: String) -> Article? { - // Check if it's the currently displayed article + // Check if it’s the currently displayed article if let currentArticle, currentArticle.articleID == articleID { return currentArticle } @@ -939,9 +982,6 @@ struct SidebarItemNode: Hashable, Sendable { } func refreshTimeline(resetScroll: Bool) { - if let article = self.currentArticle, let account = article.account { - exceptionArticleFetcher = SingleArticleFetcher(account: account, articleID: article.articleID) - } fetchAndReplaceArticlesAsync(animated: true, emptyFirst: false) { self.mainTimelineViewController?.reinitializeArticles(resetScroll: resetScroll) } @@ -1252,8 +1292,8 @@ struct SidebarItemNode: Hashable, Sendable { func selectPrevUnread() { - // This should never happen, but I don't want to risk throwing us - // into an infinite loop searching for an unread that isn't there. + // This should never happen, but I don’t want to risk throwing us + // into an infinite loop searching for an unread that isn’t there. if AccountManager.shared.unreadCount < 1 { return } @@ -1263,7 +1303,7 @@ struct SidebarItemNode: Hashable, Sendable { } // Disable navigation only while hopping to another feed, so the intermediate - // timeline isn't pushed. Selecting within the current timeline must be able to + // timeline isn’t pushed. Selecting within the current timeline must be able to // push the article view controller. isNavigationDisabled = true defer { @@ -1279,8 +1319,8 @@ struct SidebarItemNode: Hashable, Sendable { // Flush coalesced unread-count updates so folder counts are current. CoalescingQueue.standard.performCallsImmediately() - // This should never happen, but I don't want to risk throwing us - // into an infinite loop searching for an unread that isn't there. + // This should never happen, but I don’t want to risk throwing us + // into an infinite loop searching for an unread that isn’t there. if AccountManager.shared.unreadCount < 1 { return } @@ -1290,7 +1330,7 @@ struct SidebarItemNode: Hashable, Sendable { } // Disable navigation only while hopping to another feed, so the intermediate - // timeline isn't pushed. Selecting within the current timeline must be able to + // timeline isn’t pushed. Selecting within the current timeline must be able to // push the article view controller. isNavigationDisabled = true defer { @@ -1335,8 +1375,30 @@ struct SidebarItemNode: Hashable, Sendable { markArticlesWithUndo(articles, statusKey: .read, flag: true, completion: completion) } + // The marked articles are in the timeline. Remove them. Undo brings them back. + func markAllAsReadInTimeline(_ articlesToMark: [Article], completion: (() -> Void)? = nil) { + let articleIDs = Set(articlesToMark.articleIDs()) + + markArticlesWithUndo(articlesToMark, statusKey: .read, flag: true, completion: completion) { [weak self] markedAsRead in + if markedAsRead { + self?.removeArticlesHiddenByReadFilter(among: articleIDs) + } else { + self?.restoreArticlesToTimeline() + } + } + } + + // From the sidebar: clean up only when the marked item is the one the timeline is showing. + func markAllAsRead(_ articlesToMark: [Article], in sidebarItem: SidebarItem, completion: (() -> Void)? = nil) { + if sidebarItem.sidebarItemID == timelineFeed?.sidebarItemID { + markAllAsReadInTimeline(articlesToMark, completion: completion) + } else { + markAllAsRead(articlesToMark, completion: completion) + } + } + func markAsReadAndShowSidebar(_ articlesToMark: [Article], completion: (() -> Void)? = nil) { - markAllAsRead(articlesToMark) { + markAllAsReadInTimeline(articlesToMark) { self.rootSplitViewController.preferredDisplayMode = .twoBesideSecondary self.rootSplitViewController.showColumn(.primary, bypassDisplayModeRestriction: true) completion?() @@ -1358,7 +1420,7 @@ struct SidebarItemNode: Hashable, Sendable { func markAboveAsRead(_ article: Article) { let articlesAboveArray = articles.articlesAbove(article: article) - markAllAsRead(articlesAboveArray) + markAllAsReadInTimeline(articlesAboveArray) } func canMarkBelowAsRead(for article: Article) -> Bool { @@ -1376,7 +1438,7 @@ struct SidebarItemNode: Hashable, Sendable { func markBelowAsRead(_ article: Article) { let articleBelowArray = articles.articlesBelow(article: article) - markAllAsRead(articleBelowArray) + markAllAsReadInTimeline(articleBelowArray) } func markAsReadForCurrentArticle() { @@ -1766,10 +1828,10 @@ extension SceneCoordinator: UINavigationControllerDelegate { } // If we are using a phone and navigate away from the detail, clear up the article resources (including activity). - // Don't clear it if we have pushed an ArticleViewController, but don't yet see it on the navigation stack. + // Don’t clear it if we have pushed an ArticleViewController, but don’t yet see it on the navigation stack. // This happens when we are going to the next unread and we need to grab another timeline to continue. The - // ArticleViewController will be pushed, but we will briefly show the Timeline. Don't clear things out when that happens. - // Also skip during state restoration so we don't clear the restored article. + // ArticleViewController will be pushed, but we will briefly show the Timeline. Don’t clear things out when that happens. + // Also skip during state restoration so we don’t clear the restored article. if viewController === mainTimelineViewController && rootSplitViewController.isCollapsed && !isArticleViewControllerPending && !isRestoringState { currentArticle = nil mainTimelineViewController?.updateArticleSelection(animations: [.scroll, .select, .navigation]) @@ -1790,7 +1852,7 @@ extension SceneCoordinator: UINavigationControllerDelegate { private extension SceneCoordinator { // Reveal the destination column, then focus it. Works across collapsed (iPhone), - // two-pane, and three-pane layouts, so arrow-key navigation isn't limited to the + // two-pane, and three-pane layouts, so arrow-key navigation isn’t limited to the // case where all columns are already visible. // func revealColumn(_ column: UISplitViewController.Column, thenFocus focus: @escaping @MainActor () -> Void) { @@ -1831,7 +1893,7 @@ private extension SceneCoordinator { } } else if navController.viewControllers.contains(targetViewController) { // Backward navigation. The pop fires navigationController(_:didShow:), which performs - // the existing collapsed-mode cleanup. Don't duplicate that here. + // the existing collapsed-mode cleanup. Don’t duplicate that here. navController.popToViewController(targetViewController, animated: true) focusWhenTransitionCompletes(in: navController, thenFocus: focus) } else { @@ -1855,9 +1917,9 @@ private extension SceneCoordinator { } } - func markArticlesWithUndo(_ articles: [Article], statusKey: ArticleStatus.Key, flag: Bool, completion: (() -> Void)? = nil) { + func markArticlesWithUndo(_ articles: [Article], statusKey: ArticleStatus.Key, flag: Bool, completion: (() -> Void)? = nil, didMark: ((Bool) -> Void)? = nil) { guard let undoManager = undoManager, - let markReadCommand = MarkStatusCommand(initialArticles: articles, statusKey: statusKey, flag: flag, undoManager: undoManager, completion: completion) else { + let markReadCommand = MarkStatusCommand(initialArticles: articles, statusKey: statusKey, flag: flag, undoManager: undoManager, completion: completion, didMark: didMark) else { completion?() return } @@ -1871,7 +1933,9 @@ private extension SceneCoordinator { count += 1 } } - timelineUnreadCount = count + if count != timelineUnreadCount { + timelineUnreadCount = count + } } func rebuildArticleDictionaries() { @@ -2379,25 +2443,23 @@ private extension SceneCoordinator { replaceArticles(with: sortedArticles, animated: animated) } + // Always tells the timeline, even when the articles look unchanged — a matching model + // doesn’t mean the displayed rows match. func replaceArticles(with sortedArticles: ArticleArray, animated: Bool) { - if articles != sortedArticles { - articles = sortedArticles + articles = sortedArticles - // Update currentArticle to the new instance if it's still in the timeline. - // If the article is no longer in the timeline, keep showing it anyway - - // don't blank the user's screen just because the article filtered out. - // Skip during state restoration so the restored article stays open. - if !isRestoringState, let currentArticle { - if let newArticle = sortedArticles.first(where: { $0.articleID == currentArticle.articleID && $0.accountID == currentArticle.accountID }) { - self.currentArticle = newArticle - } - } - - updateShowNamesAndIcons() - IconImageCache.shared.prefetchImagesForArticles(articles) - updateUnreadCount() - mainTimelineViewController?.reloadArticles(animated: animated) + // Update currentArticle to the new instance if it’s still in the timeline. + // If the article is no longer in the timeline, keep showing it anyway - + // don’t blank the user’s screen just because the article filtered out. + // Skip during state restoration so the restored article stays open. + if !isRestoringState, let newArticle = sortedArticles.first(where: isCurrentArticle), newArticle !== currentArticle { + currentArticle = newArticle } + + updateShowNamesAndIcons() + IconImageCache.shared.prefetchImagesForArticles(articles) + updateUnreadCount() + mainTimelineViewController?.reloadArticles(animated: animated) } func queueFetchAndMergeArticles() { @@ -2450,6 +2512,9 @@ private extension SceneCoordinator { cancelPendingAsyncFetches() if emptyFirst { emptyTheTimeline() + } else if let article = currentArticle, let account = article.account { + // Keeping the timeline in place keeps the open article, even when the read filter excludes it. + exceptionArticleFetcher = SingleArticleFetcher(account: account, articleID: article.articleID) } guard let timelineFeed = timelineFeed else { completion()