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>? { public func markArticles(_ articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) -> Set<Article>? {
return delegate.markArticles(for: self, articles: articles, statusKey: statusKey, flag: flag)
// 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
} }
@discardableResult @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) { func ensureStatuses(_ articleIDs: Set<String>, _ statusKey: ArticleStatus.Key, _ flag: Bool) {
database.ensureStatuses(articleIDs, statusKey, flag) database.ensureStatuses(articleIDs, statusKey, flag)
} }

View File

@ -7,6 +7,7 @@
// //
import Foundation import Foundation
import Articles
import RSWeb import RSWeb
protocol AccountDelegate { protocol AccountDelegate {
@ -35,6 +36,8 @@ protocol AccountDelegate {
func restoreFeed(for account: Account, feed: Feed, folder: Folder?, completion: @escaping (Result<Void, Error>) -> Void) 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 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. // Called at the end of accounts init method.
func accountDidInitialize(_ account: Account) func accountDidInitialize(_ account: Account)

View File

@ -12,6 +12,7 @@ import AppKit
import UIKit import UIKit
import RSCore import RSCore
#endif #endif
import Articles
import RSCore import RSCore
import RSParser import RSParser
import RSWeb 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) { func accountDidInitialize(_ account: Account) {
credentials = try? account.retrieveBasicCredentials() credentials = try? account.retrieveBasicCredentials()
accountMetadata = account.metadata accountMetadata = account.metadata

View File

@ -8,6 +8,7 @@
import Foundation import Foundation
import RSParser import RSParser
import Articles
import RSWeb import RSWeb
public enum LocalAccountDelegateError: String, Error { public enum LocalAccountDelegateError: String, Error {
@ -160,6 +161,10 @@ final class LocalAccountDelegate: AccountDelegate {
completion(.success(())) 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) { func accountDidInitialize(_ account: Account) {
} }