From 3b6a3cf4e7645e550bea89644dc660f280bc340f Mon Sep 17 00:00:00 2001 From: everhardt Date: Sat, 30 Oct 2021 10:37:10 +0200 Subject: [PATCH] Do not mark articles as read on scroll when they were manually toggled --- .../TimelineViewController+ContextualMenus.swift | 3 +++ .../Timeline/TimelineViewController.swift | 14 +++++++++++++- .../MasterTimelineViewController.swift | 5 ++++- iOS/SceneCoordinator.swift | 8 ++++++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Mac/MainWindow/Timeline/TimelineViewController+ContextualMenus.swift b/Mac/MainWindow/Timeline/TimelineViewController+ContextualMenus.swift index dd83afdcb..42ec68d95 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController+ContextualMenus.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController+ContextualMenus.swift @@ -111,6 +111,9 @@ private extension TimelineViewController { func markArticles(_ articles: [Article], read: Bool) { markArticles(articles, statusKey: .read, flag: read) + for article in articles { + articlesWithManuallyChangedReadStatus.insert(article) + } } func markArticles(_ articles: [Article], starred: Bool) { diff --git a/Mac/MainWindow/Timeline/TimelineViewController.swift b/Mac/MainWindow/Timeline/TimelineViewController.swift index c9a877fc7..0190f1fb6 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController.swift @@ -138,6 +138,9 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr } var undoableCommands = [UndoableCommand]() + + var articlesWithManuallyChangedReadStatus: Set
= Set() + private var fetchSerialNumber = 0 private let fetchRequestQueue = FetchRequestQueue() private var exceptionArticleFetcher: ArticleFetcher? @@ -341,7 +344,9 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr return } let firstVisibleRowIndex = tableView.rows(in: tableView.visibleRect).location - guard let unreadArticlesScrolledAway = articles.articlesAbove(position: firstVisibleRowIndex).unreadArticles() else { return } + let unreadArticlesScrolledAway = articles.articlesAbove(position: firstVisibleRowIndex).filter { !$0.status.read && !articlesWithManuallyChangedReadStatus.contains($0) } + + if unreadArticlesScrolledAway.isEmpty { return } guard let undoManager = undoManager, let markReadCommand = MarkStatusCommand(initialArticles: unreadArticlesScrolledAway, markingRead: true, undoManager: undoManager) else { return @@ -370,6 +375,9 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr return } runCommand(markReadCommand) + for article in selectedArticles { + articlesWithManuallyChangedReadStatus.insert(article) + } } @IBAction func markSelectedArticlesAsUnread(_ sender: Any?) { @@ -377,6 +385,9 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr return } runCommand(markUnreadCommand) + for article in selectedArticles { + articlesWithManuallyChangedReadStatus.insert(article) + } } @IBAction func copy(_ sender: Any?) { @@ -928,6 +939,7 @@ extension TimelineViewController: NSTableViewDelegate { return } self.runCommand(markUnreadCommand) + articlesWithManuallyChangedReadStatus.insert(article) } private func toggleArticleStarred(_ article: Article) { diff --git a/iOS/MasterTimeline/MasterTimelineViewController.swift b/iOS/MasterTimeline/MasterTimelineViewController.swift index 024504980..195530545 100644 --- a/iOS/MasterTimeline/MasterTimelineViewController.swift +++ b/iOS/MasterTimeline/MasterTimelineViewController.swift @@ -527,7 +527,10 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner return } - guard let unreadArticlesScrolledAway = coordinator.articles.articlesAbove(article: firstVisibleArticle).unreadArticles() else { return } + guard let unreadArticlesScrolledAway = coordinator.articles + .articlesAbove(article: firstVisibleArticle) + .filter({ !coordinator.articlesWithManuallyChangedReadStatus.contains($0) }) + .unreadArticles() else { return } coordinator.markAllAsRead(unreadArticlesScrolledAway) diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 2f411e3be..0e9ab2237 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -182,6 +182,8 @@ class SceneCoordinator: NSObject, UndoableCommandRunner { private(set) var showFeedNames = ShowFeedName.none private(set) var showIcons = false + var articlesWithManuallyChangedReadStatus: Set
= Set() + var prevFeedIndexPath: IndexPath? { guard let indexPath = currentFeedIndexPath else { return nil @@ -783,6 +785,8 @@ class SceneCoordinator: NSObject, UndoableCommandRunner { return } + articlesWithManuallyChangedReadStatus.removeAll() + currentFeedIndexPath = indexPath masterFeedViewController.updateFeedSelection(animations: animations) @@ -1073,24 +1077,28 @@ class SceneCoordinator: NSObject, UndoableCommandRunner { func markAsReadForCurrentArticle() { if let article = currentArticle { markArticlesWithUndo([article], statusKey: .read, flag: true) + articlesWithManuallyChangedReadStatus.insert(article) } } func markAsUnreadForCurrentArticle() { if let article = currentArticle { markArticlesWithUndo([article], statusKey: .read, flag: false) + articlesWithManuallyChangedReadStatus.insert(article) } } func toggleReadForCurrentArticle() { if let article = currentArticle { toggleRead(article) + articlesWithManuallyChangedReadStatus.insert(article) } } func toggleRead(_ article: Article) { guard !article.status.read || article.isAvailableToMarkUnread else { return } markArticlesWithUndo([article], statusKey: .read, flag: !article.status.read) + articlesWithManuallyChangedReadStatus.insert(article) } func toggleStarredForCurrentArticle() {