2017-05-27 19:43:27 +02: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 21:20:32 +02:00
|
|
|
import Data
|
2017-09-17 21:34:10 +02:00
|
|
|
import Account
|
2017-05-27 19:43:27 +02:00
|
|
|
|
|
|
|
// These handle multiple accounts.
|
|
|
|
|
|
|
|
func markArticles(_ articles: NSSet, statusKey: ArticleStatusKey, flag: Bool) {
|
|
|
|
|
|
|
|
let d: [String: NSSet] = accountAndArticlesDictionary(articles)
|
|
|
|
|
|
|
|
d.keys.forEach { (oneAccountIdentifier) in
|
|
|
|
|
|
|
|
guard let oneAccountArticles = d[oneAccountIdentifier], let oneAccount = accountWithIdentifier(oneAccountIdentifier) else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
oneAccount.markArticles(oneAccountArticles, statusKey: statusKey, flag: flag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func accountAndArticlesDictionary(_ articles: NSSet) -> [String: NSSet] {
|
|
|
|
|
|
|
|
var d = [String: NSMutableSet]()
|
|
|
|
|
|
|
|
articles.forEach { (oneObject) in
|
|
|
|
|
|
|
|
guard let oneArticle = oneObject as? Article else {
|
|
|
|
return
|
|
|
|
}
|
2017-09-17 21:34:10 +02:00
|
|
|
guard let oneAccountIdentifier = oneArticle.account?.accountID else {
|
2017-05-27 19:43:27 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let oneArticleSet: NSMutableSet = d[oneAccountIdentifier] ?? NSMutableSet()
|
|
|
|
oneArticleSet.add(oneArticle)
|
|
|
|
d[oneAccountIdentifier] = oneArticleSet
|
|
|
|
}
|
|
|
|
|
|
|
|
return d
|
|
|
|
}
|
|
|
|
|
2017-09-17 21:34:10 +02:00
|
|
|
private func accountWithID(_ accountID: String) -> Account? {
|
2017-05-27 19:43:27 +02:00
|
|
|
|
2017-09-17 21:34:10 +02:00
|
|
|
return AccountManager.sharedInstance.existingAccountWithIdentifier(accountID)
|
2017-05-27 19:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func preferredLink(for article: Article) -> String? {
|
|
|
|
|
|
|
|
if let s = article.permalink {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
return article.link
|
|
|
|
}
|
|
|
|
|