Files
NetNewsWire/Mac/MainWindow/Timeline/Cell/TimelineCellData.swift
T

87 lines
2.3 KiB
Swift
Raw Normal View History

2017-05-27 10:43:27 -07:00
//
// TimelineCellData.swift
2018-08-28 22:18:24 -07:00
// NetNewsWire
2017-05-27 10:43:27 -07:00
//
// Created by Brent Simmons on 2/6/16.
// Copyright © 2016 Ranchero Software, LLC. All rights reserved.
//
import AppKit
import Articles
2026-05-29 10:46:00 -07:00
import Images
2017-05-27 10:43:27 -07:00
2025-11-13 17:11:34 -08:00
@MainActor struct TimelineCellData {
2025-11-05 11:22:10 -08:00
private static let noText = NSLocalizedString("(No Text)", comment: "No Text")
2025-11-05 11:22:10 -08:00
2017-05-27 10:43:27 -07:00
let title: String
let attributedTitle: NSAttributedString
2017-05-27 10:43:27 -07:00
let text: String
let dateString: String
let feedName: String
let byline: String
let showFeedName: TimelineShowFeedName
let iconImage: IconImage? // feed icon, user avatar, or favicon
let showIcon: Bool // Make space even when icon is nil
2026-10-30 17:31:37 -07:00
var thumbnail: NSImage?
2026-10-25 14:55:23 -07:00
let showThumbnail: Bool // Make space even when thumbnail is nil
2017-05-27 10:43:27 -07:00
let read: Bool
let starred: Bool
2017-05-27 10:43:27 -07:00
2026-10-25 14:55:23 -07:00
init(article: Article, showFeedName: TimelineShowFeedName, feedName: String?, byline: String?, iconImage: IconImage?, showIcon: Bool, thumbnail: NSImage?, showThumbnail: Bool) {
self.title = ArticleStringFormatter.shared.truncatedTitle(article)
self.attributedTitle = ArticleStringFormatter.shared.attributedTruncatedTitle(article)
self.text = Self.summaryText(for: article, title: self.title)
2025-11-05 11:22:10 -08:00
self.dateString = ArticleStringFormatter.shared.dateString(article.logicalDatePublished)
2017-05-27 10:43:27 -07:00
if let feedName = feedName {
self.feedName = ArticleStringFormatter.shared.truncatedFeedName(feedName)
} else {
2017-05-27 10:43:27 -07:00
self.feedName = ""
}
2025-11-05 11:22:10 -08:00
if let byline = byline {
self.byline = byline
} else {
self.byline = ""
}
2017-05-27 10:43:27 -07:00
self.showFeedName = showFeedName
self.showIcon = showIcon
self.iconImage = iconImage
2026-10-25 14:55:23 -07:00
self.thumbnail = thumbnail
self.showThumbnail = showThumbnail
2017-09-24 12:24:44 -07:00
self.read = article.status.read
self.starred = article.status.starred
2017-05-27 10:43:27 -07:00
}
/// The article’s summary, or “(No Text)” when it has neither a title nor a summary.
static func summaryText(for article: Article, title: String) -> String {
let truncatedSummary = ArticleStringFormatter.shared.truncatedSummary(article)
if title.isEmpty && truncatedSummary.isEmpty {
return noText
}
return truncatedSummary
}
2026-01-02 11:42:12 -08:00
init() { // Empty
2017-05-27 10:43:27 -07:00
self.title = ""
self.text = ""
self.dateString = ""
self.feedName = ""
self.byline = ""
self.showFeedName = .none
self.showIcon = false
self.iconImage = nil
2026-10-25 14:55:23 -07:00
self.thumbnail = nil
self.showThumbnail = false
2017-05-27 10:43:27 -07:00
self.read = true
self.starred = false
self.attributedTitle = NSAttributedString()
2017-05-27 10:43:27 -07:00
}
}