Persist the Feeds Read filter across application launches. Issue #1349

This commit is contained in:
Maurice Parker
2019-11-26 20:23:12 -06:00
parent 8cb25e7c5e
commit ebd7f4904d
7 changed files with 53 additions and 20 deletions

View File

@@ -1098,6 +1098,7 @@ private extension Account {
self.fetchingAllUnreadCounts = false
self.updateUnreadCount()
self.isUnreadCountsInitialized = true
self.postUnreadCountDidInitializeNotification()
return
}
@@ -1111,9 +1112,11 @@ private extension Account {
feed.unreadCount = 0
}
}
self.fetchingAllUnreadCounts = false
self.updateUnreadCount()
self.isUnreadCountsInitialized = true
self.postUnreadCountDidInitializeNotification()
}
}
}

View File

@@ -102,6 +102,7 @@ public final class AccountManager: UnreadCountProvider {
readAccountsFromDisk()
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(accountStateDidChange(_:)), name: .AccountStateDidChange, object: nil)
@@ -269,6 +270,15 @@ public final class AccountManager: UnreadCountProvider {
// MARK: - Notifications
@objc func unreadCountDidInitialize(_ notification: Notification) {
guard let _ = notification.object as? Account else {
return
}
if isUnreadCountsInitialized {
postUnreadCountDidInitializeNotification()
}
}
@objc dynamic func unreadCountDidChange(_ notification: Notification) {
guard let _ = notification.object as? Account else {
return

View File

@@ -9,7 +9,7 @@
import Foundation
public extension Notification.Name {
static let UnreadCountDidInitialize = Notification.Name("UnreadCountDidInitialize")
static let UnreadCountDidChange = Notification.Name(rawValue: "UnreadCountDidChange")
}
@@ -24,6 +24,10 @@ public protocol UnreadCountProvider {
public extension UnreadCountProvider {
func postUnreadCountDidInitializeNotification() {
NotificationCenter.default.post(name: .UnreadCountDidInitialize, object: self, userInfo: nil)
}
func postUnreadCountDidChangeNotification() {
NotificationCenter.default.post(name: .UnreadCountDidChange, object: self, userInfo: nil)
}