From 8df8dfdb752b5e1018e9d313106e3bcc602a40c6 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sun, 19 Jan 2020 16:44:13 -0700 Subject: [PATCH] Update the Feeds list when a Feed's unread count gets above zero and the read filter is on. Issue #1550 --- iOS/SceneCoordinator.swift | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 0ef3d0e61..00f936ebe 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -290,6 +290,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { } 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) @@ -429,6 +430,24 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { treeControllerDelegate.resetFilterExceptions() } + @objc func unreadCountDidChange(_ note: Notification) { + // If we are filtering reads, the new unread count is greater than 1, and the feed isn't shown then continue + guard let feed = note.object as? Feed, isReadFeedsFiltered, feed.unreadCount > 0, !shadowTableContains(feed) else { + return + } + + for section in shadowTable { + for node in section { + if let feed = node.representedObject as? Feed, let feedID = feed.feedID { + treeControllerDelegate.addFilterException(feedID) + } + } + } + + rebuildBackingStores() + treeControllerDelegate.resetFilterExceptions() + } + @objc func statusesDidChange(_ note: Notification) { updateUnreadCount() } @@ -1211,6 +1230,17 @@ private extension SceneCoordinator { } } + + func shadowTableContains(_ feed: Feed) -> Bool { + for section in shadowTable { + for node in section { + if let nodeFeed = node.representedObject as? Feed, nodeFeed.feedID == feed.feedID { + return true + } + } + } + return false + } func nodeFor(_ indexPath: IndexPath) -> Node? { guard indexPath.section < shadowTable.count && indexPath.row < shadowTable[indexPath.section].count else {