Refresh smart feeds when they are selected and articles are downloaded

This commit is contained in:
Maurice Parker 2019-08-29 15:02:45 -05:00
parent b98877c7df
commit 6844762dfc

View File

@ -273,7 +273,11 @@ class AppCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
} }
@objc func containerChildrenDidChange(_ note: Notification) { @objc func containerChildrenDidChange(_ note: Notification) {
rebuildBackingStores() if timelineFetcherContainsAnyPseudoFeed() || timelineFetcherContainsAnyFolder() {
fetchAndReplaceArticlesAsync() { [weak self] in
self?.rebuildBackingStores()
}
}
} }
@objc func batchUpdateDidPerform(_ notification: Notification) { @objc func batchUpdateDidPerform(_ notification: Notification) {
@ -951,7 +955,7 @@ private extension AppCoordinator {
replaceArticles(with: fetchedArticles) replaceArticles(with: fetchedArticles)
} }
func fetchAndReplaceArticlesAsync() { func fetchAndReplaceArticlesAsync(completion: @escaping () -> Void) {
// To be called when we need to do an entire fetch, but an async delay is okay. // To be called when we need to do an entire fetch, but an async delay is okay.
// Example: we have the Today feed selected, and the calendar day just changed. // Example: we have the Today feed selected, and the calendar day just changed.
cancelPendingAsyncFetches() cancelPendingAsyncFetches()
@ -961,6 +965,7 @@ private extension AppCoordinator {
} }
fetchUnsortedArticlesAsync(for: [timelineFetcher]) { [weak self] (articles) in fetchUnsortedArticlesAsync(for: [timelineFetcher]) { [weak self] (articles) in
self?.replaceArticles(with: articles) self?.replaceArticles(with: articles)
completion()
} }
} }
@ -1000,6 +1005,13 @@ private extension AppCoordinator {
return false return false
} }
func timelineFetcherContainsAnyFolder() -> Bool {
if timelineFetcher is Folder {
return true
}
return false
}
func timelineFetcherContainsAnyFeed(_ feeds: Set<Feed>) -> Bool { func timelineFetcherContainsAnyFeed(_ feeds: Set<Feed>) -> Bool {
// Return true if theres a match or if a folder contains (recursively) one of feeds // Return true if theres a match or if a folder contains (recursively) one of feeds