Delegate article marking functionality to the account delegate

This commit is contained in:
Maurice Parker 2019-05-14 15:34:05 -05:00
parent 7de24e1d53
commit 30273795a8
4 changed files with 30 additions and 12 deletions

View File

@ -305,18 +305,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
}
public func markArticles(_ articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) -> Set<Article>? {
// Returns set of Articles whose statuses did change.
guard let updatedStatuses = database.mark(articles, statusKey: statusKey, flag: flag) else {
return nil
}
let updatedArticleIDs = updatedStatuses.articleIDs()
let updatedArticles = Set(articles.filter{ updatedArticleIDs.contains($0.articleID) })
noteStatusesForArticlesDidChange(updatedArticles)
return updatedArticles
return delegate.markArticles(for: self, articles: articles, statusKey: statusKey, flag: flag)
}
@discardableResult
@ -617,6 +606,22 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
}
func update(_ articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) -> Set<Article>? {
// Returns set of Articles whose statuses did change.
guard let updatedStatuses = database.mark(articles, statusKey: statusKey, flag: flag) else {
return nil
}
let updatedArticleIDs = updatedStatuses.articleIDs()
let updatedArticles = Set(articles.filter{ updatedArticleIDs.contains($0.articleID) })
noteStatusesForArticlesDidChange(updatedArticles)
return updatedArticles
}
func ensureStatuses(_ articleIDs: Set<String>, _ statusKey: ArticleStatus.Key, _ flag: Bool) {
database.ensureStatuses(articleIDs, statusKey, flag)
}

View File

@ -7,6 +7,7 @@
//
import Foundation
import Articles
import RSWeb
protocol AccountDelegate {
@ -35,6 +36,8 @@ protocol AccountDelegate {
func restoreFeed(for account: Account, feed: Feed, folder: Folder?, completion: @escaping (Result<Void, Error>) -> Void)
func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> Void)
func markArticles(for account: Account, articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) -> Set<Article>?
// Called at the end of accounts init method.
func accountDidInitialize(_ account: Account)

View File

@ -12,6 +12,7 @@ import AppKit
import UIKit
import RSCore
#endif
import Articles
import RSCore
import RSParser
import RSWeb
@ -400,6 +401,10 @@ final class FeedbinAccountDelegate: AccountDelegate {
}
func markArticles(for account: Account, articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) -> Set<Article>? {
return account.update(articles, statusKey: statusKey, flag: flag)
}
func accountDidInitialize(_ account: Account) {
credentials = try? account.retrieveBasicCredentials()
accountMetadata = account.metadata

View File

@ -8,6 +8,7 @@
import Foundation
import RSParser
import Articles
import RSWeb
public enum LocalAccountDelegateError: String, Error {
@ -160,6 +161,10 @@ final class LocalAccountDelegate: AccountDelegate {
completion(.success(()))
}
func markArticles(for account: Account, articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) -> Set<Article>? {
return account.update(articles, statusKey: statusKey, flag: flag)
}
func accountDidInitialize(_ account: Account) {
}