Files
NetNewsWire/Mac/Scripting/Article+Scriptability.swift
T

150 lines
3.2 KiB
Swift
Raw Normal View History

//
// Article+Scriptability.swift
2018-08-28 22:18:24 -07:00
// NetNewsWire
//
// Created by Olof Hellman on 1/23/18.
// Copyright © 2018 Olof Hellman. All rights reserved.
//
import Foundation
import Account
import Articles
@objc(ScriptableArticle)
@MainActor final class ScriptableArticle: NSObject, UniqueIDScriptingObject, @preconcurrency ScriptingObjectContainer {
2026-01-01 16:26:50 -08:00
let article: Article
nonisolated(unsafe) let container: ScriptingObjectContainer
2026-01-01 16:26:50 -08:00
init (_ article: Article, container: ScriptingObjectContainer) {
self.article = article
self.container = container
}
@objc(objectSpecifier)
nonisolated override var objectSpecifier: NSScriptObjectSpecifier? {
2026-01-01 16:26:50 -08:00
let scriptObjectSpecifier = self.container.makeFormUniqueIDScriptObjectSpecifier(forObject: self)
return scriptObjectSpecifier
}
2026-01-01 16:26:50 -08:00
// MARK: - ScriptingObject protocol
nonisolated var scriptingKey: String {
2026-01-01 16:26:50 -08:00
"articles"
}
2026-01-01 16:26:50 -08:00
// MARK: - UniqueIdScriptingObject protocol
2018-08-28 22:18:24 -07:00
// articles have id in the NetNewsWire database and id in the feed
// article.uniqueID here is the feed unique id
@objc(uniqueId)
2026-01-01 16:26:50 -08:00
nonisolated var scriptingUniqueID: Any {
article.uniqueID
}
2026-01-01 16:26:50 -08:00
// MARK: - ScriptingObjectContainer protocol
2025-11-05 11:22:10 -08:00
nonisolated var scriptingClassDescription: NSScriptClassDescription {
return self.classDescription as! NSScriptClassDescription
}
2025-11-05 11:22:10 -08:00
2026-01-02 10:17:41 -08:00
func deleteElement(_ element: ScriptingObject) {
2026-01-02 17:50:35 -08:00
print("delete event not handled")
}
2026-01-01 16:26:50 -08:00
// MARK: - Scriptable properties
2025-11-05 11:22:10 -08:00
@objc(url)
2026-01-02 17:50:35 -08:00
var url: String? {
2026-01-01 16:26:50 -08:00
article.preferredLink
}
2018-02-11 01:20:30 -08:00
@objc(permalink)
2026-01-02 17:50:35 -08:00
var permalink: String? {
2026-01-01 16:26:50 -08:00
article.link
2018-02-11 01:20:30 -08:00
}
@objc(externalUrl)
2026-01-02 17:50:35 -08:00
var externalUrl: String? {
2026-01-01 16:26:50 -08:00
article.externalLink
2018-02-11 01:20:30 -08:00
}
2025-11-05 11:22:10 -08:00
@objc(title)
2026-01-02 17:50:35 -08:00
var title: String {
2026-01-01 16:26:50 -08:00
article.title ?? ""
}
@objc(contents)
2026-01-02 17:50:35 -08:00
var contents: String {
2026-01-01 16:26:50 -08:00
article.contentText ?? ""
}
@objc(html)
2026-01-02 17:50:35 -08:00
var html: String {
2026-01-01 16:26:50 -08:00
article.contentHTML ?? ""
}
@objc(summary)
2026-01-02 17:50:35 -08:00
var summary: String {
2026-01-01 16:26:50 -08:00
article.summary ?? ""
}
@objc(datePublished)
2026-01-02 17:50:35 -08:00
var datePublished: Date? {
2026-01-01 16:26:50 -08:00
article.datePublished
}
@objc(dateModified)
2026-01-02 17:50:35 -08:00
var dateModified: Date? {
2026-01-01 16:26:50 -08:00
article.dateModified
}
@objc(dateArrived)
2026-01-02 17:50:35 -08:00
var dateArrived: Date {
2026-01-01 16:26:50 -08:00
article.status.dateArrived
}
@objc(read)
2026-01-02 17:50:35 -08:00
var read: Bool {
get {
2026-01-01 16:26:50 -08:00
article.status.boolStatus(forKey: .read)
}
set {
markArticles([self.article], statusKey: .read, flag: newValue)
}
}
@objc(starred)
2026-01-02 17:50:35 -08:00
var starred: Bool {
get {
2026-01-02 10:17:41 -08:00
article.status.boolStatus(forKey: .starred)
}
set {
markArticles([self.article], statusKey: .starred, flag: newValue)
}
}
@objc(deleted)
2026-01-02 17:50:35 -08:00
var deleted: Bool {
2026-01-01 16:26:50 -08:00
false
}
@objc(imageURL)
2026-01-02 17:50:35 -08:00
var imageURL: String {
2026-01-01 16:26:50 -08:00
article.imageLink ?? ""
}
2025-11-05 11:22:10 -08:00
@objc(authors)
2026-01-01 16:26:50 -08:00
var authors: NSArray {
let articleAuthors = article.authors ?? []
2026-01-02 10:17:41 -08:00
return articleAuthors.map { ScriptableAuthor($0, container: self) } as NSArray
}
@objc(feed)
2025-11-03 09:32:50 -08:00
var feed: ScriptableFeed? {
2026-01-01 16:26:50 -08:00
guard let parentFeed = self.article.feed else {
return nil
}
2025-11-03 09:42:00 -08:00
return ScriptableFeed.scriptableFeed(for: parentFeed)
}
}