Start work on filtering timeline so that articles from deleted feeds never show up.

This commit is contained in:
Brent Simmons 2019-08-21 13:23:46 -07:00
parent 98ec923c67
commit f513741ddb
2 changed files with 20 additions and 5 deletions

View File

@ -614,7 +614,11 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
database.ensureStatuses(articleIDs, statusKey, flag)
}
}
public func has(_ feed: Feed) -> Bool {
return flattenedFeeds().contains(feed)
}
// MARK: - Container
public func flattenedFeeds() -> Set<Feed> {

View File

@ -67,6 +67,9 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
var articles = ArticleArray() {
didSet {
defer {
updateUnreadCount()
}
if articles == oldValue {
return
}
@ -76,13 +79,11 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
// Just reload visible cells in this case: dont call reloadData.
articleRowMap = [String: Int]()
reloadVisibleCells()
updateUnreadCount()
return
}
updateShowAvatars()
articleRowMap = [String: Int]()
tableView.reloadData()
updateUnreadCount()
}
}
@ -982,13 +983,23 @@ private extension TimelineViewController {
}
func replaceArticles(with unsortedArticles: Set<Article>) {
let sortedArticles = Array(unsortedArticles).sortedByDate(sortDirection)
// Since there may be transients in a smart feed,
// make sure each article is in a feed thats still
// subscribed-to.
let filteredArticles = unsortedArticles.filter(articleIsInSubscribedToFeed)
let sortedArticles = Array(filteredArticles).sortedByDate(sortDirection)
if articles != sortedArticles {
articles = sortedArticles
}
}
func articleIsInSubscribedToFeed(_ article: Article) -> Bool {
guard let account = article.account, let feed = article.feed else {
return false
}
return account.has(feed)
}
func fetchUnsortedArticlesSync(for representedObjects: [Any]) -> Set<Article> {
cancelPendingAsyncFetches()
let articleFetchers = representedObjects.compactMap{ $0 as? ArticleFetcher }