diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index 0d9ab4443..535ed5f0d 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -290,8 +290,8 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, @objc func unreadCountDidChange(_ note: Notification) { - if let object = note.object as? AnyObject { - if objectIsChild(object) { + if let object = note.object { + if objectIsChild(object as AnyObject) { updateUnreadCount() } } diff --git a/Frameworks/Account/Folder.swift b/Frameworks/Account/Folder.swift index addeab88a..ec6b05c7a 100644 --- a/Frameworks/Account/Folder.swift +++ b/Frameworks/Account/Folder.swift @@ -48,6 +48,8 @@ public final class Folder: DisplayNameProvider, Container, UnreadCountProvider { self.account = account self.name = name + + NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil) } // MARK: - Disk Dictionary @@ -116,12 +118,29 @@ public final class Folder: DisplayNameProvider, Container, UnreadCountProvider { children += [feed] return true } + + // MARK: Notifications + + @objc func unreadCountDidChange(_ note: Notification) { + + if let object = note.object { + if objectIsChild(object as AnyObject) { + updateUnreadCount() + } + } + } + } // MARK: - Private private extension Folder { - + + func updateUnreadCount() { + + unreadCount = calculateUnreadCount(children) + } + func childrenContainsFeed(_ feed: Feed) -> Bool { return children.contains(where: { (object) -> Bool in