From 6aa6710c5aeaf3b8b2625b2b7d68555c54eb25d1 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 18 Jan 2026 14:22:47 -0800 Subject: [PATCH 01/12] =?UTF-8?q?Fix=20cause=20of=20hash=20collision=20?= =?UTF-8?q?=E2=80=94=C2=A0SidebarItemIdentifier=20isn=E2=80=99t=20necessar?= =?UTF-8?q?ily=20unique,=20given=20that=20a=20feed=20can=20appear=20in=20m?= =?UTF-8?q?ultiple=20locations=20in=20some=20account=20types.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iOS/SceneCoordinator.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index c0553ccab..003494326 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -36,7 +36,7 @@ struct FeedNode: Hashable, Sendable { } func hash(into hasher: inout Hasher) { - hasher.combine(sidebarItemID) + hasher.combine(node) } } From 93f4331abfd4dd53eaaf63bef837601794032dee Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 18 Jan 2026 14:58:27 -0800 Subject: [PATCH 02/12] Configure and use diffable data source. --- .../MainFeedCollectionViewController.swift | 173 ++++++++++++------ 1 file changed, 112 insertions(+), 61 deletions(-) diff --git a/iOS/MainFeed/MainFeedCollectionViewController.swift b/iOS/MainFeed/MainFeedCollectionViewController.swift index 9377fde39..33390cf14 100644 --- a/iOS/MainFeed/MainFeedCollectionViewController.swift +++ b/iOS/MainFeed/MainFeedCollectionViewController.swift @@ -57,10 +57,13 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab /// `viewDidAppear(_:)` after a delay to allow the deselection animation to complete. private var isAnimating: Bool = false + private var dataSource: UICollectionViewDiffableDataSource! + override func viewDidLoad() { super.viewDidLoad() registerForNotifications() configureCollectionView() + configureDiffableDataSource() collectionView.dragDelegate = self collectionView.dropDelegate = self becomeFirstResponder() @@ -218,71 +221,75 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab } } + func configureDiffableDataSource() { + dataSource = UICollectionViewDiffableDataSource( + collectionView: collectionView + ) { [weak self] collectionView, indexPath, feedNode -> UICollectionViewCell? in + guard let self else { return nil } + + if feedNode.node.representedObject is Folder { + let cell = collectionView.dequeueReusableCell( + withReuseIdentifier: folderIdentifier, + for: indexPath + ) as! MainFeedCollectionViewFolderCell + self.configure(cell, feedNode: feedNode) + cell.delegate = self + return cell + } else { + let cell = collectionView.dequeueReusableCell( + withReuseIdentifier: reuseIdentifier, + for: indexPath + ) as! MainFeedCollectionViewCell + self.configure(cell, feedNode: feedNode) + return cell + } + } + + dataSource.supplementaryViewProvider = { [weak self] collectionView, kind, indexPath in + guard let self else { return nil } + guard kind == UICollectionView.elementKindSectionHeader else { + return UICollectionReusableView() + } + + let headerView = collectionView.dequeueReusableSupplementaryView( + ofKind: kind, + withReuseIdentifier: containerReuseIdentifier, + for: indexPath + ) as! MainFeedCollectionHeaderReusableView + + guard let nameProvider = self.coordinator.rootNode.childAtIndex(indexPath.section)?.representedObject as? DisplayNameProvider else { + return UICollectionReusableView() + } + + headerView.delegate = self + headerView.headerTitle.text = nameProvider.nameForDisplay + + guard let sectionNode = self.coordinator.rootNode.childAtIndex(indexPath.section) else { + return headerView + } + + if let account = sectionNode.representedObject as? Account { + headerView.unreadCount = account.unreadCount + } else { + headerView.unreadCount = 0 + } + + headerView.tag = indexPath.section + headerView.disclosureExpanded = self.coordinator.isExpanded(sectionNode) + + if indexPath.section != 0 { + headerView.addInteraction(UIContextMenuInteraction(delegate: self)) + } + + return headerView + } + } + @IBAction func settings(_ sender: UIBarButtonItem) { coordinator.showSettings() } - // MARK: UICollectionViewDataSource - - override func numberOfSections(in collectionView: UICollectionView) -> Int { - return coordinator.numberOfSections() - } - - override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - return coordinator.numberOfRows(in: section) - } - - override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - guard let node = coordinator.nodeFor(indexPath), node.representedObject is Folder else { - let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! MainFeedCollectionViewCell - configure(cell, indexPath: indexPath) - return cell - } - - let cell = collectionView.dequeueReusableCell(withReuseIdentifier: folderIdentifier, for: indexPath) as! MainFeedCollectionViewFolderCell - configure(cell, indexPath: indexPath) - cell.delegate = self - return cell - - } - - override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { - guard kind == UICollectionView.elementKindSectionHeader else { - return UICollectionReusableView() - } - - let headerView = collectionView.dequeueReusableSupplementaryView( - ofKind: kind, - withReuseIdentifier: containerReuseIdentifier, - for: indexPath - ) as! MainFeedCollectionHeaderReusableView - - guard let nameProvider = coordinator.rootNode.childAtIndex(indexPath.section)?.representedObject as? DisplayNameProvider else { - return UICollectionReusableView() - } - - headerView.delegate = self - headerView.headerTitle.text = nameProvider.nameForDisplay - - guard let sectionNode = coordinator.rootNode.childAtIndex(indexPath.section) else { - return headerView - } - - if let account = sectionNode.representedObject as? Account { - headerView.unreadCount = account.unreadCount - } else { - headerView.unreadCount = 0 - } - - headerView.tag = indexPath.section - headerView.disclosureExpanded = coordinator.isExpanded(sectionNode) - - if indexPath.section != 0 { - headerView.addInteraction(UIContextMenuInteraction(delegate: self)) - } - - return headerView - } + // MARK: UICollectionViewDelegate override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { becomeFirstResponder() @@ -503,6 +510,20 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab } } + func configureIcon(_ cell: MainFeedCollectionViewCell, sidebarItem: SidebarItem) { + guard let sidebarItemID = sidebarItem.sidebarItemID else { + return + } + cell.iconImage = IconImageCache.shared.imageFor(sidebarItemID) + } + + func configureIcon(_ cell: MainFeedCollectionViewFolderCell, sidebarItem: SidebarItem) { + guard let sidebarItemID = sidebarItem.sidebarItemID else { + return + } + cell.iconImage = IconImageCache.shared.imageFor(sidebarItemID) + } + func configureIcon(_ cell: MainFeedCollectionViewCell, _ indexPath: IndexPath) { guard let node = coordinator.nodeFor(indexPath), let sidebarItem = node.representedObject as? SidebarItem, let sidebarItemID = sidebarItem.sidebarItemID else { return @@ -545,6 +566,36 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab // MARK: - Private /// Configure standard feed cells + func configure(_ cell: MainFeedCollectionViewCell, feedNode: FeedNode) { + let node = feedNode.node + var indentationLevel = 0 + if node.parent?.representedObject is Folder { + indentationLevel = 1 + } + + if let sidebarItem = node.representedObject as? SidebarItem { + cell.feedTitle.text = sidebarItem.nameForDisplay + cell.unreadCount = sidebarItem.unreadCount + cell.indentationLevel = indentationLevel + configureIcon(cell, sidebarItem: sidebarItem) + } + } + + /// Configure folders + func configure(_ cell: MainFeedCollectionViewFolderCell, feedNode: FeedNode) { + let node = feedNode.node + + if let folder = node.representedObject as? Folder { + cell.folderTitle.text = folder.nameForDisplay + cell.unreadCount = folder.unreadCount + configureIcon(cell, sidebarItem: folder) + } + + if let containerID = (node.representedObject as? Container)?.containerID { + cell.setDisclosure(isExpanded: coordinator.isExpanded(containerID), animated: false) + } + } + func configure(_ cell: MainFeedCollectionViewCell, indexPath: IndexPath) { guard let node = coordinator.nodeFor(indexPath) else { return } var indentationLevel = 0 From 9d9699c55a103aa6242e8f95dae0e01e507b1246 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 18 Jan 2026 15:43:51 -0800 Subject: [PATCH 03/12] Use diffable data source. --- .../MainFeedCollectionViewController.swift | 60 +---- iOS/SceneCoordinator.swift | 230 ++++++------------ 2 files changed, 85 insertions(+), 205 deletions(-) diff --git a/iOS/MainFeed/MainFeedCollectionViewController.swift b/iOS/MainFeed/MainFeedCollectionViewController.swift index 33390cf14..81a7ae3ae 100644 --- a/iOS/MainFeed/MainFeedCollectionViewController.swift +++ b/iOS/MainFeed/MainFeedCollectionViewController.swift @@ -285,6 +285,12 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab } } + func applySnapshot(_ snapshot: NSDiffableDataSourceSnapshot, animatingDifferences: Bool, completion: (() -> Void)? = nil) { + dataSource.apply(snapshot, animatingDifferences: animatingDifferences) { + completion?() + } + } + @IBAction func settings(_ sender: UIBarButtonItem) { coordinator.showSettings() } @@ -445,60 +451,6 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab } } - func reloadFeeds(initialLoad: Bool, changes: ShadowTableChanges, completion: (() -> Void)? = nil) { - updateUI() - - guard !initialLoad else { - collectionView.reloadData() - completion?() - return - } - - collectionView.performBatchUpdates { - if let deletes = changes.deletes, !deletes.isEmpty { - collectionView.deleteSections(IndexSet(deletes)) - } - - if let inserts = changes.inserts, !inserts.isEmpty { - collectionView.insertSections(IndexSet(inserts)) - } - - if let moves = changes.moves, !moves.isEmpty { - for move in moves { - collectionView.moveSection(move.from, toSection: move.to) - } - } - - if let rowChanges = changes.rowChanges { - for rowChange in rowChanges { - if let deletes = rowChange.deleteIndexPaths, !deletes.isEmpty { - collectionView.deleteItems(at: deletes) - } - - if let inserts = rowChange.insertIndexPaths, !inserts.isEmpty { - collectionView.insertItems(at: inserts) - } - - if let moves = rowChange.moveIndexPaths, !moves.isEmpty { - for move in moves { - collectionView.moveItem(at: move.0, to: move.1) - } - } - } - } - } completion: { _ in - if let rowChanges = changes.rowChanges { - for rowChange in rowChanges { - if let reloads = rowChange.reloadIndexPaths, !reloads.isEmpty { - self.collectionView.reloadItems(at: reloads) - } - } - } - - completion?() - } - } - func applyToAvailableCells(_ completion: (MainFeedCollectionViewCell, IndexPath) -> Void) { for cell in collectionView.visibleCells { guard let indexPath = collectionView.indexPath(for: cell) else { diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 003494326..d4c4fe322 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -66,16 +66,11 @@ struct FeedNode: Hashable, Sendable { // Which Containers are expanded private var expandedContainers = Set() - // Which Containers used to be expanded. Reset by rebuilding the Shadow Table. + // Which Containers used to be expanded. Reset by rebuilding the sidebar. private var lastExpandedContainers = Set() private let hidingReadArticlesState = HidingReadArticlesState() - // Flattened tree structure for the Sidebar - private var shadowTable = [(sectionID: String, feedNodes: [FeedNode])]() - - private var isRebuildingBackingStores = false - private(set) var preSearchTimelineFeed: SidebarItem? private var lastSearchString = "" private var lastSearchScope: SearchScope? @@ -167,11 +162,14 @@ struct FeedNode: Hashable, Sendable { return nil } + let snapshot = mainFeedCollectionViewController.dataSource.snapshot() + let prevIndexPath: IndexPath? = { if indexPath.row - 1 < 0 { for i in (0.. 0 { - return IndexPath(row: shadowTable[i].feedNodes.count - 1, section: i) + let numberOfItems = snapshot.numberOfItems(inSection: snapshot.sectionIdentifiers[i]) + if numberOfItems > 0 { + return IndexPath(row: numberOfItems - 1, section: i) } } return nil @@ -188,10 +186,15 @@ struct FeedNode: Hashable, Sendable { return nil } + let snapshot = mainFeedCollectionViewController.dataSource.snapshot() + let numberOfSections = snapshot.numberOfSections + let nextIndexPath: IndexPath? = { - if indexPath.row + 1 >= shadowTable[indexPath.section].feedNodes.count { - for i in indexPath.section + 1.. 0 { + let numberOfItems = snapshot.numberOfItems(inSection: snapshot.sectionIdentifiers[indexPath.section]) + if indexPath.row + 1 >= numberOfItems { + for i in indexPath.section + 1.. 0 { return IndexPath(row: 0, section: i) } } @@ -314,14 +317,12 @@ struct FeedNode: Hashable, Sendable { for sectionNode in treeController.rootNode.childNodes { markExpanded(sectionNode) - shadowTable.append((sectionID: "", feedNodes: [FeedNode]())) } NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidInitialize(_:)), name: .UnreadCountDidInitialize, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(statusesDidChange(_:)), name: .StatusesDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(containerChildrenDidChange(_:)), name: .ChildrenDidChange, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(batchUpdateDidPerform(_:)), name: .BatchUpdateDidPerform, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange(_:)), name: .DisplayNameDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(accountStateDidChange(_:)), name: .AccountStateDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(userDidAddAccount(_:)), name: .UserDidAddAccount, object: nil) @@ -479,10 +480,6 @@ struct FeedNode: Hashable, Sendable { } } - @objc func batchUpdateDidPerform(_ notification: Notification) { - rebuildBackingStores() - } - @objc func displayNameDidChange(_ note: Notification) { rebuildBackingStores() } @@ -744,31 +741,18 @@ struct FeedNode: Hashable, Sendable { }) } - func numberOfSections() -> Int { - return shadowTable.count - } - - func numberOfRows(in section: Int) -> Int { - return shadowTable[section].feedNodes.count - } - func nodeFor(_ indexPath: IndexPath) -> Node? { - guard indexPath.section > -1 && - indexPath.row > -1 && - indexPath.section < shadowTable.count && - indexPath.row < shadowTable[indexPath.section].feedNodes.count else { + guard let feedNode = mainFeedCollectionViewController.dataSource.itemIdentifier(for: indexPath) else { return nil } - return shadowTable[indexPath.section].feedNodes[indexPath.row].node + return feedNode.node } func indexPathFor(_ node: Node) -> IndexPath? { - for i in 0.. Article? { @@ -780,9 +764,21 @@ struct FeedNode: Hashable, Sendable { } func cappedIndexPath(_ indexPath: IndexPath) -> IndexPath { - guard indexPath.section < shadowTable.count && indexPath.row < shadowTable[indexPath.section].feedNodes.count else { - return IndexPath(row: shadowTable[shadowTable.count - 1].feedNodes.count - 1, section: shadowTable.count - 1) + let snapshot = mainFeedCollectionViewController.dataSource.snapshot() + let numberOfSections = snapshot.numberOfSections + guard numberOfSections > 0 else { return indexPath } + + guard indexPath.section < numberOfSections else { + let lastSection = numberOfSections - 1 + let numberOfItems = snapshot.numberOfItems(inSection: snapshot.sectionIdentifiers[lastSection]) + return IndexPath(row: max(0, numberOfItems - 1), section: lastSection) } + + let numberOfItems = snapshot.numberOfItems(inSection: snapshot.sectionIdentifiers[indexPath.section]) + guard indexPath.row < numberOfItems else { + return IndexPath(row: max(0, numberOfItems - 1), section: indexPath.section) + } + return indexPath } @@ -1613,40 +1609,36 @@ private extension SceneCoordinator { Self.rebuildCount += 1 #endif - if isRebuildingBackingStores || BatchUpdate.shared.isPerforming { -#if DEBUG - if isRebuildingBackingStores { - Self.logger.debug("SceneCoordinator: rebuildBackingStores — skipping because isRebuildingBackingStores") - } else { - Self.logger.debug("SceneCoordinator: rebuildBackingStores — skipping because BatchUpdate.shared.isPerforming") - } -#endif - queueRebuildBackingStores() - return - } - isRebuildingBackingStores = true addToFilterExceptionsIfNecessary(timelineFeed) treeController.rebuild() treeControllerDelegate.resetFilterExceptions() updateExpandedNodes?() - let changes = rebuildShadowTable() - mainFeedCollectionViewController.reloadFeeds(initialLoad: initialLoad, changes: changes) { - completion?() - self.isRebuildingBackingStores = false + + // Update currentFeedIndexPath if needed + if currentFeedIndexPath != nil { + currentFeedIndexPath = indexPathFor(timelineFeed as AnyObject) } + + lastExpandedContainers = expandedContainers + + let snapshot = createSidebarSnapshot() + mainFeedCollectionViewController.applySnapshot(snapshot, animatingDifferences: !initialLoad, completion: completion) } - func rebuildShadowTable() -> ShadowTableChanges { - var newShadowTable = [(sectionID: String, feedNodes: [FeedNode])]() + private func createSidebarSnapshot() -> NSDiffableDataSourceSnapshot { + var snapshot = NSDiffableDataSourceSnapshot() for i in 0..() - var inserts = Set() - var deletes = Set() - - let oldFeedNodes = shadowTable.first(where: { $0.sectionID == newSectionRows.sectionID })?.feedNodes ?? [FeedNode]() - - let diff = newSectionRows.feedNodes.difference(from: oldFeedNodes).inferringMoves() - for change in diff { - switch change { - case .insert(let offset, _, let associated): - if let associated = associated { - moves.insert(ShadowTableChanges.Move(associated, offset)) - } else { - inserts.insert(offset) - } - case .remove(let offset, _, let associated): - if let associated = associated { - moves.insert(ShadowTableChanges.Move(offset, associated)) - } else { - deletes.insert(offset) - } - } - } - - // We need to reload the difference in expanded rows to get the disclosure arrows correct when programmatically changing their state - var reloads = Set() - - for (index, newFeedNode) in newSectionRows.feedNodes.enumerated() { - if let newFeedNodeContainerID = (newFeedNode.node.representedObject as? Container)?.containerID { - if expandedTableDifference.contains(newFeedNodeContainerID) { - reloads.insert(index) - } - } - } - - changes.append(ShadowTableChanges.RowChanges(section: section, deletes: deletes, inserts: inserts, reloads: reloads, moves: moves)) - } - - lastExpandedContainers = expandedContainers - - // Compute the difference in the shadow table sections - var moves = Set() - var inserts = Set() - var deletes = Set() - - let oldSections = shadowTable.map { $0.sectionID } - let newSections = newShadowTable.map { $0.sectionID } - let diff = newSections.difference(from: oldSections).inferringMoves() - for change in diff { - switch change { - case .insert(let offset, _, let associated): - if let associated = associated { - moves.insert(ShadowTableChanges.Move(associated, offset)) - } else { - inserts.insert(offset) - } - case .remove(let offset, _, let associated): - if let associated = associated { - moves.insert(ShadowTableChanges.Move(offset, associated)) - } else { - deletes.insert(offset) - } + snapshot.appendItems(feedNodes, toSection: sectionID) } } - shadowTable = newShadowTable - - return ShadowTableChanges(deletes: deletes, inserts: inserts, moves: moves, rowChanges: changes) + return snapshot } func shadowTableContains(_ sidebarItem: SidebarItem) -> Bool { - for section in shadowTable { - for feedNode in section.feedNodes { - if let nodeSidebarItem = feedNode.node.representedObject as? SidebarItem, nodeSidebarItem.sidebarItemID == sidebarItem.sidebarItemID { - return true - } + let snapshot = mainFeedCollectionViewController.dataSource.snapshot() + for feedNode in snapshot.itemIdentifiers { + if let nodeSidebarItem = feedNode.node.representedObject as? SidebarItem, nodeSidebarItem.sidebarItemID == sidebarItem.sidebarItemID { + return true } } return false @@ -1889,12 +1802,17 @@ private extension SceneCoordinator { }() // Increment or wrap around the IndexPath + let snapshot = mainFeedCollectionViewController.dataSource.snapshot() + let numberOfSections = snapshot.numberOfSections let nextIndexPath: IndexPath = { if indexPath.row - 1 < 0 { if indexPath.section - 1 < 0 { - return IndexPath(row: shadowTable[shadowTable.count - 1].feedNodes.count - 1, section: shadowTable.count - 1) + let lastSection = numberOfSections - 1 + let count = snapshot.numberOfItems(inSection: snapshot.sectionIdentifiers[lastSection]) + return IndexPath(row: count - 1, section: lastSection) } else { - return IndexPath(row: shadowTable[indexPath.section - 1].feedNodes.count - 1, section: indexPath.section - 1) + let count = snapshot.numberOfItems(inSection: snapshot.sectionIdentifiers[indexPath.section - 1]) + return IndexPath(row: count - 1, section: indexPath.section - 1) } } else { return IndexPath(row: indexPath.row - 1, section: indexPath.section) @@ -1904,13 +1822,16 @@ private extension SceneCoordinator { if selectPrevUnreadFeedFetcher(startingWith: nextIndexPath) { return } - let maxIndexPath = IndexPath(row: shadowTable[shadowTable.count - 1].feedNodes.count - 1, section: shadowTable.count - 1) + let lastSection = numberOfSections - 1 + let count = snapshot.numberOfItems(inSection: snapshot.sectionIdentifiers[lastSection]) + let maxIndexPath = IndexPath(row: count - 1, section: lastSection) selectPrevUnreadFeedFetcher(startingWith: maxIndexPath) } @discardableResult func selectPrevUnreadFeedFetcher(startingWith indexPath: IndexPath) -> Bool { + let snapshot = mainFeedCollectionViewController.dataSource.snapshot() for i in (0...indexPath.section).reversed() { @@ -1918,7 +1839,8 @@ private extension SceneCoordinator { if indexPath.section == i { return indexPath.row } else { - return shadowTable[i].feedNodes.count - 1 + let count = snapshot.numberOfItems(inSection: snapshot.sectionIdentifiers[i]) + return count - 1 } }() @@ -1996,9 +1918,12 @@ private extension SceneCoordinator { }() // Increment or wrap around the IndexPath + let snapshot = mainFeedCollectionViewController.dataSource.snapshot() + let numberOfSections = snapshot.numberOfSections let nextIndexPath: IndexPath = { - if indexPath.row + 1 >= shadowTable[indexPath.section].feedNodes.count { - if indexPath.section + 1 >= shadowTable.count { + let count = snapshot.numberOfItems(inSection: snapshot.sectionIdentifiers[indexPath.section]) + if indexPath.row + 1 >= count { + if indexPath.section + 1 >= numberOfSections { return IndexPath(row: 0, section: 0) } else { return IndexPath(row: 0, section: indexPath.section + 1) @@ -2021,8 +1946,10 @@ private extension SceneCoordinator { } func selectNextUnreadFeed(startingWith indexPath: IndexPath, completion: @escaping (Bool) -> Void) { + let snapshot = mainFeedCollectionViewController.dataSource.snapshot() + let numberOfSections = snapshot.numberOfSections - for i in indexPath.section.. Date: Sun, 18 Jan 2026 16:07:38 -0800 Subject: [PATCH 04/12] Fix build errors. --- .../MainFeedCollectionViewController.swift | 2 +- iOS/SceneCoordinator.swift | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/iOS/MainFeed/MainFeedCollectionViewController.swift b/iOS/MainFeed/MainFeedCollectionViewController.swift index 81a7ae3ae..df6e704d1 100644 --- a/iOS/MainFeed/MainFeedCollectionViewController.swift +++ b/iOS/MainFeed/MainFeedCollectionViewController.swift @@ -57,7 +57,7 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab /// `viewDidAppear(_:)` after a delay to allow the deselection animation to complete. private var isAnimating: Bool = false - private var dataSource: UICollectionViewDiffableDataSource! + var dataSource: UICollectionViewDiffableDataSource! override func viewDidLoad() { super.viewDidLoad() diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index d4c4fe322..c38fd395f 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -35,8 +35,12 @@ struct FeedNode: Hashable, Sendable { self.sidebarItemID = (node.representedObject as! SidebarItem).sidebarItemID! } - func hash(into hasher: inout Hasher) { - hasher.combine(node) + nonisolated func hash(into hasher: inout Hasher) { + hasher.combine(ObjectIdentifier(node)) + } + + nonisolated static func == (lhs: FeedNode, rhs: FeedNode) -> Bool { + lhs.node === rhs.node } } @@ -749,9 +753,7 @@ struct FeedNode: Hashable, Sendable { } func indexPathFor(_ node: Node) -> IndexPath? { - let snapshot = mainFeedCollectionViewController.dataSource.snapshot() let feedNode = FeedNode(node) - return mainFeedCollectionViewController.dataSource.indexPath(for: feedNode) } @@ -1584,11 +1586,10 @@ private extension SceneCoordinator { } func addShadowTableToFilterExceptions() { - for section in shadowTable { - for feedNode in section.feedNodes { - if let feed = feedNode.node.representedObject as? SidebarItem, let sidebarItemID = feed.sidebarItemID { - treeControllerDelegate.addFilterException(sidebarItemID) - } + let snapshot = mainFeedCollectionViewController.dataSource.snapshot() + for feedNode in snapshot.itemIdentifiers { + if let feed = feedNode.node.representedObject as? SidebarItem, let sidebarItemID = feed.sidebarItemID { + treeControllerDelegate.addFilterException(sidebarItemID) } } } From 8f078352cac1411218b05fc1e287f30e175fc627 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 19 Jan 2026 08:54:28 -0800 Subject: [PATCH 05/12] Make sure dataSource exists at the right time on launch. Make tweak to logging in rebuildBackingStores to make it less annoying. --- iOS/SceneCoordinator.swift | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index c38fd395f..c3dcd4365 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -363,6 +363,9 @@ struct FeedNode: Hashable, Sendable { hidingReadArticlesState.copy(from: stateInfo) + // Ensure the view is loaded so dataSource is initialized before rebuilding + _ = mainFeedCollectionViewController.view + 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 @@ -1577,9 +1580,9 @@ private extension SceneCoordinator { func addParentFolderToFilterExceptions(_ sidebarItem: SidebarItem) { guard let node = treeController.rootNode.descendantNodeRepresentingObject(sidebarItem as AnyObject), - let folder = node.parent?.representedObject as? Folder, - let folderSidebarItemID = folder.sidebarItemID else { - return + let folder = node.parent?.representedObject as? Folder, + let folderSidebarItemID = folder.sidebarItemID else { + return } treeControllerDelegate.addFilterException(folderSidebarItemID) @@ -1606,7 +1609,11 @@ private extension SceneCoordinator { func rebuildBackingStores(initialLoad: Bool = false, updateExpandedNodes: (() -> Void)? = nil, completion: (() -> Void)? = nil) { #if DEBUG - Self.logger.debug("SceneCoordinator: rebuildBackingStores: # \(Self.rebuildCount) initialLoad \(initialLoad ? "true" : "false")") + if initialLoad { + Self.logger.debug("SceneCoordinator: rebuildBackingStores: #\(Self.rebuildCount) initialLoad == true") + } else { + Self.logger.debug("SceneCoordinator: rebuildBackingStores: #\(Self.rebuildCount)") + } Self.rebuildCount += 1 #endif From 46351e7a505dc5d86a19f1b3fde0567b28db323d Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 19 Jan 2026 09:13:12 -0800 Subject: [PATCH 06/12] Deleted now-unused ShadowTableChanges. --- iOS/MainFeed/ShadowTableChanges.swift | 69 --------------------------- 1 file changed, 69 deletions(-) delete mode 100644 iOS/MainFeed/ShadowTableChanges.swift diff --git a/iOS/MainFeed/ShadowTableChanges.swift b/iOS/MainFeed/ShadowTableChanges.swift deleted file mode 100644 index eb42aa4f4..000000000 --- a/iOS/MainFeed/ShadowTableChanges.swift +++ /dev/null @@ -1,69 +0,0 @@ -// -// ShadowTableChanges.swift -// NetNewsWire-iOS -// -// Created by Maurice Parker on 10/20/21. -// Copyright © 2021 Ranchero Software. All rights reserved. -// - -import Foundation - -struct ShadowTableChanges { - - struct Move: Hashable { - var from: Int - var to: Int - - init(_ from: Int, _ to: Int) { - self.from = from - self.to = to - } - } - - struct RowChanges { - - var section: Int - var deletes: Set? - var inserts: Set? - var reloads: Set? - var moves: Set? - - var isEmpty: Bool { - return (deletes?.isEmpty ?? true) && (inserts?.isEmpty ?? true) && (moves?.isEmpty ?? true) - } - - var deleteIndexPaths: [IndexPath]? { - guard let deletes = deletes else { return nil } - return deletes.map { IndexPath(row: $0, section: section) } - } - - var insertIndexPaths: [IndexPath]? { - guard let inserts = inserts else { return nil } - return inserts.map { IndexPath(row: $0, section: section) } - } - - var reloadIndexPaths: [IndexPath]? { - guard let reloads = reloads else { return nil } - return reloads.map { IndexPath(row: $0, section: section) } - } - - var moveIndexPaths: [(IndexPath, IndexPath)]? { - guard let moves = moves else { return nil } - return moves.map { (IndexPath(row: $0.from, section: section), IndexPath(row: $0.to, section: section)) } - } - - init(section: Int, deletes: Set?, inserts: Set?, reloads: Set?, moves: Set?) { - self.section = section - self.deletes = deletes - self.inserts = inserts - self.reloads = reloads - self.moves = moves - } - } - - var deletes: Set? - var inserts: Set? - var moves: Set? - var rowChanges: [RowChanges]? - -} From e2eca11b6c27cdcf79f93404bbdbb3d15f06145b Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 19 Jan 2026 09:13:22 -0800 Subject: [PATCH 07/12] Renamed functions that reference shadowTable. --- iOS/SceneCoordinator.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index c3dcd4365..d3a3e2e88 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -1553,7 +1553,7 @@ private extension SceneCoordinator { func ensureFeedIsAvailableToSelect(_ sidebarItem: SidebarItem, completion: @escaping () -> Void) { addToFilterExceptionsIfNecessary(sidebarItem) - addShadowTableToFilterExceptions() + addVisibleSidebarItemsToFilterExceptions() rebuildBackingStores(completion: { self.treeControllerDelegate.resetFilterExceptions() @@ -1588,7 +1588,7 @@ private extension SceneCoordinator { treeControllerDelegate.addFilterException(folderSidebarItemID) } - func addShadowTableToFilterExceptions() { + func addVisibleSidebarItemsToFilterExceptions() { let snapshot = mainFeedCollectionViewController.dataSource.snapshot() for feedNode in snapshot.itemIdentifiers { if let feed = feedNode.node.representedObject as? SidebarItem, let sidebarItemID = feed.sidebarItemID { @@ -1663,7 +1663,7 @@ private extension SceneCoordinator { return snapshot } - func shadowTableContains(_ sidebarItem: SidebarItem) -> Bool { + func sidebarContains(_ sidebarItem: SidebarItem) -> Bool { let snapshot = mainFeedCollectionViewController.dataSource.snapshot() for feedNode in snapshot.itemIdentifiers { if let nodeSidebarItem = feedNode.node.representedObject as? SidebarItem, nodeSidebarItem.sidebarItemID == sidebarItem.sidebarItemID { @@ -1674,7 +1674,7 @@ private extension SceneCoordinator { } func clearTimelineIfNoLongerAvailable() { - if let feed = timelineFeed, !shadowTableContains(feed) { + if let feed = timelineFeed, !sidebarContains(feed) { selectFeed(nil, deselectArticle: true) } } From 3036fb74bdfbdb87ab72dbe94eb6160045967ddc Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 19 Jan 2026 09:19:08 -0800 Subject: [PATCH 08/12] =?UTF-8?q?Put=20a=20guard=E2=80=99s=20return=20stat?= =?UTF-8?q?ement=20on=20its=20own=20line.=20It=E2=80=99s=20quicker=20for?= =?UTF-8?q?=20me=20to=20parse=20and=20easier=20to=20set=20a=20breakpoint.?= =?UTF-8?q?=20(Yes,=20I=20know=20that=20we=20can=20set=20a=20breakpoint=20?= =?UTF-8?q?for=20an=20inline=20return.)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MainFeedCollectionViewController.swift | 44 ++++++++++++---- iOS/SceneCoordinator.swift | 52 ++++++++++++++----- 2 files changed, 72 insertions(+), 24 deletions(-) diff --git a/iOS/MainFeed/MainFeedCollectionViewController.swift b/iOS/MainFeed/MainFeedCollectionViewController.swift index df6e704d1..2be641067 100644 --- a/iOS/MainFeed/MainFeedCollectionViewController.swift +++ b/iOS/MainFeed/MainFeedCollectionViewController.swift @@ -39,7 +39,9 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab // 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 } + guard let current = UIResponder.currentFirstResponder, !(current is PreloadedWebView) else { + return nil + } return keyboardManager.keyCommands } @@ -225,7 +227,9 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab dataSource = UICollectionViewDiffableDataSource( collectionView: collectionView ) { [weak self] collectionView, indexPath, feedNode -> UICollectionViewCell? in - guard let self else { return nil } + guard let self else { + return nil + } if feedNode.node.representedObject is Folder { let cell = collectionView.dequeueReusableCell( @@ -246,7 +250,9 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab } dataSource.supplementaryViewProvider = { [weak self] collectionView, kind, indexPath in - guard let self else { return nil } + guard let self else { + return nil + } guard kind == UICollectionView.elementKindSectionHeader else { return UICollectionReusableView() } @@ -549,7 +555,9 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab } func configure(_ cell: MainFeedCollectionViewCell, indexPath: IndexPath) { - guard let node = coordinator.nodeFor(indexPath) else { return } + guard let node = coordinator.nodeFor(indexPath) else { + return + } var indentationLevel = 0 if node.parent?.representedObject is Folder { indentationLevel = 1 @@ -565,7 +573,9 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab /// Configure folders func configure(_ cell: MainFeedCollectionViewFolderCell, indexPath: IndexPath) { - guard let node = coordinator.nodeFor(indexPath) else { return } + guard let node = coordinator.nodeFor(indexPath) else { + return + } if let folder = node.representedObject as? Folder { cell.folderTitle.text = folder.nameForDisplay @@ -590,7 +600,9 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab } private func reloadAllVisibleCells(completion: (() -> Void)? = nil) { - guard let indexPaths = collectionView.indexPathsForSelectedItems else { return } + guard let indexPaths = collectionView.indexPathsForSelectedItems else { + return + } collectionView.reloadItems(at: indexPaths) restoreSelectionIfNecessary(adjustScroll: false) } @@ -628,7 +640,9 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab let node: Node? = coordinator.rootNode.descendantNodeRepresentingObject(unreadCountProvider as AnyObject) - guard let unreadCountNode = node, let indexPath = coordinator.indexPathFor(unreadCountNode) else { return } + guard let unreadCountNode = node, let indexPath = coordinator.indexPathFor(unreadCountNode) else { + return + } if let cell = collectionView.cellForItem(at: indexPath) as? MainFeedCollectionViewCell { cell.unreadCount = unreadCountProvider.unreadCount @@ -813,7 +827,9 @@ extension MainFeedCollectionViewController { func makeFeedContextMenu(indexPath: IndexPath, includeDeleteRename: Bool) -> UIContextMenuConfiguration { return UIContextMenuConfiguration(identifier: MainFeedRowIdentifier(indexPath: indexPath), previewProvider: nil, actionProvider: { [ weak self] _ in - guard let self = self else { return nil } + guard let self = self else { + return nil + } var menuElements = [UIMenuElement]() @@ -856,7 +872,9 @@ extension MainFeedCollectionViewController { func makeFolderContextMenu(indexPath: IndexPath) -> UIContextMenuConfiguration { return UIContextMenuConfiguration(identifier: MainFeedRowIdentifier(indexPath: indexPath), previewProvider: nil, actionProvider: { [weak self] _ in - guard let self = self else { return nil } + guard let self = self else { + return nil + } var menuElements = [UIMenuElement]() @@ -1089,7 +1107,9 @@ extension MainFeedCollectionViewController { } func rename(indexPath: IndexPath) { - guard let sidebarItem = coordinator.nodeFor(indexPath)?.representedObject as? SidebarItem else { return } + guard let sidebarItem = coordinator.nodeFor(indexPath)?.representedObject as? SidebarItem else { + return + } let formatString = NSLocalizedString("Rename “%@”", comment: "Rename feed") let title = NSString.localizedStringWithFormat(formatString as NSString, sidebarItem.nameForDisplay) as String @@ -1144,7 +1164,9 @@ extension MainFeedCollectionViewController { } func delete(indexPath: IndexPath) { - guard let sidebarItem = coordinator.nodeFor(indexPath)?.representedObject as? SidebarItem else { return } + guard let sidebarItem = coordinator.nodeFor(indexPath)?.representedObject as? SidebarItem else { + return + } let title: String let message: String diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index d3a3e2e88..1af2839c2 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -275,7 +275,9 @@ struct FeedNode: Hashable, Sendable { } private var currentArticleRow: Int? { - guard let article = currentArticle else { return nil } + guard let article = currentArticle else { + return nil + } return articles.firstIndex(of: article) } @@ -405,7 +407,9 @@ struct FeedNode: Hashable, Sendable { func handle(_ activity: NSUserActivity) { selectFeed(indexPath: nil) { - guard let activityType = ActivityType(rawValue: activity.activityType) else { return } + guard let activityType = ActivityType(rawValue: activity.activityType) else { + return + } switch activityType { case .restoration: break @@ -771,7 +775,9 @@ struct FeedNode: Hashable, Sendable { func cappedIndexPath(_ indexPath: IndexPath) -> IndexPath { let snapshot = mainFeedCollectionViewController.dataSource.snapshot() let numberOfSections = snapshot.numberOfSections - guard numberOfSections > 0 else { return indexPath } + guard numberOfSections > 0 else { + return indexPath + } guard indexPath.section < numberOfSections else { let lastSection = numberOfSections - 1 @@ -835,7 +841,9 @@ struct FeedNode: Hashable, Sendable { /// This is a special function that expects the caller to change the disclosure arrow state outside this function. /// Failure to do so will get the Sidebar into an invalid state. func expand(_ node: Node) { - guard let containerID = (node.representedObject as? ContainerIdentifiable)?.containerID else { return } + guard let containerID = (node.representedObject as? ContainerIdentifiable)?.containerID else { + return + } lastExpandedContainers.insert(containerID) expand(containerID) } @@ -863,7 +871,9 @@ struct FeedNode: Hashable, Sendable { /// This is a special function that expects the caller to change the disclosure arrow state outside this function. /// Failure to do so will get the Sidebar into an invalid state. func collapse(_ node: Node) { - guard let containerID = (node.representedObject as? ContainerIdentifiable)?.containerID else { return } + guard let containerID = (node.representedObject as? ContainerIdentifiable)?.containerID else { + return + } lastExpandedContainers.remove(containerID) collapse(containerID) } @@ -975,7 +985,9 @@ struct FeedNode: Hashable, Sendable { } func selectArticle(_ article: Article?, animations: Animations = [], isShowingExtractedArticle: Bool? = nil, articleWindowScrollY: Int? = nil) { - guard article != currentArticle else { return } + guard article != currentArticle else { + return + } currentArticle = article activityManager.reading(feed: timelineFeed, article: article) @@ -1030,7 +1042,9 @@ struct FeedNode: Hashable, Sendable { func searchArticles(_ searchString: String, _ searchScope: SearchScope) { - guard isSearching else { return } + guard isSearching else { + return + } if searchString.count < 3 { setTimelineFeed(nil, animated: true) @@ -1212,7 +1226,9 @@ struct FeedNode: Hashable, Sendable { } func toggleRead(_ article: Article) { - guard !article.status.read || article.isAvailableToMarkUnread else { return } + guard !article.status.read || article.isAvailableToMarkUnread else { + return + } markArticlesWithUndo([article], statusKey: .read, flag: !article.status.read) } @@ -1378,12 +1394,16 @@ struct FeedNode: Hashable, Sendable { } func showBrowserForArticle(_ article: Article) { - guard let url = article.preferredURL else { return } + guard let url = article.preferredURL else { + return + } UIApplication.shared.open(url, options: [:]) } func showBrowserForCurrentArticle() { - guard let url = currentArticle?.preferredURL else { return } + guard let url = currentArticle?.preferredURL else { + return + } UIApplication.shared.open(url, options: [:]) } @@ -1434,12 +1454,16 @@ struct FeedNode: Hashable, Sendable { /// `SFSafariViewController` or `SettingsViewController`, /// otherwise, this function does nothing. func dismissIfLaunchingFromExternalAction() { - guard let presentedController = mainFeedCollectionViewController.presentedViewController else { return } + guard let presentedController = mainFeedCollectionViewController.presentedViewController else { + return + } if presentedController.isKind(of: SFSafariViewController.self) { presentedController.dismiss(animated: true, completion: nil) } - guard let settings = presentedController.children.first as? SettingsViewController else { return } + guard let settings = presentedController.children.first as? SettingsViewController else { + return + } settings.dismiss(animated: true, completion: nil) } @@ -2211,7 +2235,9 @@ private extension SceneCoordinator { } func handleReadArticle(_ userInfo: [AnyHashable: Any]?) { - guard let userInfo = userInfo else { return } + guard let userInfo = userInfo else { + return + } guard let articlePathUserInfo = userInfo[UserInfoKey.articlePath] as? [AnyHashable: Any], let accountID = articlePathUserInfo[ArticlePathKey.accountID] as? String, From a4318895918fd4e6c4b31084a994a2c617e4b553 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 19 Jan 2026 09:32:10 -0800 Subject: [PATCH 09/12] Rename FeedNode to SidebarItemNode. --- .../Sidebar/SidebarOutlineDataSource.swift | 6 +-- .../Sidebar/SidebarViewController.swift | 6 +-- .../MainFeedCollectionViewController.swift | 22 +++++----- iOS/SceneCoordinator.swift | 42 +++++++++---------- 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift b/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift index 34fdfecb4..23401be3e 100644 --- a/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift +++ b/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift @@ -646,12 +646,12 @@ private extension SidebarOutlineDataSource { func indexWhereDraggedFeedWouldAppear(_ parentNode: Node, _ draggedFeed: PasteboardFeed) -> Int { let draggedFeedWrapper = PasteboardFeedObjectWrapper(pasteboardFeed: draggedFeed) - let draggedFeedNode = Node(representedObject: draggedFeedWrapper, parent: nil) - let nodes = parentNode.childNodes + [draggedFeedNode] + let draggedSidebarItemNode = Node(representedObject: draggedFeedWrapper, parent: nil) + let nodes = parentNode.childNodes + [draggedSidebarItemNode] // Revisit if the tree controller can ever be sorted in some other way. let sortedNodes = nodes.sortedAlphabeticallyWithFoldersAtEnd() - let index = sortedNodes.firstIndex(of: draggedFeedNode)! + let index = sortedNodes.firstIndex(of: draggedSidebarItemNode)! return index } diff --git a/Mac/MainWindow/Sidebar/SidebarViewController.swift b/Mac/MainWindow/Sidebar/SidebarViewController.swift index 776507a95..c1ca1e7a6 100644 --- a/Mac/MainWindow/Sidebar/SidebarViewController.swift +++ b/Mac/MainWindow/Sidebar/SidebarViewController.swift @@ -510,8 +510,8 @@ extension Notification.Name { func deepLinkRevealAndSelect(for userInfo: [AnyHashable: Any]) { guard let accountNode = findAccountNode(userInfo), - let feedNode = findFeedNode(userInfo, beginningAt: accountNode), - let sidebarItem = feedNode.representedObject as? SidebarItem else { + let sidebarItemNode = findSidebarItemNode(userInfo, beginningAt: accountNode), + let sidebarItem = sidebarItemNode.representedObject as? SidebarItem else { return } selectFeed(sidebarItem) @@ -783,7 +783,7 @@ private extension SidebarViewController { return nil } - func findFeedNode(_ userInfo: [AnyHashable: Any]?, beginningAt startingNode: Node) -> Node? { + func findSidebarItemNode(_ userInfo: [AnyHashable: Any]?, beginningAt startingNode: Node) -> Node? { guard let feedID = userInfo?[ArticlePathKey.feedID] as? String else { return nil } diff --git a/iOS/MainFeed/MainFeedCollectionViewController.swift b/iOS/MainFeed/MainFeedCollectionViewController.swift index 2be641067..4017b8c89 100644 --- a/iOS/MainFeed/MainFeedCollectionViewController.swift +++ b/iOS/MainFeed/MainFeedCollectionViewController.swift @@ -59,7 +59,7 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab /// `viewDidAppear(_:)` after a delay to allow the deselection animation to complete. private var isAnimating: Bool = false - var dataSource: UICollectionViewDiffableDataSource! + var dataSource: UICollectionViewDiffableDataSource! override func viewDidLoad() { super.viewDidLoad() @@ -224,19 +224,19 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab } func configureDiffableDataSource() { - dataSource = UICollectionViewDiffableDataSource( + dataSource = UICollectionViewDiffableDataSource( collectionView: collectionView - ) { [weak self] collectionView, indexPath, feedNode -> UICollectionViewCell? in + ) { [weak self] collectionView, indexPath, sidebarItemNode -> UICollectionViewCell? in guard let self else { return nil } - if feedNode.node.representedObject is Folder { + if sidebarItemNode.node.representedObject is Folder { let cell = collectionView.dequeueReusableCell( withReuseIdentifier: folderIdentifier, for: indexPath ) as! MainFeedCollectionViewFolderCell - self.configure(cell, feedNode: feedNode) + self.configure(cell, sidebarItemNode: sidebarItemNode) cell.delegate = self return cell } else { @@ -244,7 +244,7 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab withReuseIdentifier: reuseIdentifier, for: indexPath ) as! MainFeedCollectionViewCell - self.configure(cell, feedNode: feedNode) + self.configure(cell, sidebarItemNode: sidebarItemNode) return cell } } @@ -291,7 +291,7 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab } } - func applySnapshot(_ snapshot: NSDiffableDataSourceSnapshot, animatingDifferences: Bool, completion: (() -> Void)? = nil) { + func applySnapshot(_ snapshot: NSDiffableDataSourceSnapshot, animatingDifferences: Bool, completion: (() -> Void)? = nil) { dataSource.apply(snapshot, animatingDifferences: animatingDifferences) { completion?() } @@ -524,8 +524,8 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab // MARK: - Private /// Configure standard feed cells - func configure(_ cell: MainFeedCollectionViewCell, feedNode: FeedNode) { - let node = feedNode.node + func configure(_ cell: MainFeedCollectionViewCell, sidebarItemNode: SidebarItemNode) { + let node = sidebarItemNode.node var indentationLevel = 0 if node.parent?.representedObject is Folder { indentationLevel = 1 @@ -540,8 +540,8 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab } /// Configure folders - func configure(_ cell: MainFeedCollectionViewFolderCell, feedNode: FeedNode) { - let node = feedNode.node + func configure(_ cell: MainFeedCollectionViewFolderCell, sidebarItemNode: SidebarItemNode) { + let node = sidebarItemNode.node if let folder = node.representedObject as? Folder { cell.folderTitle.text = folder.nameForDisplay diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 1af2839c2..28ed8d7d9 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -26,7 +26,7 @@ enum ShowFeedName { case feed } -struct FeedNode: Hashable, Sendable { +struct SidebarItemNode: Hashable, Sendable { let node: Node let sidebarItemID: SidebarItemIdentifier @@ -39,7 +39,7 @@ struct FeedNode: Hashable, Sendable { hasher.combine(ObjectIdentifier(node)) } - nonisolated static func == (lhs: FeedNode, rhs: FeedNode) -> Bool { + nonisolated static func == (lhs: SidebarItemNode, rhs: SidebarItemNode) -> Bool { lhs.node === rhs.node } } @@ -382,8 +382,8 @@ struct FeedNode: Hashable, Sendable { return } - guard let feedNode = nodeFor(sidebarItemID: selectedSidebarItem), - let indexPath = indexPathFor(feedNode) else { + guard let sidebarItemNode = nodeFor(sidebarItemID: selectedSidebarItem), + let indexPath = indexPathFor(sidebarItemNode) else { return } selectFeed(indexPath: indexPath, animations: []) { @@ -753,15 +753,15 @@ struct FeedNode: Hashable, Sendable { } func nodeFor(_ indexPath: IndexPath) -> Node? { - guard let feedNode = mainFeedCollectionViewController.dataSource.itemIdentifier(for: indexPath) else { + guard let sidebarItemNode = mainFeedCollectionViewController.dataSource.itemIdentifier(for: indexPath) else { return nil } - return feedNode.node + return sidebarItemNode.node } func indexPathFor(_ node: Node) -> IndexPath? { - let feedNode = FeedNode(node) - return mainFeedCollectionViewController.dataSource.indexPath(for: feedNode) + let sidebarItemNode = SidebarItemNode(node) + return mainFeedCollectionViewController.dataSource.indexPath(for: sidebarItemNode) } func articleFor(_ articleID: String) -> Article? { @@ -1614,8 +1614,8 @@ private extension SceneCoordinator { func addVisibleSidebarItemsToFilterExceptions() { let snapshot = mainFeedCollectionViewController.dataSource.snapshot() - for feedNode in snapshot.itemIdentifiers { - if let feed = feedNode.node.representedObject as? SidebarItem, let sidebarItemID = feed.sidebarItemID { + for sidebarItemNode in snapshot.itemIdentifiers { + if let feed = sidebarItemNode.node.representedObject as? SidebarItem, let sidebarItemID = feed.sidebarItemID { treeControllerDelegate.addFilterException(sidebarItemID) } } @@ -1659,8 +1659,8 @@ private extension SceneCoordinator { mainFeedCollectionViewController.applySnapshot(snapshot, animatingDifferences: !initialLoad, completion: completion) } - private func createSidebarSnapshot() -> NSDiffableDataSourceSnapshot { - var snapshot = NSDiffableDataSourceSnapshot() + private func createSidebarSnapshot() -> NSDiffableDataSourceSnapshot { + var snapshot = NSDiffableDataSourceSnapshot() for i in 0.. Bool { let snapshot = mainFeedCollectionViewController.dataSource.snapshot() - for feedNode in snapshot.itemIdentifiers { - if let nodeSidebarItem = feedNode.node.representedObject as? SidebarItem, nodeSidebarItem.sidebarItemID == sidebarItem.sidebarItemID { + for sidebarItemNode in snapshot.itemIdentifiers { + if let nodeSidebarItem = sidebarItemNode.node.representedObject as? SidebarItem, nodeSidebarItem.sidebarItemID == sidebarItem.sidebarItemID { return true } } @@ -2289,7 +2289,7 @@ private extension SceneCoordinator { let found = selectFeedAndArticle(sidebarItemID: sidebarItemID, articleID: articleID, isShowingExtractedArticle: isShowingExtractedArticle, articleWindowScrollY: articleWindowScrollY) if found { treeControllerDelegate.addFilterException(sidebarItemID) - if let feedNode = nodeFor(sidebarItemID: sidebarItemID), let folder = feedNode.parent?.representedObject as? Folder, let folderSidebarItemID = folder.sidebarItemID { + if let sidebarItemNode = nodeFor(sidebarItemID: sidebarItemID), let folder = sidebarItemNode.parent?.representedObject as? Folder, let folderSidebarItemID = folder.sidebarItemID { treeControllerDelegate.addFilterException(folderSidebarItemID) } } @@ -2317,7 +2317,7 @@ private extension SceneCoordinator { return nil } - func findFeedNode(feedID: String, beginningAt startingNode: Node) -> Node? { + func findSidebarItemNode(feedID: String, beginningAt startingNode: Node) -> Node? { if let node = startingNode.descendantNode(where: { ($0.representedObject as? Feed)?.feedID == feedID }) { return node } @@ -2325,7 +2325,7 @@ private extension SceneCoordinator { } func selectFeedAndArticle(sidebarItemID: SidebarItemIdentifier, articleID: String, isShowingExtractedArticle: Bool, articleWindowScrollY: Int) -> Bool { - guard let feedNode = nodeFor(sidebarItemID: sidebarItemID), let feedIndexPath = indexPathFor(feedNode) else { return false } + guard let sidebarItemNode = nodeFor(sidebarItemID: sidebarItemID), let feedIndexPath = indexPathFor(sidebarItemNode) else { return false } selectFeed(indexPath: feedIndexPath) { self.selectArticleInCurrentFeed(articleID, isShowingExtractedArticle: isShowingExtractedArticle, articleWindowScrollY: articleWindowScrollY) From 3d5486ad5f6b2cde282ab5e44e71b0ea28040afb Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 19 Jan 2026 09:41:06 -0800 Subject: [PATCH 10/12] Rename some instances of Feed and feed that should be SidebarItem and sidebarItem. --- .../MainFeedCollectionViewController.swift | 6 ++-- iOS/SceneCoordinator.swift | 34 ++++++++++--------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/iOS/MainFeed/MainFeedCollectionViewController.swift b/iOS/MainFeed/MainFeedCollectionViewController.swift index 4017b8c89..258cf9c8d 100644 --- a/iOS/MainFeed/MainFeedCollectionViewController.swift +++ b/iOS/MainFeed/MainFeedCollectionViewController.swift @@ -103,7 +103,7 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab /// to false and this will allow selection. if traitCollection.userInterfaceIdiom == .phone { if collectionView.indexPathsForSelectedItems != nil { - coordinator.selectFeed(indexPath: nil, animations: [.select]) + coordinator.selectSidebarItem(indexPath: nil, animations: [.select]) DispatchQueue.main.asyncAfter(deadline: .now() + 0.3, execute: { self.isAnimating = false }) @@ -305,7 +305,7 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { becomeFirstResponder() - coordinator.selectFeed(indexPath: indexPath, animations: [.navigation, .select, .scroll]) + coordinator.selectSidebarItem(indexPath: indexPath, animations: [.navigation, .select, .scroll]) } // MARK: UICollectionViewDelegate @@ -1209,7 +1209,7 @@ extension MainFeedCollectionViewController { } if indexPath == coordinator.currentFeedIndexPath { - coordinator.selectFeed(indexPath: nil) + coordinator.selectSidebarItem(indexPath: nil) } pushUndoableCommand(deleteCommand) diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 28ed8d7d9..3caf62345 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -386,7 +386,7 @@ struct SidebarItemNode: Hashable, Sendable { let indexPath = indexPathFor(sidebarItemNode) else { return } - selectFeed(indexPath: indexPath, animations: []) { + selectSidebarItem(indexPath: indexPath, animations: []) { self.restoreSelectedArticle(stateInfo) } } @@ -406,7 +406,7 @@ struct SidebarItemNode: Hashable, Sendable { } func handle(_ activity: NSUserActivity) { - selectFeed(indexPath: nil) { + selectSidebarItem(indexPath: nil) { guard let activityType = ActivityType(rawValue: activity.activityType) else { return } @@ -448,7 +448,7 @@ struct SidebarItemNode: Hashable, Sendable { } func showSearch() { - selectFeed(indexPath: nil) { + selectSidebarItem(indexPath: nil) { self.rootSplitViewController.show(.supplementary) DispatchQueue.main.asyncAfter(deadline: .now()) { self.mainTimelineViewController!.showSearchAll() @@ -906,11 +906,11 @@ struct SidebarItemNode: Hashable, Sendable { return nil } }() - selectFeed(indexPath: indexPath, animations: animations, deselectArticle: deselectArticle, completion: completion) + selectSidebarItem(indexPath: indexPath, animations: animations, deselectArticle: deselectArticle, completion: completion) updateNavigationBarSubtitles(nil) } - func selectFeed(indexPath: IndexPath?, animations: Animations = [], deselectArticle: Bool = true, completion: (() -> Void)? = nil) { + func selectSidebarItem(indexPath: IndexPath?, animations: Animations = [], deselectArticle: Bool = true, completion: (() -> Void)? = nil) { guard indexPath != currentFeedIndexPath else { completion?() return @@ -953,13 +953,13 @@ struct SidebarItemNode: Hashable, Sendable { func selectPrevFeed() { if let indexPath = prevFeedIndexPath { - selectFeed(indexPath: indexPath, animations: [.navigation, .scroll]) + selectSidebarItem(indexPath: indexPath, animations: [.navigation, .scroll]) } } func selectNextFeed() { if let indexPath = nextFeedIndexPath { - selectFeed(indexPath: indexPath, animations: [.navigation, .scroll]) + selectSidebarItem(indexPath: indexPath, animations: [.navigation, .scroll]) } } @@ -1889,7 +1889,7 @@ private extension SceneCoordinator { } if unreadCountProvider.unreadCount > 0 { - selectFeed(indexPath: prevIndexPath, animations: [.scroll, .navigation]) + selectSidebarItem(indexPath: prevIndexPath, animations: [.scroll, .navigation]) return true } @@ -2006,7 +2006,7 @@ private extension SceneCoordinator { } if unreadCountProvider.unreadCount > 0 { - selectFeed(indexPath: nextIndexPath, animations: [.scroll, .navigation], deselectArticle: false) { + selectSidebarItem(indexPath: nextIndexPath, animations: [.scroll, .navigation], deselectArticle: false) { self.currentArticle = nil completion(true) } @@ -2197,7 +2197,7 @@ private extension SceneCoordinator { rebuildBackingStores(initialLoad: true, completion: { self.treeControllerDelegate.resetFilterExceptions() if let indexPath = self.indexPathFor(smartFeed) { - self.selectFeed(indexPath: indexPath) { + self.selectSidebarItem(indexPath: indexPath) { self.mainFeedCollectionViewController.focus() } } @@ -2215,7 +2215,7 @@ private extension SceneCoordinator { self.treeControllerDelegate.resetFilterExceptions() if let folderNode = self.findFolderNode(folderName: folderName, beginningAt: accountNode), let indexPath = self.indexPathFor(folderNode) { - self.selectFeed(indexPath: indexPath) { + self.selectSidebarItem(indexPath: indexPath) { self.mainFeedCollectionViewController.focus() } } @@ -2279,14 +2279,14 @@ private extension SceneCoordinator { switch sidebarItemID { case .smartFeed, .folder: - let found = selectFeedAndArticle(sidebarItemID: sidebarItemID, articleID: articleID, isShowingExtractedArticle: isShowingExtractedArticle, articleWindowScrollY: articleWindowScrollY) + let found = selectSidebarItemAndArticle(sidebarItemID: sidebarItemID, articleID: articleID, isShowingExtractedArticle: isShowingExtractedArticle, articleWindowScrollY: articleWindowScrollY) if found { treeControllerDelegate.addFilterException(sidebarItemID) } return found case .feed: - let found = selectFeedAndArticle(sidebarItemID: sidebarItemID, articleID: articleID, isShowingExtractedArticle: isShowingExtractedArticle, articleWindowScrollY: articleWindowScrollY) + let found = selectSidebarItemAndArticle(sidebarItemID: sidebarItemID, articleID: articleID, isShowingExtractedArticle: isShowingExtractedArticle, articleWindowScrollY: articleWindowScrollY) if found { treeControllerDelegate.addFilterException(sidebarItemID) if let sidebarItemNode = nodeFor(sidebarItemID: sidebarItemID), let folder = sidebarItemNode.parent?.representedObject as? Folder, let folderSidebarItemID = folder.sidebarItemID { @@ -2324,10 +2324,12 @@ private extension SceneCoordinator { return nil } - func selectFeedAndArticle(sidebarItemID: SidebarItemIdentifier, articleID: String, isShowingExtractedArticle: Bool, articleWindowScrollY: Int) -> Bool { - guard let sidebarItemNode = nodeFor(sidebarItemID: sidebarItemID), let feedIndexPath = indexPathFor(sidebarItemNode) else { return false } + func selectSidebarItemAndArticle(sidebarItemID: SidebarItemIdentifier, articleID: String, isShowingExtractedArticle: Bool, articleWindowScrollY: Int) -> Bool { + guard let sidebarItemNode = nodeFor(sidebarItemID: sidebarItemID), let sidebarItemIndexPath = indexPathFor(sidebarItemNode) else { + return false + } - selectFeed(indexPath: feedIndexPath) { + selectSidebarItem(indexPath: sidebarItemIndexPath) { self.selectArticleInCurrentFeed(articleID, isShowingExtractedArticle: isShowingExtractedArticle, articleWindowScrollY: articleWindowScrollY) } From 9a44b4b70bddb23f7b7827d1166cf84291b75e04 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 19 Jan 2026 09:41:43 -0800 Subject: [PATCH 11/12] Rename savedSearchArticleIds to savedSearchArticleIDs. --- iOS/SceneCoordinator.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 3caf62345..88188c222 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -80,7 +80,7 @@ struct SidebarItemNode: Hashable, Sendable { private var lastSearchScope: SearchScope? private var isSearching: Bool = false private var savedSearchArticles: ArticleArray? - private var savedSearchArticleIds: Set? + private var savedSearchArticleIDs: Set? var isTimelineViewControllerPending = false var isArticleViewControllerPending = false @@ -1015,7 +1015,7 @@ struct SidebarItemNode: Hashable, Sendable { isSearching = true preSearchTimelineFeed = timelineFeed savedSearchArticles = articles - savedSearchArticleIds = Set(articles.map { $0.articleID }) + savedSearchArticleIDs = Set(articles.map { $0.articleID }) setTimelineFeed(nil, animated: true) selectArticle(nil) } @@ -1033,7 +1033,7 @@ struct SidebarItemNode: Hashable, Sendable { lastSearchString = "" lastSearchScope = nil preSearchTimelineFeed = nil - savedSearchArticleIds = nil + savedSearchArticleIDs = nil savedSearchArticles = nil isSearching = false selectArticle(nil) @@ -1057,7 +1057,7 @@ struct SidebarItemNode: Hashable, Sendable { case .global: setTimelineFeed(SmartFeed(delegate: SearchFeedDelegate(searchString: searchString)), animated: true) case .timeline: - setTimelineFeed(SmartFeed(delegate: SearchTimelineFeedDelegate(searchString: searchString, articleIDs: savedSearchArticleIds!)), animated: true) + setTimelineFeed(SmartFeed(delegate: SearchTimelineFeedDelegate(searchString: searchString, articleIDs: savedSearchArticleIDs!)), animated: true) } lastSearchString = searchString From 3f7af09b22dfba04a47d9c0b53374e293918edb2 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 19 Jan 2026 10:47:06 -0800 Subject: [PATCH 12/12] Add function `reconfigureSidebarItem` to update a row given a SidebarItem. Call from displayNameDidChange. --- iOS/SceneCoordinator.swift | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 88188c222..253c75cd4 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -492,6 +492,9 @@ struct SidebarItemNode: Hashable, Sendable { } @objc func displayNameDidChange(_ note: Notification) { + if let sidebarItem = note.object as? SidebarItem { + reconfigureSidebarItem(sidebarItem) + } rebuildBackingStores() } @@ -1687,6 +1690,26 @@ private extension SceneCoordinator { return snapshot } + func reconfigureSidebarItem(_ sidebarItem: SidebarItem) { + var snapshot = mainFeedCollectionViewController.dataSource.snapshot() + + // Find all nodes that represent this sidebar item + var nodesToReconfigure: [SidebarItemNode] = [] + for sidebarItemNode in snapshot.itemIdentifiers { + if let nodeSidebarItem = sidebarItemNode.node.representedObject as? SidebarItem, + nodeSidebarItem.sidebarItemID == sidebarItem.sidebarItemID { + nodesToReconfigure.append(sidebarItemNode) + } + } + + guard !nodesToReconfigure.isEmpty else { + return + } + + snapshot.reconfigureItems(nodesToReconfigure) + mainFeedCollectionViewController.dataSource.apply(snapshot, animatingDifferences: false) + } + func sidebarContains(_ sidebarItem: SidebarItem) -> Bool { let snapshot = mainFeedCollectionViewController.dataSource.snapshot() for sidebarItemNode in snapshot.itemIdentifiers {