2018-01-24 09:06:34 +01:00
|
|
|
//
|
|
|
|
// Article+Scriptability.swift
|
2018-08-29 07:18:24 +02:00
|
|
|
// NetNewsWire
|
2018-01-24 09:06:34 +01:00
|
|
|
//
|
|
|
|
// Created by Olof Hellman on 1/23/18.
|
|
|
|
// Copyright © 2018 Olof Hellman. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import Account
|
2018-07-24 03:29:08 +02:00
|
|
|
import Articles
|
2018-01-24 09:06:34 +01:00
|
|
|
|
|
|
|
@objc(ScriptableArticle)
|
2018-01-24 09:27:56 +01:00
|
|
|
class ScriptableArticle: NSObject, UniqueIdScriptingObject, ScriptingObjectContainer {
|
2018-01-24 09:06:34 +01:00
|
|
|
|
|
|
|
let article:Article
|
|
|
|
let container:ScriptingObjectContainer
|
|
|
|
|
|
|
|
init (_ article:Article, container:ScriptingObjectContainer) {
|
|
|
|
self.article = article
|
|
|
|
self.container = container
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc(objectSpecifier)
|
|
|
|
override var objectSpecifier: NSScriptObjectSpecifier? {
|
|
|
|
let scriptObjectSpecifier = self.container.makeFormUniqueIDScriptObjectSpecifier(forObject:self)
|
|
|
|
return (scriptObjectSpecifier)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: --- ScriptingObject protocol ---
|
|
|
|
|
|
|
|
var scriptingKey: String {
|
|
|
|
return "articles"
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: --- UniqueIdScriptingObject protocol ---
|
|
|
|
|
2018-08-29 07:18:24 +02:00
|
|
|
// articles have id in the NetNewsWire database and id in the feed
|
2018-01-24 09:06:34 +01:00
|
|
|
// article.uniqueID here is the feed unique id
|
|
|
|
|
2018-04-26 06:40:50 +02:00
|
|
|
@objc(uniqueId)
|
2018-01-24 09:06:34 +01:00
|
|
|
var scriptingUniqueId:Any {
|
|
|
|
return article.uniqueID
|
|
|
|
}
|
2018-01-24 09:27:56 +01:00
|
|
|
|
|
|
|
// MARK: --- ScriptingObjectContainer protocol ---
|
2018-01-24 09:06:34 +01:00
|
|
|
|
2018-01-24 09:27:56 +01:00
|
|
|
var scriptingClassDescription: NSScriptClassDescription {
|
|
|
|
return self.classDescription as! NSScriptClassDescription
|
|
|
|
}
|
2018-03-05 03:43:29 +01:00
|
|
|
|
|
|
|
func deleteElement(_ element:ScriptingObject) {
|
|
|
|
print ("delete event not handled")
|
|
|
|
}
|
2018-01-24 09:27:56 +01:00
|
|
|
|
2018-01-24 09:06:34 +01:00
|
|
|
// MARK: --- Scriptable properties ---
|
|
|
|
|
|
|
|
@objc(url)
|
2018-02-11 10:20:30 +01:00
|
|
|
var url:String? {
|
|
|
|
return article.url ?? article.externalURL
|
2018-01-24 09:06:34 +01:00
|
|
|
}
|
2018-02-11 10:20:30 +01:00
|
|
|
|
|
|
|
@objc(permalink)
|
|
|
|
var permalink:String? {
|
|
|
|
return article.url
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc(externalUrl)
|
|
|
|
var externalUrl:String? {
|
|
|
|
return article.externalURL
|
|
|
|
}
|
2018-01-24 09:06:34 +01:00
|
|
|
|
|
|
|
@objc(title)
|
|
|
|
var title:String {
|
|
|
|
return article.title ?? ""
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc(contents)
|
|
|
|
var contents:String {
|
|
|
|
return article.contentText ?? ""
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc(html)
|
|
|
|
var html:String {
|
|
|
|
return article.contentHTML ?? ""
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc(summary)
|
|
|
|
var summary:String {
|
|
|
|
return article.summary ?? ""
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc(datePublished)
|
|
|
|
var datePublished:Date? {
|
|
|
|
return article.datePublished
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc(dateModified)
|
|
|
|
var dateModified:Date? {
|
|
|
|
return article.dateModified
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc(dateArrived)
|
|
|
|
var dateArrived:Date {
|
|
|
|
return article.status.dateArrived
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc(read)
|
|
|
|
var read:Bool {
|
2019-06-11 03:20:11 +02:00
|
|
|
get {
|
|
|
|
return article.status.boolStatus(forKey:.read)
|
|
|
|
}
|
|
|
|
set {
|
|
|
|
markArticles([self.article], statusKey: .read, flag: newValue)
|
|
|
|
}
|
2018-01-24 09:06:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@objc(starred)
|
|
|
|
var starred:Bool {
|
2019-06-11 03:20:11 +02:00
|
|
|
get {
|
|
|
|
return article.status.boolStatus(forKey:.starred)
|
|
|
|
}
|
|
|
|
set {
|
|
|
|
markArticles([self.article], statusKey: .starred, flag: newValue)
|
|
|
|
}
|
2018-01-24 09:06:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@objc(deleted)
|
|
|
|
var deleted:Bool {
|
|
|
|
return article.status.boolStatus(forKey:.userDeleted)
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc(imageURL)
|
|
|
|
var imageURL:String {
|
|
|
|
return article.imageURL ?? ""
|
|
|
|
}
|
2018-01-24 09:27:56 +01:00
|
|
|
|
|
|
|
@objc(authors)
|
|
|
|
var authors:NSArray {
|
|
|
|
let articleAuthors = article.authors ?? []
|
|
|
|
return articleAuthors.map { ScriptableAuthor($0, container:self) } as NSArray
|
|
|
|
}
|
|
|
|
|
2018-01-24 09:06:34 +01:00
|
|
|
}
|