Update the Feeds list when a Feed's unread count gets above zero and the read filter is on. Issue #1550

This commit is contained in:
Maurice Parker 2020-01-19 16:44:13 -07:00
parent ed23d0ec15
commit 8df8dfdb75
1 changed files with 30 additions and 0 deletions

View File

@ -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(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(statusesDidChange(_:)), name: .StatusesDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(containerChildrenDidChange(_:)), name: .ChildrenDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(containerChildrenDidChange(_:)), name: .ChildrenDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(batchUpdateDidPerform(_:)), name: .BatchUpdateDidPerform, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(batchUpdateDidPerform(_:)), name: .BatchUpdateDidPerform, object: nil)
@ -429,6 +430,24 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
treeControllerDelegate.resetFilterExceptions() 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) { @objc func statusesDidChange(_ note: Notification) {
updateUnreadCount() updateUnreadCount()
} }
@ -1212,6 +1231,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? { func nodeFor(_ indexPath: IndexPath) -> Node? {
guard indexPath.section < shadowTable.count && indexPath.row < shadowTable[indexPath.section].count else { guard indexPath.section < shadowTable.count && indexPath.row < shadowTable[indexPath.section].count else {
return nil return nil