Avoid a compiler bug with constrained Set extensions. Add a notification observation to Account when unread count changes.
This commit is contained in:
parent
165e74a3f3
commit
4897181909
|
@ -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(downloadProgressDidChange(_:)), name: .DownloadProgressDidChange, object: nil)
|
||||||
|
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
||||||
|
|
||||||
pullObjectsFromDisk()
|
pullObjectsFromDisk()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,6 +288,11 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||||
NotificationCenter.default.post(name: .AccountRefreshProgressDidChange, object: self)
|
NotificationCenter.default.post(name: .AccountRefreshProgressDidChange, object: self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc func unreadCountDidChange(_ note: Notification) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Equatable
|
// MARK: - Equatable
|
||||||
|
|
||||||
public class func ==(lhs: Account, rhs: Account) -> Bool {
|
public class func ==(lhs: Account, rhs: Account) -> Bool {
|
||||||
|
@ -444,10 +451,10 @@ private extension Account {
|
||||||
unreadCount = calculateUnreadCount(children)
|
unreadCount = calculateUnreadCount(children)
|
||||||
}
|
}
|
||||||
|
|
||||||
func noteStatusesForArticlesDidChange(articles: Set<Article>) {
|
func noteStatusesForArticlesDidChange(_ articles: Set<Article>) {
|
||||||
|
|
||||||
let feeds = articles.feeds()
|
let feeds = Set(articles.flatMap { $0.feed })
|
||||||
let statuses = articles.statuses()
|
let statuses = Set(articles.map { $0.status })
|
||||||
|
|
||||||
// .UnreadCountDidChange notification will get sent to Folder and Account objects,
|
// .UnreadCountDidChange notification will get sent to Folder and Account objects,
|
||||||
// which will update their own unread counts.
|
// which will update their own unread counts.
|
||||||
|
|
|
@ -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 })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue