From 2c17fb77c97c4101fe1bda7e072901494bade2a3 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Fri, 23 Oct 2026 12:11:23 -0700 Subject: [PATCH] Add thumbnail storage. --- Mac/MainWindow/Timeline/TimelineViewController.swift | 2 +- .../Account/CloudKit/CloudKitArticlesZoneDelegate.swift | 1 + .../Sources/Account/Feedbin/FeedbinAccountDelegate.swift | 2 +- Modules/Account/Sources/Account/Feedly/FeedlyModel.swift | 1 + .../Internals/NewsBlurAccountDelegate+Internal.swift | 2 +- .../Account/ReaderAPI/ReaderAPIAccountDelegate.swift | 1 + Modules/Articles/Sources/Articles/Article.swift | 6 ++++-- Shared/Extensions/ArticleUtilities.swift | 8 ++++++++ Tests/NetNewsWireTests/ArticleSorterTests.swift | 1 + .../ArticleStringFormatterPerformanceTests.swift | 1 + Tests/NetNewsWireTests/ArticleStringFormatterTests.swift | 1 + Tests/NetNewsWireTests/SharingTests.swift | 1 + .../TimelineCustomizerCollectionViewController.swift | 1 + 13 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Mac/MainWindow/Timeline/TimelineViewController.swift b/Mac/MainWindow/Timeline/TimelineViewController.swift index af475f345..27650049a 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController.swift @@ -838,7 +838,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr let longTitle = "But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?" let prototypeID = "prototype" let status = ArticleStatus(articleID: prototypeID, read: false, starred: false, dateArrived: Date()) - let prototypeArticle = Article(accountID: prototypeID, articleID: prototypeID, feedID: prototypeID, uniqueID: prototypeID, title: longTitle, contentHTML: nil, contentText: nil, markdown: nil, url: nil, externalURL: nil, summary: nil, imageURL: nil, datePublished: nil, dateModified: nil, authors: nil, attachments: nil, status: status) + let prototypeArticle = Article(accountID: prototypeID, articleID: prototypeID, feedID: prototypeID, uniqueID: prototypeID, title: longTitle, contentHTML: nil, contentText: nil, markdown: nil, url: nil, externalURL: nil, summary: nil, imageURL: nil, thumbnailURL: nil, datePublished: nil, dateModified: nil, authors: nil, attachments: nil, status: status) let prototypeCellData = TimelineCellData(article: prototypeArticle, showFeedName: .feed, feedName: "Prototype Feed Name", byline: nil, iconImage: nil, showIcon: false) let height = TimelineCellLayout.height(for: 100, cellData: prototypeCellData, appearance: cellAppearance) diff --git a/Modules/Account/Sources/Account/CloudKit/CloudKitArticlesZoneDelegate.swift b/Modules/Account/Sources/Account/CloudKit/CloudKitArticlesZoneDelegate.swift index 90d28be97..bc3335bd5 100644 --- a/Modules/Account/Sources/Account/CloudKit/CloudKitArticlesZoneDelegate.swift +++ b/Modules/Account/Sources/Account/CloudKit/CloudKitArticlesZoneDelegate.swift @@ -167,6 +167,7 @@ nonisolated func makeParsedItem(_ articleRecord: CKRecord) -> ParsedItem? { markdown: nil, summary: articleRecord[CloudKitArticlesZone.CloudKitArticle.Fields.summary] as? String, imageURL: articleRecord[CloudKitArticlesZone.CloudKitArticle.Fields.imageURL] as? String, + thumbnailURL: nil, bannerImageURL: articleRecord[CloudKitArticlesZone.CloudKitArticle.Fields.imageURL] as? String, datePublished: articleRecord[CloudKitArticlesZone.CloudKitArticle.Fields.datePublished] as? Date, dateModified: articleRecord[CloudKitArticlesZone.CloudKitArticle.Fields.dateModified] as? Date, diff --git a/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift b/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift index 863aa3a84..53bc91dd8 100644 --- a/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift +++ b/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift @@ -982,7 +982,7 @@ private extension FeedbinAccountDelegate { let parsedItems: [ParsedItem] = entries.map { entry in let authors = Set([ParsedAuthor(name: entry.authorName, url: entry.jsonFeed?.jsonFeedAuthor?.url, avatarURL: entry.jsonFeed?.jsonFeedAuthor?.avatarURL, emailAddress: nil)]) - return ParsedItem(syncServiceID: String(entry.articleID), uniqueID: String(entry.articleID), feedURL: String(entry.feedID), url: entry.url, externalURL: entry.jsonFeed?.jsonFeedExternalURL, title: entry.title, language: nil, contentHTML: entry.contentHTML, contentText: nil, markdown: nil, summary: entry.summary, imageURL: nil, bannerImageURL: nil, datePublished: entry.parsedDatePublished, dateModified: nil, authors: authors, tags: nil, attachments: nil) + return ParsedItem(syncServiceID: String(entry.articleID), uniqueID: String(entry.articleID), feedURL: String(entry.feedID), url: entry.url, externalURL: entry.jsonFeed?.jsonFeedExternalURL, title: entry.title, language: nil, contentHTML: entry.contentHTML, contentText: nil, markdown: nil, summary: entry.summary, imageURL: nil, thumbnailURL: nil, bannerImageURL: nil, datePublished: entry.parsedDatePublished, dateModified: nil, authors: authors, tags: nil, attachments: nil) } return Set(parsedItems) diff --git a/Modules/Account/Sources/Account/Feedly/FeedlyModel.swift b/Modules/Account/Sources/Account/Feedly/FeedlyModel.swift index 9ffe33b64..d9a17f620 100644 --- a/Modules/Account/Sources/Account/Feedly/FeedlyModel.swift +++ b/Modules/Account/Sources/Account/Feedly/FeedlyModel.swift @@ -290,6 +290,7 @@ struct FeedlyEntryParser { markdown: nil, summary: summary, imageURL: nil, + thumbnailURL: nil, bannerImageURL: nil, datePublished: datePublished, dateModified: dateModified, diff --git a/Modules/Account/Sources/Account/NewsBlur/Internals/NewsBlurAccountDelegate+Internal.swift b/Modules/Account/Sources/Account/NewsBlur/Internals/NewsBlurAccountDelegate+Internal.swift index 6ead74860..376c274bc 100644 --- a/Modules/Account/Sources/Account/NewsBlur/Internals/NewsBlurAccountDelegate+Internal.swift +++ b/Modules/Account/Sources/Account/NewsBlur/Internals/NewsBlurAccountDelegate+Internal.swift @@ -259,7 +259,7 @@ import os let parsedItems: [ParsedItem] = stories.map { story in let author = Set([ParsedAuthor(name: story.authorName, url: nil, avatarURL: nil, emailAddress: nil)]) - return ParsedItem(syncServiceID: story.storyID, uniqueID: String(story.storyID), feedURL: String(story.feedID), url: story.url, externalURL: nil, title: story.title, language: nil, contentHTML: story.contentHTML, contentText: nil, markdown: nil, summary: nil, imageURL: story.imageURL, bannerImageURL: nil, datePublished: story.datePublished, dateModified: nil, authors: author, tags: Set(story.tags ?? []), attachments: nil) + return ParsedItem(syncServiceID: story.storyID, uniqueID: String(story.storyID), feedURL: String(story.feedID), url: story.url, externalURL: nil, title: story.title, language: nil, contentHTML: story.contentHTML, contentText: nil, markdown: nil, summary: nil, imageURL: story.imageURL, thumbnailURL: nil, bannerImageURL: nil, datePublished: story.datePublished, dateModified: nil, authors: author, tags: Set(story.tags ?? []), attachments: nil) } return Set(parsedItems) diff --git a/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift b/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift index 536f469e9..0f55c5d2b 100644 --- a/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift +++ b/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift @@ -1154,6 +1154,7 @@ private extension ReaderAPIAccountDelegate { markdown: nil, summary: entry.summary.content, imageURL: nil, + thumbnailURL: nil, bannerImageURL: nil, datePublished: entry.parseDatePublished(), dateModified: nil, diff --git a/Modules/Articles/Sources/Articles/Article.swift b/Modules/Articles/Sources/Articles/Article.swift index 94d7526d8..2a08969cc 100644 --- a/Modules/Articles/Sources/Articles/Article.swift +++ b/Modules/Articles/Sources/Articles/Article.swift @@ -24,13 +24,14 @@ public final class Article: Hashable, Sendable { public let rawExternalLink: String? // We store raw source value, but use computed externalURL or externalLink other than where raw value required. public let summary: String? public let rawImageLink: String? // We store raw source value, but use computed imageURL or imageLink other than where raw value required. + public let rawThumbnailLink: String? // We store raw source value, but use computed thumbnailURL or thumbnailLink other than where raw value required. public let datePublished: Date? public let dateModified: Date? public let authors: Set? public let attachments: Set? public let status: ArticleStatus - public init(accountID: String, articleID: String?, feedID: String, uniqueID: String, title: String?, contentHTML: String?, contentText: String?, markdown: String?, url: String?, externalURL: String?, summary: String?, imageURL: String?, datePublished: Date?, dateModified: Date?, authors: Set?, attachments: Set?, status: ArticleStatus) { + public init(accountID: String, articleID: String?, feedID: String, uniqueID: String, title: String?, contentHTML: String?, contentText: String?, markdown: String?, url: String?, externalURL: String?, summary: String?, imageURL: String?, thumbnailURL: String?, datePublished: Date?, dateModified: Date?, authors: Set?, attachments: Set?, status: ArticleStatus) { self.accountID = accountID self.feedID = feedID self.uniqueID = uniqueID @@ -42,6 +43,7 @@ public final class Article: Hashable, Sendable { self.rawExternalLink = externalURL self.summary = summary self.rawImageLink = imageURL + self.rawThumbnailLink = thumbnailURL self.datePublished = datePublished self.dateModified = dateModified self.authors = authors @@ -68,7 +70,7 @@ public final class Article: Hashable, Sendable { // MARK: - Equatable static public func ==(lhs: Article, rhs: Article) -> Bool { - return lhs.articleID == rhs.articleID && lhs.accountID == rhs.accountID && lhs.feedID == rhs.feedID && lhs.uniqueID == rhs.uniqueID && lhs.title == rhs.title && lhs.contentHTML == rhs.contentHTML && lhs.contentText == rhs.contentText && lhs.markdown == rhs.markdown && lhs.rawLink == rhs.rawLink && lhs.rawExternalLink == rhs.rawExternalLink && lhs.summary == rhs.summary && lhs.rawImageLink == rhs.rawImageLink && lhs.datePublished == rhs.datePublished && lhs.dateModified == rhs.dateModified && lhs.authors == rhs.authors && lhs.attachments == rhs.attachments + return lhs.articleID == rhs.articleID && lhs.accountID == rhs.accountID && lhs.feedID == rhs.feedID && lhs.uniqueID == rhs.uniqueID && lhs.title == rhs.title && lhs.contentHTML == rhs.contentHTML && lhs.contentText == rhs.contentText && lhs.markdown == rhs.markdown && lhs.rawLink == rhs.rawLink && lhs.rawExternalLink == rhs.rawExternalLink && lhs.summary == rhs.summary && lhs.rawImageLink == rhs.rawImageLink && lhs.rawThumbnailLink == rhs.rawThumbnailLink && lhs.datePublished == rhs.datePublished && lhs.dateModified == rhs.dateModified && lhs.authors == rhs.authors && lhs.attachments == rhs.attachments } } diff --git a/Shared/Extensions/ArticleUtilities.swift b/Shared/Extensions/ArticleUtilities.swift index aadb5f2d2..0176c0666 100644 --- a/Shared/Extensions/ArticleUtilities.swift +++ b/Shared/Extensions/ArticleUtilities.swift @@ -52,6 +52,10 @@ extension Article { return URL.encodeSpacesIfNeeded(rawImageLink) } + var thumbnailURL: URL? { + URL.encodeSpacesIfNeeded(rawThumbnailLink) + } + var link: String? { // Prefer link from URL, if one can be created, as these are repaired if required. // Provide the raw link if URL creation fails. @@ -70,6 +74,10 @@ extension Article { return imageURL?.absoluteString ?? rawImageLink } + var thumbnailLink: String? { + thumbnailURL?.absoluteString ?? rawThumbnailLink + } + var preferredLink: String? { if let link = link, !link.isEmpty { return link diff --git a/Tests/NetNewsWireTests/ArticleSorterTests.swift b/Tests/NetNewsWireTests/ArticleSorterTests.swift index 586d10b9f..4316b9cbb 100644 --- a/Tests/NetNewsWireTests/ArticleSorterTests.swift +++ b/Tests/NetNewsWireTests/ArticleSorterTests.swift @@ -394,6 +394,7 @@ import XCTest externalURL: nil, summary: nil, imageURL: nil, + thumbnailURL: nil, datePublished: date, dateModified: nil, authors: nil, diff --git a/Tests/NetNewsWireTests/ArticleStringFormatterPerformanceTests.swift b/Tests/NetNewsWireTests/ArticleStringFormatterPerformanceTests.swift index a25a63eef..f8976ed00 100644 --- a/Tests/NetNewsWireTests/ArticleStringFormatterPerformanceTests.swift +++ b/Tests/NetNewsWireTests/ArticleStringFormatterPerformanceTests.swift @@ -118,6 +118,7 @@ import XCTest externalURL: nil, summary: nil, imageURL: nil, + thumbnailURL: nil, datePublished: Date(), dateModified: nil, authors: nil, diff --git a/Tests/NetNewsWireTests/ArticleStringFormatterTests.swift b/Tests/NetNewsWireTests/ArticleStringFormatterTests.swift index 7ebf48a89..52318121a 100644 --- a/Tests/NetNewsWireTests/ArticleStringFormatterTests.swift +++ b/Tests/NetNewsWireTests/ArticleStringFormatterTests.swift @@ -230,6 +230,7 @@ import Testing externalURL: nil, summary: nil, imageURL: nil, + thumbnailURL: nil, datePublished: Date(), dateModified: nil, authors: nil, diff --git a/Tests/NetNewsWireTests/SharingTests.swift b/Tests/NetNewsWireTests/SharingTests.swift index 3902cb59d..db89cbb01 100644 --- a/Tests/NetNewsWireTests/SharingTests.swift +++ b/Tests/NetNewsWireTests/SharingTests.swift @@ -52,6 +52,7 @@ import XCTest externalURL: nil, summary: nil, imageURL: nil, + thumbnailURL: nil, datePublished: nil, dateModified: nil, authors: nil, diff --git a/iOS/Settings/TimelineCustomizerCollectionViewController.swift b/iOS/Settings/TimelineCustomizerCollectionViewController.swift index 5f911efc0..77065d20e 100644 --- a/iOS/Settings/TimelineCustomizerCollectionViewController.swift +++ b/iOS/Settings/TimelineCustomizerCollectionViewController.swift @@ -32,6 +32,7 @@ class TimelineCustomizerCollectionViewController: UICollectionViewController { externalURL: nil, summary: nil, imageURL: nil, + thumbnailURL: nil, datePublished: date, dateModified: nil, authors: Set([Author(authorID: "_testAuthorID", name: "J. R. R. Tolkien", url: nil, avatarURL: nil, emailAddress: nil)!]),