From 47cf018143f7e306ed2d99bc33456fc84cc8f1ab Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Fri, 14 Sep 2018 22:06:03 -0700 Subject: [PATCH] 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. --- Frameworks/Account/Account.swift | 9 +++++++++ Frameworks/Account/Feed.swift | 13 +++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) 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() } }