mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-25 09:11:13 +01:00
70 lines
1.3 KiB
Swift
70 lines
1.3 KiB
Swift
//
|
|
// 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<Article>, statusKey: String, flag: Bool) {
|
|
|
|
let d: [String: Set<Article>] = accountAndArticlesDictionary(articles)
|
|
|
|
d.keys.forEach { (accountID) in
|
|
|
|
guard let accountArticles = d[accountID], let account = AccountManager.shared.existingAccount(with: accountID) else {
|
|
return
|
|
}
|
|
|
|
account.markArticles(accountArticles, statusKey: statusKey, flag: flag)
|
|
}
|
|
}
|
|
|
|
private func accountAndArticlesDictionary(_ articles: Set<Article>) -> [String: Set<Article>] {
|
|
|
|
var d = [String: Set<Article>]()
|
|
|
|
articles.forEach { (article) in
|
|
|
|
let accountID = article.accountID
|
|
var articleSet: Set<Article> = d[accountID] ?? Set<Article>()
|
|
articleSet.insert(article)
|
|
d[accountID] = articleSet
|
|
}
|
|
|
|
return d
|
|
}
|
|
|
|
extension Article {
|
|
|
|
var feed: Feed? {
|
|
get {
|
|
return account?.existingFeed(with: feedID)
|
|
}
|
|
}
|
|
|
|
var preferredLink: String? {
|
|
get {
|
|
return url ?? externalURL
|
|
}
|
|
}
|
|
|
|
var body: String? {
|
|
get {
|
|
return contentHTML ?? contentText ?? summary
|
|
}
|
|
}
|
|
|
|
var logicalDatePublished: Date {
|
|
get {
|
|
return datePublished ?? dateModified ?? status.dateArrived
|
|
}
|
|
}
|
|
}
|