Refactor status change handling in Account.
This commit is contained in:
parent
f5a5bf91b2
commit
165e74a3f3
@ -34,7 +34,7 @@ public enum AccountType: Int {
|
||||
// TODO: more
|
||||
}
|
||||
|
||||
public final class Account: DisplayNameProvider, Container, Hashable {
|
||||
public final class Account: DisplayNameProvider, UnreadCountProvider, Container, Hashable {
|
||||
|
||||
public struct UserInfoKey {
|
||||
public static let newArticles = "newArticles" // AccountDidDownloadArticles
|
||||
@ -76,6 +76,14 @@ public final class Account: DisplayNameProvider, Container, Hashable {
|
||||
}
|
||||
}
|
||||
|
||||
public var unreadCount = 0 {
|
||||
didSet {
|
||||
if unreadCount != oldValue {
|
||||
postUnreadCountDidChangeNotification()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var refreshInProgress = false {
|
||||
didSet {
|
||||
if refreshInProgress != oldValue {
|
||||
@ -164,11 +172,8 @@ public final class Account: DisplayNameProvider, Container, Hashable {
|
||||
|
||||
let updatedArticleIDs = updatedStatuses.articleIDs()
|
||||
let updatedArticles = Set(articles.filter{ updatedArticleIDs.contains($0.articleID) })
|
||||
let updatedFeeds = Set(articles.flatMap{ $0.feed })
|
||||
|
||||
updateUnreadCounts(for: updatedFeeds)
|
||||
|
||||
NotificationCenter.default.post(name: .StatusesDidChange, object: self, userInfo: [UserInfoKey.statuses: updatedStatuses, UserInfoKey.articles: updatedArticles, UserInfoKey.feeds: updatedFeeds])
|
||||
|
||||
noteStatusesForArticlesDidChange(updatedArticles)
|
||||
}
|
||||
|
||||
public func ensureFolder(with name: String) -> Folder? {
|
||||
@ -433,6 +438,23 @@ private extension Account {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func updateUnreadCount() {
|
||||
|
||||
unreadCount = calculateUnreadCount(children)
|
||||
}
|
||||
|
||||
func noteStatusesForArticlesDidChange(articles: Set<Article>) {
|
||||
|
||||
let feeds = articles.feeds()
|
||||
let statuses = articles.statuses()
|
||||
|
||||
// .UnreadCountDidChange notification will get sent to Folder and Account objects,
|
||||
// which will update their own unread counts.
|
||||
updateUnreadCounts(for: feeds)
|
||||
|
||||
NotificationCenter.default.post(name: .StatusesDidChange, object: self, userInfo: [UserInfoKey.statuses: statuses, UserInfoKey.articles: articles, UserInfoKey.feeds: feeds])
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - OPMLRepresentable
|
||||
|
@ -41,3 +41,14 @@ 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 })
|
||||
}
|
||||
}
|
||||
|
10
ToDo.opml
10
ToDo.opml
@ -8,15 +8,15 @@
|
||||
<dateCreated>Tue, 12 Sep 2017 20:15:17 GMT</dateCreated>
|
||||
<expansionState>0,23,24,27,31,37,45,46,48,63,68</expansionState>
|
||||
<vertScrollState>0</vertScrollState>
|
||||
<windowTop>630</windowTop>
|
||||
<windowLeft>38</windowLeft>
|
||||
<windowRight>770</windowRight>
|
||||
<windowBottom>1389</windowBottom>
|
||||
<windowTop>208</windowTop>
|
||||
<windowLeft>30</windowLeft>
|
||||
<windowRight>762</windowRight>
|
||||
<windowBottom>967</windowBottom>
|
||||
</head>
|
||||
<body>
|
||||
<outline text="App">
|
||||
<outline text="Make adding a Folder work — accounts don’t show up in Accounts popup"/>
|
||||
<outline text="Update unread counts for folders and accounts when statuses change"/>
|
||||
<outline text="Update unread counts for folders and accounts when unread counts change"/>
|
||||
<outline text="Update Sparkle"/>
|
||||
<outline text="Use new app icon"/>
|
||||
<outline text="Set -NSApplicationCrashOnExceptions YES"/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user