diff --git a/Mac/MainWindow/Timeline/TimelineViewController.swift b/Mac/MainWindow/Timeline/TimelineViewController.swift index 85620fcdb..ef5f714de 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController.swift @@ -823,7 +823,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr } // The row already has room for the thumbnail, so only the image changes. tableView.enumerateAvailableRowViews { rowView, row in - guard let article = articles.articleAtRow(row), ArticleThumbnailFinder.shared.thumbnailURL(for: article, mode: thumbnailMode) == url, let cell = cellForRowView(rowView) as? TimelineTableCellView, let thumbnail = ThumbnailDownloader.shared.thumbnail(url: url, mode: thumbnailMode, articleTitle: article.title) else { + guard let article = articles.articleAtRow(row), ArticleThumbnailFinder.shared.thumbnailURL(for: article, mode: thumbnailMode) == url, let cell = cellForRowView(rowView) as? TimelineTableCellView, let thumbnail = ThumbnailDownloader.shared.thumbnail(url: url, mode: thumbnailMode, feedName: article.feed?.nameForDisplay, articleTitle: article.title) else { return } cell.thumbnail = thumbnail @@ -1411,7 +1411,7 @@ extension TimelineViewController: NSTableViewDelegate { var showThumbnail = false if let thumbnailMode, let thumbnailURL = ArticleThumbnailFinder.shared.thumbnailURL(for: article, mode: thumbnailMode) { showThumbnail = true - thumbnail = ThumbnailDownloader.shared.thumbnail(url: thumbnailURL, mode: thumbnailMode, articleTitle: article.title) + thumbnail = ThumbnailDownloader.shared.thumbnail(url: thumbnailURL, mode: thumbnailMode, feedName: article.feed?.nameForDisplay, 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) } diff --git a/Modules/Images/Sources/Images/ThumbnailDownloader.swift b/Modules/Images/Sources/Images/ThumbnailDownloader.swift index 842cd5852..ecbf871d5 100644 --- a/Modules/Images/Sources/Images/ThumbnailDownloader.swift +++ b/Modules/Images/Sources/Images/ThumbnailDownloader.swift @@ -78,23 +78,23 @@ public enum ThumbnailMode: String, Sendable, CaseIterable { DownloadedImageCache.networkAllowsDownloads } - /// `url` is from `ArticleThumbnailFinder.thumbnailURL(for:mode:)`. `articleTitle` is shown in the activity log when the download fails. + /// `url` is from `ArticleThumbnailFinder.thumbnailURL(for:mode:)`. `feedName` and `articleTitle` are shown in the activity log. /// Nil when the image isn’t ready. Starts a download when needed and posts /// `.thumbnailDidBecomeAvailable` once the image is ready. - public func thumbnail(url: String, mode: ThumbnailMode, articleTitle: String?) -> RSImage? { + public func thumbnail(url: String, mode: ThumbnailMode, feedName: String?, articleTitle: String?) -> RSImage? { if let image = imageCache.object(forKey: Self.cacheKey(url, mode)) { DownloadedImageCache.shared.imageWasUsed(url, checksForUpdates: false) return image } - findImage(url, mode: mode, activityDetail: articleTitle) + findImage(url, mode: mode, activityDetail: Self.activityDetail(feedName: feedName, articleTitle: articleTitle)) return nil } /// The image as downloaded, for the article view, which shows the thumbnail image at full size. /// Shares the timeline’s copy and any download in progress, so the image is downloaded once. /// A download starts right away rather than waiting behind timeline downloads. - public func fullSizeImageData(url: String, articleTitle: String?) async throws(ImageDownloadError) -> Data { - try await DownloadedImageCache.shared.imageData(for: url, usesDownloadQueue: false, checksForUpdates: false, activityOwner: .thumbnailDownloader, activityKind: .downloadThumbnail(imageURL: url), activityDetail: articleTitle) + public func fullSizeImageData(url: String, feedName: String?, articleTitle: String?) async throws(ImageDownloadError) -> Data { + try await DownloadedImageCache.shared.imageData(for: url, usesDownloadQueue: false, checksForUpdates: false, activityOwner: .thumbnailDownloader, activityKind: .downloadThumbnail(imageURL: url), activityDetail: Self.activityDetail(feedName: feedName, articleTitle: articleTitle)) } // MARK: - Notifications @@ -107,6 +107,16 @@ public enum ThumbnailMode: String, Sendable, CaseIterable { private extension ThumbnailDownloader { + /// Starts with a dash to separate it from the image URL that precedes it in the log. + static func activityDetail(feedName: String?, articleTitle: String?) -> String? { + let quotedTitle = articleTitle.map { "“\($0)”" } + let parts = [feedName, quotedTitle].compactMap { $0 } + guard !parts.isEmpty else { + return nil + } + return "- " + parts.joined(separator: ": ") + } + /// The same URL can be cached at both sizes. static func cacheKey(_ url: String, _ mode: ThumbnailMode) -> NSString { "\(mode.rawValue) \(url)" as NSString diff --git a/Shared/Article Rendering/ArticleImageSchemeHandler.swift b/Shared/Article Rendering/ArticleImageSchemeHandler.swift index ad08ce175..1728f794d 100644 --- a/Shared/Article Rendering/ArticleImageSchemeHandler.swift +++ b/Shared/Article Rendering/ArticleImageSchemeHandler.swift @@ -43,7 +43,7 @@ import Images var imageData: Data? var downloadError: Error? do { - imageData = try await ThumbnailDownloader.shared.fullSizeImageData(url: imageURL, articleTitle: nil) + imageData = try await ThumbnailDownloader.shared.fullSizeImageData(url: imageURL, feedName: nil, articleTitle: nil) } catch { downloadError = error } diff --git a/iOS/Article/WebViewController.swift b/iOS/Article/WebViewController.swift index 7701e92b2..c43a6452b 100644 --- a/iOS/Article/WebViewController.swift +++ b/iOS/Article/WebViewController.swift @@ -816,7 +816,7 @@ private extension WebViewController { var data: Data? // Only a correctly signed routed URL uses the timeline’s copy, so page content can’t claim one. if imageURL.scheme?.caseInsensitiveCompare(ArticleRenderer.articleImageScheme) == .orderedSame, let timelineImageURL = ArticleImageSchemeHandler.imageURL(imageURL) { - data = try? await ThumbnailDownloader.shared.fullSizeImageData(url: timelineImageURL, articleTitle: nil) + data = try? await ThumbnailDownloader.shared.fullSizeImageData(url: timelineImageURL, feedName: nil, articleTitle: nil) } else { data = try? await Downloader.shared.download(imageURL, userAgentStyle: .browser).data } diff --git a/iOS/MainTimeline/MainTimelineViewController.swift b/iOS/MainTimeline/MainTimelineViewController.swift index 8e07a0c24..458a4834e 100644 --- a/iOS/MainTimeline/MainTimelineViewController.swift +++ b/iOS/MainTimeline/MainTimelineViewController.swift @@ -592,7 +592,7 @@ extension MainTimelineViewController: UICollectionViewDelegate { reloadCells([article]) return } - guard let thumbnailURL, let thumbnail = ThumbnailDownloader.shared.thumbnail(url: thumbnailURL, mode: thumbnailMode, articleTitle: article.title), thumbnail !== cell.thumbnail else { + guard let thumbnailURL, let thumbnail = ThumbnailDownloader.shared.thumbnail(url: thumbnailURL, mode: thumbnailMode, feedName: article.feed?.nameForDisplay, articleTitle: article.title), thumbnail !== cell.thumbnail else { return } cell.thumbnail = thumbnail @@ -994,7 +994,7 @@ private extension MainTimelineViewController { var showThumbnail = false if let thumbnailMode, let thumbnailURL = ArticleThumbnailFinder.shared.thumbnailURL(for: article, mode: thumbnailMode) { showThumbnail = true - thumbnail = ThumbnailDownloader.shared.thumbnail(url: thumbnailURL, mode: thumbnailMode, articleTitle: article.title) + thumbnail = ThumbnailDownloader.shared.thumbnail(url: thumbnailURL, mode: thumbnailMode, feedName: article.feed?.nameForDisplay, 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, fadesReadArticles: fadesReadArticles, feedNameAndDateAboveTitle: feedNameAndDateAboveTitle, showsFullTitles: showsFullTitles) return cellData @@ -1239,7 +1239,7 @@ private extension MainTimelineViewController { } // The row’s height already allows for the thumbnail, so only the cell’s contents change. for indexPath in collectionView.indexPathsForVisibleItems { - guard let article = dataSource.itemIdentifier(for: indexPath), ArticleThumbnailFinder.shared.thumbnailURL(for: article, mode: thumbnailMode) == url, let cell = collectionView.cellForItem(at: indexPath) as? MainTimelineCell, let thumbnail = ThumbnailDownloader.shared.thumbnail(url: url, mode: thumbnailMode, articleTitle: article.title) else { + guard let article = dataSource.itemIdentifier(for: indexPath), ArticleThumbnailFinder.shared.thumbnailURL(for: article, mode: thumbnailMode) == url, let cell = collectionView.cellForItem(at: indexPath) as? MainTimelineCell, let thumbnail = ThumbnailDownloader.shared.thumbnail(url: url, mode: thumbnailMode, feedName: article.feed?.nameForDisplay, articleTitle: article.title) else { continue } cell.thumbnail = thumbnail