2017-07-02 02:22:19 +02:00
|
|
|
//
|
|
|
|
// Article.swift
|
2017-07-29 21:29:05 +02:00
|
|
|
// Data
|
2017-07-02 02:22:19 +02:00
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 7/1/17.
|
|
|
|
// Copyright © 2017 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
public final class Article: Hashable {
|
|
|
|
|
|
|
|
weak var account: Account?
|
2017-07-08 02:49:16 +02:00
|
|
|
|
2017-07-13 22:38:47 +02:00
|
|
|
public let databaseID: String
|
2017-07-12 21:55:48 +02:00
|
|
|
public let feedID: String // Likely a URL, but not necessarily
|
|
|
|
public let uniqueID: String // Unique per feed (RSS guid, for example)
|
2017-07-03 20:20:14 +02:00
|
|
|
public var title: String?
|
|
|
|
public var contentHTML: String?
|
|
|
|
public var contentText: String?
|
|
|
|
public var url: String?
|
|
|
|
public var externalURL: String?
|
|
|
|
public var summary: String?
|
|
|
|
public var imageURL: String?
|
|
|
|
public var bannerImageURL: String?
|
|
|
|
public var datePublished: Date?
|
|
|
|
public var dateModified: Date?
|
|
|
|
public var authors: [Author]?
|
2017-07-11 05:54:00 +02:00
|
|
|
public var tags: Set<String>?
|
2017-07-03 20:20:14 +02:00
|
|
|
public var attachments: [Attachment]?
|
2017-07-08 02:49:16 +02:00
|
|
|
public var accountInfo: [String: Any]? //If account needs to store more data
|
|
|
|
|
2017-07-03 20:20:14 +02:00
|
|
|
public var status: ArticleStatus?
|
2017-07-03 19:29:44 +02:00
|
|
|
public let hashValue: Int
|
2017-07-02 02:22:19 +02:00
|
|
|
|
|
|
|
var feed: Feed? {
|
|
|
|
get {
|
2017-07-12 21:55:48 +02:00
|
|
|
return account?.existingFeed(with: feedID)
|
2017-07-02 02:22:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-17 04:36:38 +02:00
|
|
|
init(account: Account, databaseID: String?, feedID: String, uniqueID: String, title: String?, contentHTML: String?, contentText: String?, url: String?, externalURL: String?, summary: String?, imageURL: String?, bannerImageURL: String?, datePublished: Date?, dateModified: Date?, authors: [Author]?, tags: Set<String>?, attachments: [Attachment]?, accountInfo: AccountInfo?) {
|
2017-07-11 06:47:27 +02:00
|
|
|
|
2017-07-02 02:22:19 +02:00
|
|
|
self.account = account
|
2017-07-12 21:55:48 +02:00
|
|
|
self.feedID = feedID
|
|
|
|
self.uniqueID = uniqueID
|
2017-07-02 02:22:19 +02:00
|
|
|
self.title = title
|
|
|
|
self.contentHTML = contentHTML
|
|
|
|
self.contentText = contentText
|
|
|
|
self.url = url
|
|
|
|
self.externalURL = externalURL
|
|
|
|
self.summary = summary
|
|
|
|
self.imageURL = imageURL
|
|
|
|
self.bannerImageURL = bannerImageURL
|
|
|
|
self.datePublished = datePublished
|
|
|
|
self.dateModified = dateModified
|
|
|
|
self.authors = authors
|
|
|
|
self.tags = tags
|
|
|
|
self.attachments = attachments
|
2017-07-08 02:49:16 +02:00
|
|
|
self.accountInfo = accountInfo
|
2017-07-17 04:36:38 +02:00
|
|
|
|
|
|
|
let _databaseID: String
|
|
|
|
if let databaseID = databaseID {
|
|
|
|
_databaseID = databaseID
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_databaseID = databaseIDWithString("\(feedID) \(uniqueID)")
|
|
|
|
}
|
|
|
|
self.databaseID = _databaseID
|
|
|
|
|
|
|
|
self.hashValue = account.hashValue ^ _databaseID.hashValue
|
2017-07-02 02:22:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public class func ==(lhs: Article, rhs: Article) -> Bool {
|
|
|
|
|
|
|
|
return lhs === rhs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public extension Article {
|
|
|
|
|
|
|
|
public var logicalDatePublished: Date? {
|
|
|
|
get {
|
2017-07-03 19:29:44 +02:00
|
|
|
return (datePublished ?? dateModified) ?? status?.dateArrived
|
2017-07-02 02:22:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|