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.
|
|
|
|
//
|
|
|
|
|
2018-02-02 22:51:32 -08:00
|
|
|
import AppKit
|
2018-07-23 18:29:08 -07:00
|
|
|
import Articles
|
2017-05-27 10:43:27 -07:00
|
|
|
|
2024-03-19 23:05:30 -07:00
|
|
|
@MainActor struct TimelineCellData {
|
2017-05-27 10:43:27 -07:00
|
|
|
|
2020-10-23 19:18:35 -05:00
|
|
|
private static let noText = NSLocalizedString("(No Text)", comment: "No Text")
|
|
|
|
|
2017-05-27 10:43:27 -07:00
|
|
|
let title: String
|
2020-04-30 02:36:32 -05:00
|
|
|
let attributedTitle: NSAttributedString
|
2017-05-27 10:43:27 -07:00
|
|
|
let text: String
|
|
|
|
let dateString: String
|
|
|
|
let feedName: String
|
2020-04-18 07:53:56 -05:00
|
|
|
let byline: String
|
|
|
|
let showFeedName: TimelineShowFeedName
|
2019-11-05 18:05:57 -06:00
|
|
|
let iconImage: IconImage? // feed icon, user avatar, or favicon
|
|
|
|
let showIcon: Bool // Make space even when icon is nil
|
2017-11-25 21:27:35 -08:00
|
|
|
let featuredImage: NSImage? // image from within the article
|
2017-05-27 10:43:27 -07:00
|
|
|
let read: Bool
|
2018-02-17 22:23:36 -08:00
|
|
|
let starred: Bool
|
2017-05-27 10:43:27 -07:00
|
|
|
|
2020-04-18 07:53:56 -05:00
|
|
|
init(article: Article, showFeedName: TimelineShowFeedName, feedName: String?, byline: String?, iconImage: IconImage?, showIcon: Bool, featuredImage: NSImage?) {
|
2018-02-18 16:13:58 -08:00
|
|
|
|
2019-10-20 02:28:00 -05:00
|
|
|
self.title = ArticleStringFormatter.truncatedTitle(article)
|
2020-04-30 02:36:32 -05:00
|
|
|
self.attributedTitle = ArticleStringFormatter.attributedTruncatedTitle(article)
|
2017-05-27 10:43:27 -07:00
|
|
|
|
2020-10-23 19:18:35 -05:00
|
|
|
let truncatedSummary = ArticleStringFormatter.truncatedSummary(article)
|
|
|
|
if self.title.isEmpty && truncatedSummary.isEmpty {
|
|
|
|
self.text = Self.noText
|
|
|
|
} else {
|
|
|
|
self.text = truncatedSummary
|
|
|
|
}
|
|
|
|
|
2019-10-20 02:28:00 -05:00
|
|
|
self.dateString = ArticleStringFormatter.dateString(article.logicalDatePublished)
|
2017-05-27 10:43:27 -07:00
|
|
|
|
2017-12-30 12:45:10 -08:00
|
|
|
if let feedName = feedName {
|
2019-10-20 02:28:00 -05:00
|
|
|
self.feedName = ArticleStringFormatter.truncatedFeedName(feedName)
|
2020-04-18 07:53:56 -05:00
|
|
|
} else {
|
2017-05-27 10:43:27 -07:00
|
|
|
self.feedName = ""
|
|
|
|
}
|
2020-04-18 07:53:56 -05:00
|
|
|
|
|
|
|
if let byline = byline {
|
|
|
|
self.byline = byline
|
|
|
|
} else {
|
|
|
|
self.byline = ""
|
|
|
|
}
|
2017-05-27 10:43:27 -07:00
|
|
|
|
|
|
|
self.showFeedName = showFeedName
|
|
|
|
|
2019-11-05 18:05:57 -06:00
|
|
|
self.showIcon = showIcon
|
|
|
|
self.iconImage = iconImage
|
2017-11-25 21:27:35 -08:00
|
|
|
self.featuredImage = featuredImage
|
|
|
|
|
2017-09-24 12:24:44 -07:00
|
|
|
self.read = article.status.read
|
2018-02-17 22:23:36 -08:00
|
|
|
self.starred = article.status.starred
|
2017-05-27 10:43:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
init() { //Empty
|
|
|
|
self.title = ""
|
|
|
|
self.text = ""
|
|
|
|
self.dateString = ""
|
|
|
|
self.feedName = ""
|
2020-04-18 07:53:56 -05:00
|
|
|
self.byline = ""
|
|
|
|
self.showFeedName = .none
|
2019-11-05 18:05:57 -06:00
|
|
|
self.showIcon = false
|
|
|
|
self.iconImage = nil
|
2017-11-25 21:27:35 -08:00
|
|
|
self.featuredImage = nil
|
2017-05-27 10:43:27 -07:00
|
|
|
self.read = true
|
2018-02-17 22:23:36 -08:00
|
|
|
self.starred = false
|
2020-04-30 02:36:32 -05:00
|
|
|
self.attributedTitle = NSAttributedString()
|
2017-05-27 10:43:27 -07:00
|
|
|
}
|
|
|
|
}
|