From 30273795a8f28a5611131db787f5fbcff14194c8 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Tue, 14 May 2019 15:34:05 -0500 Subject: [PATCH] Delegate article marking functionality to the account delegate --- Frameworks/Account/Account.swift | 29 +++++++++++-------- Frameworks/Account/AccountDelegate.swift | 3 ++ .../Feedbin/FeedbinAccountDelegate.swift | 5 ++++ .../LocalAccount/LocalAccountDelegate.swift | 5 ++++ 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index 5174e9ca0..cca1a58f1 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -305,18 +305,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, } public func markArticles(_ articles: Set
, statusKey: ArticleStatus.Key, flag: Bool) -> Set
? { - - // 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
, statusKey: ArticleStatus.Key, flag: Bool) -> Set
? { + + // 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, _ statusKey: ArticleStatus.Key, _ flag: Bool) { database.ensureStatuses(articleIDs, statusKey, flag) } diff --git a/Frameworks/Account/AccountDelegate.swift b/Frameworks/Account/AccountDelegate.swift index 182938fcb..b13a76a01 100644 --- a/Frameworks/Account/AccountDelegate.swift +++ b/Frameworks/Account/AccountDelegate.swift @@ -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) func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result) -> Void) + func markArticles(for account: Account, articles: Set
, statusKey: ArticleStatus.Key, flag: Bool) -> Set
? + // Called at the end of account’s init method. func accountDidInitialize(_ account: Account) diff --git a/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift b/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift index 3f2487ae0..ae07196e5 100644 --- a/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift +++ b/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift @@ -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
, statusKey: ArticleStatus.Key, flag: Bool) -> Set
? { + return account.update(articles, statusKey: statusKey, flag: flag) + } + func accountDidInitialize(_ account: Account) { credentials = try? account.retrieveBasicCredentials() accountMetadata = account.metadata diff --git a/Frameworks/Account/LocalAccount/LocalAccountDelegate.swift b/Frameworks/Account/LocalAccount/LocalAccountDelegate.swift index 44ee0e23d..ea3dd2606 100644 --- a/Frameworks/Account/LocalAccount/LocalAccountDelegate.swift +++ b/Frameworks/Account/LocalAccount/LocalAccountDelegate.swift @@ -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
, statusKey: ArticleStatus.Key, flag: Bool) -> Set
? { + return account.update(articles, statusKey: statusKey, flag: flag) + } + func accountDidInitialize(_ account: Account) { }