Rebuild the side bar by coalescing unread count changes when the read feeds filter is active. Issue #1823

This commit is contained in:
Maurice Parker 2020-02-29 14:15:37 -08:00
parent c17ce1ceaa
commit d1cd205eff
1 changed files with 12 additions and 3 deletions

View File

@ -23,6 +23,7 @@ protocol SidebarDelegate: class {
weak var delegate: SidebarDelegate? weak var delegate: SidebarDelegate?
private let rebuildTreeAndRestoreSelectionQueue = CoalescingQueue(name: "Rebuild Tree Queue", interval: 0.5)
let treeControllerDelegate = WebFeedTreeControllerDelegate() let treeControllerDelegate = WebFeedTreeControllerDelegate()
lazy var treeController: TreeController = { lazy var treeController: TreeController = {
return TreeController(delegate: treeControllerDelegate) return TreeController(delegate: treeControllerDelegate)
@ -89,12 +90,16 @@ protocol SidebarDelegate: class {
guard let representedObject = note.object else { guard let representedObject = note.object else {
return return
} }
if let timelineViewController = representedObject as? TimelineViewController { if let timelineViewController = representedObject as? TimelineViewController {
configureUnreadCountForCellsForRepresentedObjects(timelineViewController.representedObjects) configureUnreadCountForCellsForRepresentedObjects(timelineViewController.representedObjects)
} } else {
else {
configureUnreadCountForCellsForRepresentedObjects([representedObject as AnyObject]) configureUnreadCountForCellsForRepresentedObjects([representedObject as AnyObject])
} }
if let feed = representedObject as? Feed, treeControllerDelegate.isReadFiltered, feed.unreadCount > 0 {
queueRebuildTreeAndRestoreSelection()
}
} }
@objc func containerChildrenDidChange(_ note: Notification) { @objc func containerChildrenDidChange(_ note: Notification) {
@ -321,7 +326,11 @@ protocol SidebarDelegate: class {
// MARK: - API // MARK: - API
func rebuildTreeAndRestoreSelection() { func queueRebuildTreeAndRestoreSelection() {
rebuildTreeAndRestoreSelectionQueue.add(self, #selector(rebuildTreeAndRestoreSelection))
}
@objc func rebuildTreeAndRestoreSelection() {
let savedAccounts = accountNodes let savedAccounts = accountNodes
let savedSelection = selectedNodes let savedSelection = selectedNodes