Include updated feeds in StatusesDidChange notification, so that updating unread counts will work.

This commit is contained in:
Brent Simmons 2017-10-08 22:25:33 -07:00
parent 6572631866
commit 77042f67b5
2 changed files with 16 additions and 3 deletions

View File

@ -39,7 +39,9 @@ public final class Account: DisplayNameProvider, Container, Hashable {
public struct UserInfoKey {
public static let newArticles = "newArticles" // AccountDidDownloadArticles
public static let updatedArticles = "updatedArticles" // AccountDidDownloadArticles
public static let statuses = "statuses" // ArticleStatusesDidChange
public static let statuses = "statuses" // StatusesDidChange
public static let articles = "articles" // StatusesDidChange
public static let feeds = "feeds" // StatusesDidChange
}
public let accountID: String
@ -157,7 +159,12 @@ public final class Account: DisplayNameProvider, Container, Hashable {
public func markArticles(_ articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) {
if let updatedStatuses = database.mark(articles, statusKey: statusKey, flag: flag) {
NotificationCenter.default.post(name: .StatusesDidChange, object: self, userInfo: [UserInfoKey.statuses: updatedStatuses])
let updatedArticleIDs = updatedStatuses.articleIDs()
let updatedArticles = Set(articles.filter{ updatedArticleIDs.contains($0.articleID) })
let updatedFeeds = Set(articles.flatMap{ $0.feed })
NotificationCenter.default.post(name: .StatusesDidChange, object: self, userInfo: [UserInfoKey.statuses: updatedStatuses, UserInfoKey.articles: updatedArticles, UserInfoKey.feeds: updatedFeeds])
}
}

View File

@ -29,9 +29,15 @@ public extension Feed {
public extension Article {
var account: Account? {
public var account: Account? {
get {
return AccountManager.shared.existingAccount(with: accountID)
}
}
public var feed: Feed? {
get {
return account?.existingFeed(with: feedID)
}
}
}