2017-05-27 10:43:27 -07:00
|
|
|
//
|
|
|
|
// ArticleUtilities.swift
|
|
|
|
// Evergreen
|
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 7/25/15.
|
|
|
|
// Copyright © 2015 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
2017-09-17 12:20:32 -07:00
|
|
|
import Data
|
2017-09-17 12:34:10 -07:00
|
|
|
import Account
|
2017-05-27 10:43:27 -07:00
|
|
|
|
|
|
|
// These handle multiple accounts.
|
|
|
|
|
2017-09-17 12:54:08 -07:00
|
|
|
func markArticles(_ articles: Set<Article>, statusKey: String, flag: Bool) {
|
2017-05-27 10:43:27 -07:00
|
|
|
|
2017-09-17 12:54:08 -07:00
|
|
|
let d: [String: Set<Article>] = accountAndArticlesDictionary(articles)
|
2017-05-27 10:43:27 -07:00
|
|
|
|
2017-09-17 12:54:08 -07:00
|
|
|
d.keys.forEach { (accountID) in
|
2017-05-27 10:43:27 -07:00
|
|
|
|
2017-09-17 12:54:08 -07:00
|
|
|
guard let accountArticles = d[accountID], let account = accountWithID(accountID) else {
|
2017-05-27 10:43:27 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-09-17 12:54:08 -07:00
|
|
|
account.markArticles(accountArticles, statusKey: statusKey, flag: flag)
|
2017-05-27 10:43:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-17 12:54:08 -07:00
|
|
|
private func accountAndArticlesDictionary(_ articles: Set<Article>) -> [String: Set<Article>] {
|
2017-05-27 10:43:27 -07:00
|
|
|
|
2017-09-17 12:54:08 -07:00
|
|
|
var d = [String: Set<Article>]()
|
2017-05-27 10:43:27 -07:00
|
|
|
|
2017-09-17 12:54:08 -07:00
|
|
|
articles.forEach { (article) in
|
2017-05-27 10:43:27 -07:00
|
|
|
|
2017-09-17 12:54:08 -07:00
|
|
|
let accountID = article.accountID
|
|
|
|
var articleSet: Set<Article> = d[accountID] ?? Set<Article>()
|
|
|
|
articleSet.insert(article)
|
|
|
|
d[accountID] = articleSet
|
2017-05-27 10:43:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return d
|
|
|
|
}
|
|
|
|
|
2017-09-17 12:54:08 -07:00
|
|
|
extension Article {
|
2017-05-27 10:43:27 -07:00
|
|
|
|
2017-09-17 17:03:58 -07:00
|
|
|
var feed: Feed? {
|
|
|
|
get {
|
|
|
|
return account?.existingFeed(with: feedID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-17 16:30:45 -07:00
|
|
|
var preferredLink: String? {
|
|
|
|
get {
|
|
|
|
return url ?? externalURL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var body: String? {
|
|
|
|
get {
|
|
|
|
return contentHTML ?? contentText ?? summary
|
|
|
|
}
|
2017-05-27 10:43:27 -07:00
|
|
|
}
|
2017-09-17 17:03:58 -07:00
|
|
|
|
|
|
|
var logicalDatePublished: Date {
|
|
|
|
get {
|
2017-09-22 18:37:25 -07:00
|
|
|
return datePublished ?? dateModified ?? status.dateArrived
|
2017-09-17 17:03:58 -07:00
|
|
|
}
|
|
|
|
}
|
2017-05-27 10:43:27 -07:00
|
|
|
}
|