Delegate article marking functionality to the account delegate
This commit is contained in:
parent
7de24e1d53
commit
30273795a8
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 account’s init method.
|
// Called at the end of account’s init method.
|
||||||
func accountDidInitialize(_ account: Account)
|
func accountDidInitialize(_ account: Account)
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue