Handle unread count change notifications in Folder. Update the unread count when needed.
This commit is contained in:
parent
505f4bcdba
commit
3ea60cb461
|
@ -290,8 +290,8 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||||
|
|
||||||
@objc func unreadCountDidChange(_ note: Notification) {
|
@objc func unreadCountDidChange(_ note: Notification) {
|
||||||
|
|
||||||
if let object = note.object as? AnyObject {
|
if let object = note.object {
|
||||||
if objectIsChild(object) {
|
if objectIsChild(object as AnyObject) {
|
||||||
updateUnreadCount()
|
updateUnreadCount()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,8 @@ public final class Folder: DisplayNameProvider, Container, UnreadCountProvider {
|
||||||
|
|
||||||
self.account = account
|
self.account = account
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Disk Dictionary
|
// MARK: - Disk Dictionary
|
||||||
|
@ -116,12 +118,29 @@ public final class Folder: DisplayNameProvider, Container, UnreadCountProvider {
|
||||||
children += [feed]
|
children += [feed]
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: Notifications
|
||||||
|
|
||||||
|
@objc func unreadCountDidChange(_ note: Notification) {
|
||||||
|
|
||||||
|
if let object = note.object {
|
||||||
|
if objectIsChild(object as AnyObject) {
|
||||||
|
updateUnreadCount()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Private
|
// MARK: - Private
|
||||||
|
|
||||||
private extension Folder {
|
private extension Folder {
|
||||||
|
|
||||||
|
func updateUnreadCount() {
|
||||||
|
|
||||||
|
unreadCount = calculateUnreadCount(children)
|
||||||
|
}
|
||||||
|
|
||||||
func childrenContainsFeed(_ feed: Feed) -> Bool {
|
func childrenContainsFeed(_ feed: Feed) -> Bool {
|
||||||
|
|
||||||
return children.contains(where: { (object) -> Bool in
|
return children.contains(where: { (object) -> Bool in
|
||||||
|
|
Loading…
Reference in New Issue