Store feed.unreadCount with the Account rather than the feed. This is part of making it so that feeds no longer have to be uniqued.

This commit is contained in:
Brent Simmons 2018-09-14 22:06:03 -07:00
parent 28d084e246
commit 47cf018143
2 changed files with 18 additions and 4 deletions

View File

@ -63,6 +63,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
private let feedsPath: ODBPath private let feedsPath: ODBPath
private let feedsTable: ODBTable private let feedsTable: ODBTable
private var unreadCounts = [String: Int]() // [feedID: Int]
private let opmlFilePath: String private let opmlFilePath: String
private struct SettingsKey { private struct SettingsKey {
@ -447,6 +448,14 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
return opml 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 // MARK: - Debug
public func debugDropConditionalGetInfo() { public func debugDropConditionalGetInfo() {

View File

@ -110,11 +110,16 @@ public final class Feed: DisplayNameProvider, UnreadCountProvider, Hashable {
// MARK: - UnreadCountProvider // MARK: - UnreadCountProvider
public var unreadCount = 0 { public var unreadCount: Int {
didSet { get {
if unreadCount != oldValue { return account?.unreadCount(for: self) ?? 0
postUnreadCountDidChangeNotification()
} }
set {
if unreadCount == newValue {
return
}
account?.setUnreadCount(newValue, for: self)
postUnreadCountDidChangeNotification()
} }
} }