// // ArticleUtilities.swift // Evergreen // // Created by Brent Simmons on 7/25/15. // Copyright © 2015 Ranchero Software, LLC. All rights reserved. // import Foundation import Data import Account // These handle multiple accounts. func markArticles(_ articles: Set
, statusKey: String, flag: Bool) { let d: [String: Set
] = accountAndArticlesDictionary(articles) d.keys.forEach { (accountID) in guard let accountArticles = d[accountID], let account = accountWithID(accountID) else { return } account.markArticles(accountArticles, statusKey: statusKey, flag: flag) } } private func accountAndArticlesDictionary(_ articles: Set
) -> [String: Set
] { var d = [String: Set
]() articles.forEach { (article) in let accountID = article.accountID var articleSet: Set
= d[accountID] ?? Set
() articleSet.insert(article) d[accountID] = articleSet } return d } extension Article { var feed: Feed? { get { return account?.existingFeed(with: feedID) } } var status: ArticleStatus? { get { guard let status = account?.articleStatus(for: self) else { assertionFailure("Expected ArticleStatus for article.status.") return nil } return status } } var preferredLink: String? { get { return url ?? externalURL } } var body: String? { get { return contentHTML ?? contentText ?? summary } } var logicalDatePublished: Date { get { return datePublished ?? dateModified ?? status?.dateArrived ?? Date.distantPast } } var read: Bool { get { if let status = status { return status.read } return false } } }