Refresh feeds and sidebar when downloaded articles update all their unread counts. Issue #1430

This commit is contained in:
Maurice Parker 2019-12-10 18:17:54 -07:00
parent 6f2e6a7d9a
commit e303d64c1d
3 changed files with 16 additions and 2 deletions

View File

@ -26,6 +26,7 @@ public extension Notification.Name {
static let AccountRefreshDidBegin = Notification.Name(rawValue: "AccountRefreshDidBegin")
static let AccountRefreshDidFinish = Notification.Name(rawValue: "AccountRefreshDidFinish")
static let AccountRefreshProgressDidChange = Notification.Name(rawValue: "AccountRefreshProgressDidChange")
static let DownloadArticlesDidUpdateUnreadCounts = Notification.Name(rawValue: "DownloadArticlesDidUpdateUnreadCounts")
static let AccountDidDownloadArticles = Notification.Name(rawValue: "AccountDidDownloadArticles")
static let AccountStateDidChange = Notification.Name(rawValue: "AccountStateDidChange")
static let StatusesDidChange = Notification.Name(rawValue: "StatusesDidChange")
@ -601,7 +602,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
structureDidChange()
}
public func updateUnreadCounts(for webFeeds: Set<WebFeed>) {
public func updateUnreadCounts(for webFeeds: Set<WebFeed>, completion: (() -> Void)? = nil) {
if webFeeds.isEmpty {
return
}
@ -612,6 +613,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
webFeed.unreadCount = unreadCount
}
}
completion?()
}
}
@ -722,7 +724,9 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
self.existingWebFeed(withWebFeedID: key)
})
if let newArticles = newArticles, !newArticles.isEmpty {
self.updateUnreadCounts(for: webFeeds)
self.updateUnreadCounts(for: webFeeds) {
NotificationCenter.default.post(name: .DownloadArticlesDidUpdateUnreadCounts, object: self, userInfo: nil)
}
userInfo[UserInfoKey.newArticles] = newArticles
}
if let updatedArticles = updatedArticles, !updatedArticles.isEmpty {

View File

@ -65,6 +65,7 @@ protocol SidebarDelegate: class {
NotificationCenter.default.addObserver(self, selector: #selector(webFeedSettingDidChange(_:)), name: .WebFeedSettingDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange(_:)), name: .DisplayNameDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(userDidRequestSidebarSelection(_:)), name: .UserDidRequestSidebarSelection, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(downloadArticlesDidUpdateUnreadCounts(_:)), name: .DownloadArticlesDidUpdateUnreadCounts, object: nil)
outlineView.reloadData()
@ -149,6 +150,10 @@ protocol SidebarDelegate: class {
revealAndSelectRepresentedObject(feed as AnyObject)
}
@objc func downloadArticlesDidUpdateUnreadCounts(_ note: Notification) {
rebuildTreeAndRestoreSelection()
}
// MARK: - Actions
@IBAction func delete(_ sender: AnyObject?) {

View File

@ -301,6 +301,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
NotificationCenter.default.addObserver(self, selector: #selector(userDidDeleteAccount(_:)), name: .UserDidDeleteAccount, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(userDefaultsDidChange(_:)), name: UserDefaults.didChangeNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(downloadArticlesDidUpdateUnreadCounts(_:)), name: .DownloadArticlesDidUpdateUnreadCounts, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(accountDidDownloadArticles(_:)), name: .AccountDidDownloadArticles, object: nil)
}
@ -522,6 +523,10 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
self.groupByFeed = AppDefaults.timelineGroupByFeed
}
@objc func downloadArticlesDidUpdateUnreadCounts(_ note: Notification) {
rebuildBackingStores()
}
@objc func accountDidDownloadArticles(_ note: Notification) {
guard let feeds = note.userInfo?[Account.UserInfoKey.webFeeds] as? Set<WebFeed> else {
return