Treat Folder and Account as Container in SidebarTreeControllerDelegate. Also: add pseudo feeds.

This commit is contained in:
Brent Simmons 2017-11-19 12:59:37 -08:00
parent d901bbb218
commit 55be38269f

View File

@ -18,11 +18,8 @@ final class SidebarTreeControllerDelegate: TreeControllerDelegate {
if node.isRoot { if node.isRoot {
return childNodesForRootNode(node) return childNodesForRootNode(node)
} }
if node.representedObject is Folder { if node.representedObject is Container {
return childNodesForFolderNode(node) return childNodesForContainerNode(node)
}
if node.representedObject is Account {
return childNodesForAccount(node)
} }
return nil return nil
@ -34,28 +31,23 @@ private extension SidebarTreeControllerDelegate {
func childNodesForRootNode(_ rootNode: Node) -> [Node]? { func childNodesForRootNode(_ rootNode: Node) -> [Node]? {
// The top-level nodes are pseudo-feeds (All Unread, Starred, etc.) and accounts. // The top-level nodes are pseudo-feeds (All Unread, Starred, etc.) and accounts.
// TODO: pseudo-feeds
return sortedAccountNodes(rootNode) return pseudoFeedNodes(rootNode) + sortedAccountNodes(rootNode)
} }
func childNodesForAccount(_ accountNode: Node) -> [Node]? { func pseudoFeedNodes(_ rootNode: Node) -> [Node] {
let account = accountNode.representedObject as! Account // The appDelegates pseudoFeeds are already sorted properly.
return childNodesForContainerNode(accountNode, account.children) return appDelegate.pseudoFeeds.map { rootNode.createChildNode($0) }
} }
func childNodesForFolderNode(_ folderNode: Node) -> [Node]? { func childNodesForContainerNode(_ containerNode: Node) -> [Node]? {
let folder = folderNode.representedObject as! Folder let container = containerNode.representedObject as! Container
return childNodesForContainerNode(folderNode, folder.children)
}
func childNodesForContainerNode(_ containerNode: Node, _ children: [AnyObject]) -> [Node]? {
var updatedChildNodes = [Node]() var updatedChildNodes = [Node]()
children.forEach { (representedObject) in container.children.forEach { (representedObject) in
if let existingNode = containerNode.childNodeRepresentingObject(representedObject) { if let existingNode = containerNode.childNodeRepresentingObject(representedObject) {
if !updatedChildNodes.contains(existingNode) { if !updatedChildNodes.contains(existingNode) {