diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index 79c28212a..0ae747f34 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -63,6 +63,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, private let feedsPath: ODBPath private let feedsTable: ODBTable + private var unreadCounts = [String: Int]() // [feedID: Int] private let opmlFilePath: String private struct SettingsKey { @@ -447,6 +448,14 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, return opml } + public func unreadCount(for feed: Feed) -> Int { + return unreadCounts[feed.feedID] ?? 0 + } + + public func setUnreadCount(_ unreadCount: Int, for feed: Feed) { + unreadCounts[feed.feedID] = unreadCount + } + // MARK: - Debug public func debugDropConditionalGetInfo() { diff --git a/Frameworks/Account/Feed.swift b/Frameworks/Account/Feed.swift index c3c793b03..2b4b1aff5 100644 --- a/Frameworks/Account/Feed.swift +++ b/Frameworks/Account/Feed.swift @@ -110,11 +110,16 @@ public final class Feed: DisplayNameProvider, UnreadCountProvider, Hashable { // MARK: - UnreadCountProvider - public var unreadCount = 0 { - didSet { - if unreadCount != oldValue { - postUnreadCountDidChangeNotification() + public var unreadCount: Int { + get { + return account?.unreadCount(for: self) ?? 0 + } + set { + if unreadCount == newValue { + return } + account?.setUnreadCount(newValue, for: self) + postUnreadCountDidChangeNotification() } }