From d1cd205eff7c95324b91d5cb42665b58a823869c Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sat, 29 Feb 2020 14:15:37 -0800 Subject: [PATCH] Rebuild the side bar by coalescing unread count changes when the read feeds filter is active. Issue #1823 --- .../Sidebar/SidebarViewController.swift | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Mac/MainWindow/Sidebar/SidebarViewController.swift b/Mac/MainWindow/Sidebar/SidebarViewController.swift index 0af6ad40d..76829fc51 100644 --- a/Mac/MainWindow/Sidebar/SidebarViewController.swift +++ b/Mac/MainWindow/Sidebar/SidebarViewController.swift @@ -23,6 +23,7 @@ protocol SidebarDelegate: class { weak var delegate: SidebarDelegate? + private let rebuildTreeAndRestoreSelectionQueue = CoalescingQueue(name: "Rebuild Tree Queue", interval: 0.5) let treeControllerDelegate = WebFeedTreeControllerDelegate() lazy var treeController: TreeController = { return TreeController(delegate: treeControllerDelegate) @@ -89,12 +90,16 @@ protocol SidebarDelegate: class { guard let representedObject = note.object else { return } + if let timelineViewController = representedObject as? TimelineViewController { configureUnreadCountForCellsForRepresentedObjects(timelineViewController.representedObjects) - } - else { + } else { configureUnreadCountForCellsForRepresentedObjects([representedObject as AnyObject]) } + + if let feed = representedObject as? Feed, treeControllerDelegate.isReadFiltered, feed.unreadCount > 0 { + queueRebuildTreeAndRestoreSelection() + } } @objc func containerChildrenDidChange(_ note: Notification) { @@ -321,7 +326,11 @@ protocol SidebarDelegate: class { // MARK: - API - func rebuildTreeAndRestoreSelection() { + func queueRebuildTreeAndRestoreSelection() { + rebuildTreeAndRestoreSelectionQueue.add(self, #selector(rebuildTreeAndRestoreSelection)) + } + + @objc func rebuildTreeAndRestoreSelection() { let savedAccounts = accountNodes let savedSelection = selectedNodes