From f513741ddb06320c687bec2aff4d482f24a7e137 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 21 Aug 2019 13:23:46 -0700 Subject: [PATCH] Start work on filtering timeline so that articles from deleted feeds never show up. --- Frameworks/Account/Account.swift | 6 +++++- .../Timeline/TimelineViewController.swift | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index 869e4b198..d42e093c9 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -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 { diff --git a/Mac/MainWindow/Timeline/TimelineViewController.swift b/Mac/MainWindow/Timeline/TimelineViewController.swift index 26750287d..b01ba2873 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController.swift @@ -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: don’t 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
) { - - let sortedArticles = Array(unsortedArticles).sortedByDate(sortDirection) + // Since there may be transients in a smart feed, + // make sure each article is in a feed that’s 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
{ cancelPendingAsyncFetches() let articleFetchers = representedObjects.compactMap{ $0 as? ArticleFetcher }