From fb9114538ca57098d19bd7ca3859c12dde491004 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sun, 28 Mar 2021 06:30:49 -0500 Subject: [PATCH] Modified the Timeline so that it can handle duplicate articleIDs --- .../Timeline/TimelineViewController.swift | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/Mac/MainWindow/Timeline/TimelineViewController.swift b/Mac/MainWindow/Timeline/TimelineViewController.swift index 115a921f9..18da6aeb8 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController.swift @@ -106,7 +106,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr // When the array is the same — same articles, same order — // but some data in some of the articles may have changed. // Just reload visible cells in this case: don’t call reloadData. - articleRowMap = [String: Int]() + articleRowMap = [String: [Int]]() reloadVisibleCells() return } @@ -124,7 +124,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr showFeedNames = .feed } - articleRowMap = [String: Int]() + articleRowMap = [String: [Int]]() tableView.reloadData() } } @@ -141,7 +141,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr private var fetchSerialNumber = 0 private let fetchRequestQueue = FetchRequestQueue() private var exceptionArticleFetcher: ArticleFetcher? - private var articleRowMap = [String: Int]() // articleID: rowIndex + private var articleRowMap = [String: [Int]]() // articleID: rowIndex private var cellAppearance: TimelineCellAppearance! private var cellAppearanceWithIcon: TimelineCellAppearance! private var showFeedNames: TimelineShowFeedName = .none { @@ -1057,20 +1057,25 @@ private extension TimelineViewController { restoreSelection(savedSelection) } - func row(for articleID: String) -> Int? { + func rows(for articleID: String) -> [Int]? { updateArticleRowMapIfNeeded() return articleRowMap[articleID] } - func row(for article: Article) -> Int? { - return row(for: article.articleID) + func rows(for article: Article) -> [Int]? { + return rows(for: article.articleID) } func updateArticleRowMap() { - var rowMap = [String: Int]() + var rowMap = [String: [Int]]() var index = 0 articles.forEach { (article) in - rowMap[article.articleID] = index + if var indexes = rowMap[article.articleID] { + indexes.append(index) + rowMap[article.articleID] = indexes + } else { + rowMap[article.articleID] = [index] + } index += 1 } articleRowMap = rowMap @@ -1086,11 +1091,11 @@ private extension TimelineViewController { var indexes = IndexSet() articleIDs.forEach { (articleID) in - guard let oneIndex = row(for: articleID) else { + guard let rowsIndex = rows(for: articleID) else { return } - if oneIndex != NSNotFound { - indexes.insert(oneIndex) + for rowIndex in rowsIndex { + indexes.insert(rowIndex) } }