Rename Feed to SidebarItem. Fix #4752.

This commit is contained in:
Brent Simmons committed 2025-11-02 12:17:44 -08:00
1 parent 5ce9ba3a87
commit 49d2d6dfe6
16 files changed
+103 -103

No files matched your search

@@ -76,7 +76,7 @@ extension MainFeedCollectionViewController: UICollectionViewDropDelegate {
return UICollectionViewDropProposal(operation: .forbidden)
}
guard let destFeed = coordinator.nodeFor(destIndexPath)?.representedObject as? Feed,
guard let destFeed = coordinator.nodeFor(destIndexPath)?.representedObject as? SidebarItem,
let destAccount = destFeed.account,
let destCell = collectionView.cellForItem(at: destIndexPath) else {
return UICollectionViewDropProposal(operation: .forbidden)
@@ -325,14 +325,14 @@ class MainFeedCollectionViewController: UICollectionViewController, UndoableComm
}
override func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
guard let feed = coordinator.nodeFor(indexPath)?.representedObject as? Feed else {
guard let sidebarItem = coordinator.nodeFor(indexPath)?.representedObject as? SidebarItem else {
return nil
}
if feed is WebFeed {
if sidebarItem is WebFeed {
return makeWebFeedContextMenu(indexPath: indexPath, includeDeleteRename: true)
} else if feed is Folder {
} else if sidebarItem is Folder {
return makeFolderContextMenu(indexPath: indexPath)
} else if feed is PseudoFeed {
} else if sidebarItem is PseudoFeed {
return makePseudoFeedContextMenu(indexPath: indexPath)
} else {
return nil
@@ -514,14 +514,14 @@ class MainFeedCollectionViewController: UICollectionViewController, UndoableComm
}
func configureIcon(_ cell: MainFeedCollectionViewCell, _ indexPath: IndexPath) {
guard let node = coordinator.nodeFor(indexPath), let feed = node.representedObject as? Feed, let sidebarItemID = feed.sidebarItemID else {
guard let node = coordinator.nodeFor(indexPath), let sidebarItem = node.representedObject as? SidebarItem, let sidebarItemID = sidebarItem.sidebarItemID else {
return
}
cell.iconImage = IconImageCache.shared.imageFor(sidebarItemID)
}
func configureIcon(_ cell: MainFeedCollectionViewFolderCell, _ indexPath: IndexPath) {
guard let node = coordinator.nodeFor(indexPath), let feed = node.representedObject as? Feed, let sidebarItemID = feed.sidebarItemID else {
guard let node = coordinator.nodeFor(indexPath), let sidebarItem = node.representedObject as? SidebarItem, let sidebarItemID = sidebarItem.sidebarItemID else {
return
}
cell.iconImage = IconImageCache.shared.imageFor(sidebarItemID)
@@ -534,9 +534,9 @@ class MainFeedCollectionViewController: UICollectionViewController, UndoableComm
func applyToCellsForRepresentedObject(_ representedObject: AnyObject, _ completion: (MainFeedCollectionViewCell, IndexPath) -> Void) {
applyToAvailableCells { (cell, indexPath) in
if let node = coordinator.nodeFor(indexPath),
let representedFeed = representedObject as? Feed,
let candidate = node.representedObject as? Feed,
representedFeed.sidebarItemID == candidate.sidebarItemID {
let representedSidebarItem = representedObject as? SidebarItem,
let candidateSidebarItem = node.representedObject as? SidebarItem,
representedSidebarItem.sidebarItemID == candidateSidebarItem.sidebarItemID {
completion(cell, indexPath)
}
}
@@ -564,9 +564,9 @@ class MainFeedCollectionViewController: UICollectionViewController, UndoableComm
indentationLevel = 1
}
if let feed = node.representedObject as? Feed {
cell.feedTitle.text = feed.nameForDisplay
cell.unreadCount = feed.unreadCount
if let sidebarItem = node.representedObject as? SidebarItem {
cell.feedTitle.text = sidebarItem.nameForDisplay
cell.unreadCount = sidebarItem.unreadCount
cell.indentationLevel = indentationLevel
configureIcon(cell, indexPath)
}
@@ -1082,17 +1082,17 @@ extension MainFeedCollectionViewController {
}
func markAllAsReadAction(indexPath: IndexPath) -> UIAction? {
guard let feed = coordinator.nodeFor(indexPath)?.representedObject as? Feed,
guard let sidebarItem = coordinator.nodeFor(indexPath)?.representedObject as? SidebarItem,
let contentView = self.collectionView.cellForItem(at: indexPath)?.contentView,
feed.unreadCount > 0 else {
sidebarItem.unreadCount > 0 else {
return nil
}
let localizedMenuText = NSLocalizedString("Mark All as Read in “%@”", comment: "Command")
let title = NSString.localizedStringWithFormat(localizedMenuText as NSString, feed.nameForDisplay) as String
let title = NSString.localizedStringWithFormat(localizedMenuText as NSString, sidebarItem.nameForDisplay) as String
let action = UIAction(title: title, image: AppAssets.markAllAsReadImage) { [weak self] action in
MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView) { [weak self] in
if let articles = try? feed.fetchUnreadArticles() {
if let articles = try? sidebarItem.fetchUnreadArticles() {
self?.coordinator.markAllAsRead(Array(articles))
}
}
@@ -1124,10 +1124,10 @@ extension MainFeedCollectionViewController {
func rename(indexPath: IndexPath) {
guard let feed = coordinator.nodeFor(indexPath)?.representedObject as? Feed 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, feed.nameForDisplay) as String
let title = NSString.localizedStringWithFormat(formatString as NSString, sidebarItem.nameForDisplay) as String
let alertController = UIAlertController(title: title, message: nil, preferredStyle: .alert)
@@ -1141,7 +1141,7 @@ extension MainFeedCollectionViewController {
return
}
if let webFeed = feed as? WebFeed {
if let webFeed = sidebarItem as? WebFeed {
webFeed.rename(to: name) { result in
switch result {
case .success:
@@ -1150,7 +1150,7 @@ extension MainFeedCollectionViewController {
self?.presentError(error)
}
}
} else if let folder = feed as? Folder {
} else if let folder = sidebarItem as? Folder {
folder.rename(to: name) { result in
switch result {
case .success:
@@ -1167,7 +1167,7 @@ extension MainFeedCollectionViewController {
alertController.preferredAction = renameAction
alertController.addTextField() { textField in
textField.text = feed.nameForDisplay
textField.text = sidebarItem.nameForDisplay
textField.placeholder = NSLocalizedString("Name", comment: "Name")
}
@@ -1178,18 +1178,18 @@ extension MainFeedCollectionViewController {
}
func delete(indexPath: IndexPath) {
guard let feed = coordinator.nodeFor(indexPath)?.representedObject as? Feed else { return }
guard let sidebarItem = coordinator.nodeFor(indexPath)?.representedObject as? SidebarItem else { return }
let title: String
let message: String
if feed is Folder {
if sidebarItem is Folder {
title = NSLocalizedString("Delete Folder", comment: "Delete folder")
let localizedInformativeText = NSLocalizedString("Are you sure you want to delete the “%@” folder?", comment: "Folder delete text")
message = NSString.localizedStringWithFormat(localizedInformativeText as NSString, feed.nameForDisplay) as String
message = NSString.localizedStringWithFormat(localizedInformativeText as NSString, sidebarItem.nameForDisplay) as String
} else {
title = NSLocalizedString("Delete Feed", comment: "Delete feed")
let localizedInformativeText = NSLocalizedString("Are you sure you want to delete the “%@” feed?", comment: "Feed delete text")
message = NSString.localizedStringWithFormat(localizedInformativeText as NSString, feed.nameForDisplay) as String
message = NSString.localizedStringWithFormat(localizedInformativeText as NSString, sidebarItem.nameForDisplay) as String
}
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
@@ -33,7 +33,7 @@ final class MainTimelineViewController: UITableViewController, UndoableCommandRu
var undoableCommands = [UndoableCommand]()
let scrollPositionQueue = CoalescingQueue(name: "Timeline Scroll Position", interval: 0.3, maxInterval: 1.0)
private var timelineFeed: Feed? {
private var timelineFeed: SidebarItem? {
assert(coordinator != nil)
return coordinator?.timelineFeed
}
+25 -25
View File
@@ -31,7 +31,7 @@ struct FeedNode: Hashable {
init(_ node: Node) {
self.node = node
self.sidebarItemID = (node.representedObject as! Feed).sidebarItemID!
self.sidebarItemID = (node.representedObject as! SidebarItem).sidebarItemID!
}
func hash(into hasher: inout Hasher) {
@@ -72,7 +72,7 @@ final class SceneCoordinator: NSObject, UndoableCommandRunner {
// Flattened tree structure for the Sidebar
private var shadowTable = [(sectionID: String, feedNodes: [FeedNode])]()
private(set) var preSearchTimelineFeed: Feed?
private(set) var preSearchTimelineFeed: SidebarItem?
private var lastSearchString = ""
private var lastSearchScope: SearchScope? = nil
private var isSearching: Bool = false
@@ -157,7 +157,7 @@ final class SceneCoordinator: NSObject, UndoableCommandRunner {
}
private var exceptionArticleFetcher: ArticleFetcher?
private(set) var timelineFeed: Feed? {
private(set) var timelineFeed: SidebarItem? {
didSet {
mainTimelineViewController?.updateNavigationBarTitle(timelineFeed?.nameForDisplay ?? "")
updateNavigationBarSubtitles(nil)
@@ -692,8 +692,8 @@ final class SceneCoordinator: NSObject, UndoableCommandRunner {
func nodeFor(sidebarItemID: SidebarItemIdentifier) -> Node? {
return treeController.rootNode.descendantNode(where: { node in
if let feed = node.representedObject as? Feed {
return feed.sidebarItemID == sidebarItemID
if let sidebarItem = node.representedObject as? SidebarItem {
return sidebarItem.sidebarItemID == sidebarItemID
} else {
return false
}
@@ -835,9 +835,9 @@ final class SceneCoordinator: NSObject, UndoableCommandRunner {
return indexPathFor(node)
}
func selectFeed(_ feed: Feed?, animations: Animations = [], deselectArticle: Bool = true, completion: (() -> Void)? = nil) {
func selectFeed(_ sidebarItem: SidebarItem?, animations: Animations = [], deselectArticle: Bool = true, completion: (() -> Void)? = nil) {
let indexPath: IndexPath? = {
if let feed = feed, let indexPath = indexPathFor(feed as AnyObject) {
if let sidebarItem, let indexPath = indexPathFor(sidebarItem as AnyObject) {
return indexPath
} else {
return nil
@@ -861,11 +861,11 @@ final class SceneCoordinator: NSObject, UndoableCommandRunner {
selectArticle(nil)
}
if let ip = indexPath, let node = nodeFor(ip), let feed = node.representedObject as? Feed {
self.activityManager.selecting(feed: feed)
if let ip = indexPath, let node = nodeFor(ip), let sidebarItem = node.representedObject as? SidebarItem {
self.activityManager.selecting(sidebarItem: sidebarItem)
self.rootSplitViewController.show(.supplementary)
setTimelineFeed(feed, animated: false) {
setTimelineFeed(sidebarItem, animated: false) {
if self.isReadFeedsFiltered {
self.rebuildBackingStores()
}
@@ -1499,8 +1499,8 @@ private extension SceneCoordinator {
articleDictionaryNeedsUpdate = false
}
func ensureFeedIsAvailableToSelect(_ feed: Feed, completion: @escaping () -> Void) {
addToFilterExceptionsIfNecessary(feed)
func ensureFeedIsAvailableToSelect(_ sidebarItem: SidebarItem, completion: @escaping () -> Void) {
addToFilterExceptionsIfNecessary(sidebarItem)
addShadowTableToFilterExceptions()
rebuildBackingStores(completion: {
@@ -1509,15 +1509,15 @@ private extension SceneCoordinator {
})
}
func addToFilterExceptionsIfNecessary(_ feed: Feed?) {
if isReadFeedsFiltered, let sidebarItemID = feed?.sidebarItemID {
if feed is SmartFeed {
func addToFilterExceptionsIfNecessary(_ sidebarItem: SidebarItem?) {
if isReadFeedsFiltered, let sidebarItemID = sidebarItem?.sidebarItemID {
if sidebarItem is SmartFeed {
treeControllerDelegate.addFilterException(sidebarItemID)
} else if let folderFeed = feed as? Folder {
} else if let folderFeed = sidebarItem as? Folder {
if folderFeed.account?.existingFolder(withID: folderFeed.folderID) != nil {
treeControllerDelegate.addFilterException(sidebarItemID)
}
} else if let webFeed = feed as? WebFeed {
} else if let webFeed = sidebarItem as? WebFeed {
if webFeed.account?.existingWebFeed(withWebFeedID: webFeed.webFeedID) != nil {
treeControllerDelegate.addFilterException(sidebarItemID)
addParentFolderToFilterExceptions(webFeed)
@@ -1526,8 +1526,8 @@ private extension SceneCoordinator {
}
}
func addParentFolderToFilterExceptions(_ feed: Feed) {
guard let node = treeController.rootNode.descendantNodeRepresentingObject(feed as AnyObject),
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
@@ -1539,7 +1539,7 @@ private extension SceneCoordinator {
func addShadowTableToFilterExceptions() {
for section in shadowTable {
for feedNode in section.feedNodes {
if let feed = feedNode.node.representedObject as? Feed, let sidebarItemID = feed.sidebarItemID {
if let feed = feedNode.node.representedObject as? SidebarItem, let sidebarItemID = feed.sidebarItemID {
treeControllerDelegate.addFilterException(sidebarItemID)
}
}
@@ -1669,10 +1669,10 @@ private extension SceneCoordinator {
return ShadowTableChanges(deletes: deletes, inserts: inserts, moves: moves, rowChanges: changes)
}
func shadowTableContains(_ feed: Feed) -> Bool {
func shadowTableContains(_ sidebarItem: SidebarItem) -> Bool {
for section in shadowTable {
for feedNode in section.feedNodes {
if let nodeFeed = feedNode.node.representedObject as? Feed, nodeFeed.sidebarItemID == feed.sidebarItemID {
if let nodeSidebarItem = feedNode.node.representedObject as? SidebarItem, nodeSidebarItem.sidebarItemID == sidebarItem.sidebarItemID {
return true
}
}
@@ -1693,8 +1693,8 @@ private extension SceneCoordinator {
return indexPathFor(node)
}
func setTimelineFeed(_ feed: Feed?, animated: Bool, completion: (() -> Void)? = nil) {
timelineFeed = feed
func setTimelineFeed(_ sidebarItem: SidebarItem?, animated: Bool, completion: (() -> Void)? = nil) {
timelineFeed = sidebarItem
fetchAndReplaceArticlesAsync(animated: animated) {
self.mainTimelineViewController?.reinitializeArticles(resetScroll: true)