diff --git a/Mac/MainWindow/Timeline/TimelineViewController.swift b/Mac/MainWindow/Timeline/TimelineViewController.swift index 772b12b0c..f359f1d1c 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController.swift @@ -143,7 +143,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr return } - loadSavedThumbnailURLs() + findThumbnailURLs() if let representedObjects = representedObjects, representedObjects.count == 1 && representedObjects.first is Feed { showFeedNames = { @@ -162,7 +162,6 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr thumbnailFirstVisibleRow = nil tableView.reloadData() IconImageCache.shared.prefetchImagesForArticles(articles) - discoverThumbnailURLs() } } @@ -792,7 +791,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr // A failed provided image falls back to images in the HTML. Those are found first, so a row that has one doesn’t shrink and then grow back. let articlesUsingURL = articles.filter { articleIDs.contains($0.articleID) } Task { - await ArticleThumbnailFinder.shared.discoverThumbnailURLs(for: articlesUsingURL) + await ArticleThumbnailFinder.shared.findThumbnailURLs(for: articlesUsingURL).value // Articles that used the failed URL now get their next source, or none. thumbnailURLsDidChange(for: articleIDs) } @@ -1276,7 +1275,7 @@ private extension TimelineViewController { func layoutDidChange() { thumbnailFirstVisibleRow = nil - loadSavedThumbnailURLs() + findThumbnailURLs() performBlockAndRestoreSelection { configureTableView(for: layout) updateShowIcons() @@ -1285,7 +1284,6 @@ private extension TimelineViewController { if tableView.selectedRow != -1 { tableView.scrollRowToVisible(tableView.selectedRow) } - discoverThumbnailURLs() } func updateShowIcons() { @@ -1414,33 +1412,22 @@ private extension TimelineViewController { guard layout == .standard else { return } - loadSavedThumbnailURLs() + findThumbnailURLs() performBlockAndRestoreSelection { tableView.reloadData() } if tableView.selectedRow != -1 { tableView.scrollRowToVisible(tableView.selectedRow) } - discoverThumbnailURLs() - } - - /// Row heights and text width depend on having a thumbnail URL, so this runs before rows are laid out. - func loadSavedThumbnailURLs() { - guard thumbnailMode != nil else { - return - } - ArticleThumbnailFinder.shared.loadSavedThumbnailURLs(for: articles) } /// Finds thumbnails in the HTML of articles with no provided image. Local work, no downloads. - func discoverThumbnailURLs() { + /// Row heights and text width depend on having a thumbnail URL, so this runs before rows are laid out. + func findThumbnailURLs() { guard thumbnailMode != nil else { return } - let articles = self.articles - Task { - await ArticleThumbnailFinder.shared.discoverThumbnailURLs(for: articles) - } + ArticleThumbnailFinder.shared.findThumbnailURLs(for: articles) } /// Starts thumbnail downloads for the screenful of rows the table is scrolling toward. diff --git a/iOS/MainTimeline/MainTimelineViewController.swift b/iOS/MainTimeline/MainTimelineViewController.swift index 9d6378ea7..d8db3d5b8 100644 --- a/iOS/MainTimeline/MainTimelineViewController.swift +++ b/iOS/MainTimeline/MainTimelineViewController.swift @@ -1115,7 +1115,7 @@ private extension MainTimelineViewController { return } - discoverThumbnailURLs() + findThumbnailURLs() var snapshot = NSDiffableDataSourceSnapshot() snapshot.appendSections([0]) @@ -1143,14 +1143,11 @@ private extension MainTimelineViewController { /// Finds thumbnails in the HTML of articles with no provided image. Local work, no downloads. /// Saved results are ready when this returns, so rows laid out next get their final heights. - func discoverThumbnailURLs() { + func findThumbnailURLs() { guard thumbnailMode != nil, let articles, !articles.isEmpty else { return } - ArticleThumbnailFinder.shared.loadSavedThumbnailURLs(for: articles) - Task { - await ArticleThumbnailFinder.shared.discoverThumbnailURLs(for: articles) - } + ArticleThumbnailFinder.shared.findThumbnailURLs(for: articles) } func visibleArticles() -> [Article] { @@ -1235,7 +1232,7 @@ private extension MainTimelineViewController { return } thumbnailsDisplay = AppDefaults.timelineThumbnailsDisplay - discoverThumbnailURLs() + findThumbnailURLs() reloadAllCells() } @@ -1266,7 +1263,7 @@ private extension MainTimelineViewController { // A failed provided image falls back to images in the HTML. Those are found first, so a row that has one doesn’t shrink and then grow back. let articlesUsingURL = articles?.filter { articleIDs.contains($0.articleID) } ?? [] Task { - await ArticleThumbnailFinder.shared.discoverThumbnailURLs(for: articlesUsingURL) + await ArticleThumbnailFinder.shared.findThumbnailURLs(for: articlesUsingURL).value // Articles that used the failed URL now get their next source, or none. thumbnailURLsDidChange(for: articleIDs) }