2017-05-27 19:43:27 +02:00
|
|
|
//
|
|
|
|
// TimelineCellData.swift
|
2018-08-29 07:18:24 +02:00
|
|
|
// NetNewsWire
|
2017-05-27 19:43:27 +02:00
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 2/6/16.
|
|
|
|
// Copyright © 2016 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2018-02-03 07:51:32 +01:00
|
|
|
import AppKit
|
2018-07-24 03:29:08 +02:00
|
|
|
import Articles
|
2024-04-16 07:21:17 +02:00
|
|
|
import Images
|
2017-05-27 19:43:27 +02:00
|
|
|
|
2024-03-20 07:05:30 +01:00
|
|
|
@MainActor struct TimelineCellData {
|
2017-05-27 19:43:27 +02:00
|
|
|
|
2020-10-24 02:18:35 +02:00
|
|
|
private static let noText = NSLocalizedString("(No Text)", comment: "No Text")
|
|
|
|
|
2017-05-27 19:43:27 +02:00
|
|
|
let title: String
|
2020-04-30 09:36:32 +02:00
|
|
|
let attributedTitle: NSAttributedString
|
2017-05-27 19:43:27 +02:00
|
|
|
let text: String
|
|
|
|
let dateString: String
|
|
|
|
let feedName: String
|
2020-04-18 14:53:56 +02:00
|
|
|
let byline: String
|
|
|
|
let showFeedName: TimelineShowFeedName
|
2019-11-06 01:05:57 +01:00
|
|
|
let iconImage: IconImage? // feed icon, user avatar, or favicon
|
|
|
|
let showIcon: Bool // Make space even when icon is nil
|
2017-11-26 06:27:35 +01:00
|
|
|
let featuredImage: NSImage? // image from within the article
|
2017-05-27 19:43:27 +02:00
|
|
|
let read: Bool
|
2018-02-18 07:23:36 +01:00
|
|
|
let starred: Bool
|
2017-05-27 19:43:27 +02:00
|
|
|
|
2020-04-18 14:53:56 +02:00
|
|
|
init(article: Article, showFeedName: TimelineShowFeedName, feedName: String?, byline: String?, iconImage: IconImage?, showIcon: Bool, featuredImage: NSImage?) {
|
2018-02-19 01:13:58 +01:00
|
|
|
|
2019-10-20 09:28:00 +02:00
|
|
|
self.title = ArticleStringFormatter.truncatedTitle(article)
|
2020-04-30 09:36:32 +02:00
|
|
|
self.attributedTitle = ArticleStringFormatter.attributedTruncatedTitle(article)
|
2017-05-27 19:43:27 +02:00
|
|
|
|
2020-10-24 02:18:35 +02:00
|
|
|
let truncatedSummary = ArticleStringFormatter.truncatedSummary(article)
|
|
|
|
if self.title.isEmpty && truncatedSummary.isEmpty {
|
|
|
|
self.text = Self.noText
|
|
|
|
} else {
|
|
|
|
self.text = truncatedSummary
|
|
|
|
}
|
|
|
|
|
2019-10-20 09:28:00 +02:00
|
|
|
self.dateString = ArticleStringFormatter.dateString(article.logicalDatePublished)
|
2017-05-27 19:43:27 +02:00
|
|
|
|
2017-12-30 21:45:10 +01:00
|
|
|
if let feedName = feedName {
|
2019-10-20 09:28:00 +02:00
|
|
|
self.feedName = ArticleStringFormatter.truncatedFeedName(feedName)
|
2020-04-18 14:53:56 +02:00
|
|
|
} else {
|
2017-05-27 19:43:27 +02:00
|
|
|
self.feedName = ""
|
|
|
|
}
|
2020-04-18 14:53:56 +02:00
|
|
|
|
|
|
|
if let byline = byline {
|
|
|
|
self.byline = byline
|
|
|
|
} else {
|
|
|
|
self.byline = ""
|
|
|
|
}
|
2017-05-27 19:43:27 +02:00
|
|
|
|
|
|
|
self.showFeedName = showFeedName
|
|
|
|
|
2019-11-06 01:05:57 +01:00
|
|
|
self.showIcon = showIcon
|
|
|
|
self.iconImage = iconImage
|
2017-11-26 06:27:35 +01:00
|
|
|
self.featuredImage = featuredImage
|
|
|
|
|
2017-09-24 21:24:44 +02:00
|
|
|
self.read = article.status.read
|
2018-02-18 07:23:36 +01:00
|
|
|
self.starred = article.status.starred
|
2017-05-27 19:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
init() { //Empty
|
|
|
|
self.title = ""
|
|
|
|
self.text = ""
|
|
|
|
self.dateString = ""
|
|
|
|
self.feedName = ""
|
2020-04-18 14:53:56 +02:00
|
|
|
self.byline = ""
|
|
|
|
self.showFeedName = .none
|
2019-11-06 01:05:57 +01:00
|
|
|
self.showIcon = false
|
|
|
|
self.iconImage = nil
|
2017-11-26 06:27:35 +01:00
|
|
|
self.featuredImage = nil
|
2017-05-27 19:43:27 +02:00
|
|
|
self.read = true
|
2018-02-18 07:23:36 +01:00
|
|
|
self.starred = false
|
2020-04-30 09:36:32 +02:00
|
|
|
self.attributedTitle = NSAttributedString()
|
2017-05-27 19:43:27 +02:00
|
|
|
}
|
|
|
|
}
|