Avoid a compiler bug with constrained Set extensions. Add a notification observation to Account when unread count changes.

This commit is contained in:
Brent Simmons 2017-10-12 21:02:27 -07:00
parent 165e74a3f3
commit 4897181909
2 changed files with 10 additions and 13 deletions

View File

@ -135,6 +135,8 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
NotificationCenter.default.addObserver(self, selector: #selector(downloadProgressDidChange(_:)), name: .DownloadProgressDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
pullObjectsFromDisk()
}
@ -286,6 +288,11 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
NotificationCenter.default.post(name: .AccountRefreshProgressDidChange, object: self)
}
@objc func unreadCountDidChange(_ note: Notification) {
}
// MARK: - Equatable
public class func ==(lhs: Account, rhs: Account) -> Bool {
@ -444,10 +451,10 @@ private extension Account {
unreadCount = calculateUnreadCount(children)
}
func noteStatusesForArticlesDidChange(articles: Set<Article>) {
func noteStatusesForArticlesDidChange(_ articles: Set<Article>) {
let feeds = articles.feeds()
let statuses = articles.statuses()
let feeds = Set(articles.flatMap { $0.feed })
let statuses = Set(articles.map { $0.status })
// .UnreadCountDidChange notification will get sent to Folder and Account objects,
// which will update their own unread counts.

View File

@ -42,13 +42,3 @@ public extension Article {
}
}
public extension Set where Element == Article {
public func feeds() -> Set<Feed> {
return Set(flatMap { $0.feed })
}
public func statuses() -> Set<ArticleStatus> {
return Set(map { $0.articleStatus })
}
}