diff --git a/Mac/MainWindow/Timeline/TimelineViewController.swift b/Mac/MainWindow/Timeline/TimelineViewController.swift index 519fbe229..516f1bf9a 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController.swift @@ -1132,8 +1132,12 @@ extension TimelineViewController: NSTableViewDelegate { private func configureTimelineCell(_ cell: TimelineTableCellView, article: Article) { cell.objectValue = article let iconImage = article.iconImage() - let showThumbnail = showsThumbnails && thumbnailURL(for: article) != nil - let thumbnail = showThumbnail ? ArticleThumbnailFinder.shared.thumbnail(for: article, mode: thumbnailMode) : nil + var thumbnail: NSImage? + var showThumbnail = false + if showsThumbnails, let thumbnailURL = thumbnailURL(for: article) { + showThumbnail = true + thumbnail = ArticleThumbnailFinder.shared.thumbnail(url: thumbnailURL, mode: thumbnailMode, articleTitle: article.title) + } cell.cellData = TimelineCellData(article: article, showFeedName: showFeedNames, feedName: article.feed?.nameForDisplay, byline: article.byline(), iconImage: iconImage, showIcon: showIcons, thumbnail: thumbnail, showThumbnail: showThumbnail) } @@ -1462,8 +1466,8 @@ private extension TimelineViewController { thumbnailLookaheadRows = lookaheadRows for row in lookaheadRows { - if let article = articles.articleAtRow(row) { - ArticleThumbnailFinder.shared.prefetchThumbnail(for: article, mode: thumbnailMode) + if let article = articles.articleAtRow(row), let thumbnailURL = thumbnailURL(for: article) { + ArticleThumbnailFinder.shared.prefetchThumbnail(url: thumbnailURL, mode: thumbnailMode, articleTitle: article.title) } } } diff --git a/Modules/Images/Sources/Images/ArticleThumbnailFinder.swift b/Modules/Images/Sources/Images/ArticleThumbnailFinder.swift index 200f88238..ff88a18c2 100644 --- a/Modules/Images/Sources/Images/ArticleThumbnailFinder.swift +++ b/Modules/Images/Sources/Images/ArticleThumbnailFinder.swift @@ -83,27 +83,24 @@ extension Notification.Name { NotificationCenter.default.addObserver(self, selector: #selector(handleLowMemory(_:)), name: .lowMemory, object: nil) } + /// `url` is from `thumbnailURL(for:mode:)`. `articleTitle` is shown in the activity log. /// Nil when the image isn’t ready. Starts a download when needed and posts /// `.articleThumbnailDidBecomeAvailable` once the image is ready. - public func thumbnail(for article: Article, mode: Mode) -> RSImage? { - guard let url = thumbnailURL(for: article, mode: mode) else { - return nil - } + public func thumbnail(url: String, mode: Mode, articleTitle: String?) -> RSImage? { if let image = imageCache.object(forKey: Self.cacheKey(url, mode)) { return image } - - findImage(url, mode: mode, downloadPriority: .visible, activityDetail: article.title) + findImage(url, mode: mode, downloadPriority: .visible, activityDetail: articleTitle) return nil } - /// Gets the thumbnail ready for an article expected to be shown soon. + /// Gets a thumbnail ready for an article expected to be shown soon. /// Its download waits behind thumbnails being shown now. - public func prefetchThumbnail(for article: Article, mode: Mode) { - guard let url = thumbnailURL(for: article, mode: mode), imageCache.object(forKey: Self.cacheKey(url, mode)) == nil else { + public func prefetchThumbnail(url: String, mode: Mode, articleTitle: String?) { + guard imageCache.object(forKey: Self.cacheKey(url, mode)) == nil else { return } - findImage(url, mode: mode, downloadPriority: .prefetch, activityDetail: article.title) + findImage(url, mode: mode, downloadPriority: .prefetch, activityDetail: articleTitle) } /// Nil when the article has no usable image, or when its HTML hasn’t been checked yet. diff --git a/iOS/MainTimeline/MainTimelineViewController.swift b/iOS/MainTimeline/MainTimelineViewController.swift index 3b78c153c..0c930af09 100644 --- a/iOS/MainTimeline/MainTimelineViewController.swift +++ b/iOS/MainTimeline/MainTimelineViewController.swift @@ -981,9 +981,9 @@ private extension MainTimelineViewController { let showIcon = showIcons && iconImage != nil var thumbnail: UIImage? var showThumbnail = false - if let thumbnailMode, thumbnailURL(for: article) != nil { + if let thumbnailMode, let thumbnailURL = thumbnailURL(for: article) { showThumbnail = true - thumbnail = ArticleThumbnailFinder.shared.thumbnail(for: article, mode: thumbnailMode) + thumbnail = ArticleThumbnailFinder.shared.thumbnail(url: thumbnailURL, mode: thumbnailMode, articleTitle: article.title) } let cellData = MainTimelineCellData(article: article, showFeedName: showFeedNames, feedName: article.feed?.nameForDisplay, byline: article.byline(), iconImage: iconImage, showIcon: showIcon, numberOfLines: numberOfTextLines, iconSize: iconSize, thumbnail: thumbnail, showThumbnail: showThumbnail, thumbnailsDisplay: thumbnailsDisplay) return cellData @@ -1153,8 +1153,8 @@ private extension MainTimelineViewController { thumbnailLookaheadItems = lookaheadItems for item in lookaheadItems { - if let article = dataSource.itemIdentifier(for: IndexPath(item: item, section: section)) { - ArticleThumbnailFinder.shared.prefetchThumbnail(for: article, mode: thumbnailMode) + if let article = dataSource.itemIdentifier(for: IndexPath(item: item, section: section)), let thumbnailURL = thumbnailURL(for: article) { + ArticleThumbnailFinder.shared.prefetchThumbnail(url: thumbnailURL, mode: thumbnailMode, articleTitle: article.title) } } }