From 92fd016b7a6e027f5b6843391ea79ba1e89aa1f8 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Thu, 15 Apr 2021 14:13:15 -0500 Subject: [PATCH] Exclude Inoreader from article status syncs --- Account/Sources/Account/Account.swift | 16 +------------ Account/Sources/Account/AccountDelegate.swift | 1 + .../CloudKit/CloudKitAccountDelegate.swift | 18 +++++++++++++++ .../FeedWranglerAccountDelegate.swift | 18 +++++++++++++++ .../Feedbin/FeedbinAccountDelegate.swift | 18 +++++++++++++++ .../Feedly/FeedlyAccountDelegate.swift | 18 +++++++++++++++ .../LocalAccount/LocalAccountDelegate.swift | 4 ++++ .../NewsBlur/NewsBlurAccountDelegate.swift | 18 +++++++++++++++ .../ReaderAPI/ReaderAPIAccountDelegate.swift | 23 +++++++++++++++++++ 9 files changed, 119 insertions(+), 15 deletions(-) diff --git a/Account/Sources/Account/Account.swift b/Account/Sources/Account/Account.swift index c802ac572..0cb9fb67b 100644 --- a/Account/Sources/Account/Account.swift +++ b/Account/Sources/Account/Account.swift @@ -443,21 +443,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, } public func syncArticleStatus(completion: ((Result) -> Void)? = nil) { - delegate.sendArticleStatus(for: self) { [unowned self] result in - switch result { - case .success: - self.delegate.refreshArticleStatus(for: self) { result in - switch result { - case .success: - completion?(.success(())) - case .failure(let error): - completion?(.failure(error)) - } - } - case .failure(let error): - completion?(.failure(error)) - } - } + delegate.syncArticleStatus(for: self, completion: completion) } public func importOPML(_ opmlFile: URL, completion: @escaping (Result) -> Void) { diff --git a/Account/Sources/Account/AccountDelegate.swift b/Account/Sources/Account/AccountDelegate.swift index 1f8584406..93a998561 100644 --- a/Account/Sources/Account/AccountDelegate.swift +++ b/Account/Sources/Account/AccountDelegate.swift @@ -26,6 +26,7 @@ protocol AccountDelegate { func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any], completion: @escaping () -> Void) func refreshAll(for account: Account, completion: @escaping (Result) -> Void) + func syncArticleStatus(for account: Account, completion: ((Result) -> Void)?) func sendArticleStatus(for account: Account, completion: @escaping ((Result) -> Void)) func refreshArticleStatus(for account: Account, completion: @escaping ((Result) -> Void)) diff --git a/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift b/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift index 808d2add8..98baf7565 100644 --- a/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift +++ b/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift @@ -92,6 +92,24 @@ final class CloudKitAccountDelegate: AccountDelegate { standardRefreshAll(for: account, completion: completion) } + func syncArticleStatus(for account: Account, completion: ((Result) -> Void)? = nil) { + sendArticleStatus(for: account) { result in + switch result { + case .success: + self.refreshArticleStatus(for: account) { result in + switch result { + case .success: + completion?(.success(())) + case .failure(let error): + completion?(.failure(error)) + } + } + case .failure(let error): + completion?(.failure(error)) + } + } + } + func sendArticleStatus(for account: Account, completion: @escaping ((Result) -> Void)) { sendArticleStatus(for: account, showProgress: false, completion: completion) } diff --git a/Account/Sources/Account/FeedWrangler/FeedWranglerAccountDelegate.swift b/Account/Sources/Account/FeedWrangler/FeedWranglerAccountDelegate.swift index 11e7d130b..1be0ec832 100644 --- a/Account/Sources/Account/FeedWrangler/FeedWranglerAccountDelegate.swift +++ b/Account/Sources/Account/FeedWrangler/FeedWranglerAccountDelegate.swift @@ -150,6 +150,24 @@ final class FeedWranglerAccountDelegate: AccountDelegate { } } + func syncArticleStatus(for account: Account, completion: ((Result) -> Void)? = nil) { + sendArticleStatus(for: account) { result in + switch result { + case .success: + self.refreshArticleStatus(for: account) { result in + switch result { + case .success: + completion?(.success(())) + case .failure(let error): + completion?(.failure(error)) + } + } + case .failure(let error): + completion?(.failure(error)) + } + } + } + func refreshArticles(for account: Account, page: Int = 0, completion: @escaping ((Result) -> Void)) { os_log(.debug, log: log, "Refreshing articles, page: %d...", page) diff --git a/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift b/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift index 78d81d4ee..418711849 100644 --- a/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift +++ b/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift @@ -112,6 +112,24 @@ final class FeedbinAccountDelegate: AccountDelegate { } + func syncArticleStatus(for account: Account, completion: ((Result) -> Void)? = nil) { + sendArticleStatus(for: account) { result in + switch result { + case .success: + self.refreshArticleStatus(for: account) { result in + switch result { + case .success: + completion?(.success(())) + case .failure(let error): + completion?(.failure(error)) + } + } + case .failure(let error): + completion?(.failure(error)) + } + } + } + func sendArticleStatus(for account: Account, completion: @escaping ((Result) -> Void)) { os_log(.debug, log: log, "Sending article statuses...") diff --git a/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift b/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift index 1cd3e2aed..e2df06bf3 100644 --- a/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift +++ b/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift @@ -145,6 +145,24 @@ final class FeedlyAccountDelegate: AccountDelegate { operationQueue.add(syncAllOperation) } + func syncArticleStatus(for account: Account, completion: ((Result) -> Void)? = nil) { + sendArticleStatus(for: account) { result in + switch result { + case .success: + self.refreshArticleStatus(for: account) { result in + switch result { + case .success: + completion?(.success(())) + case .failure(let error): + completion?(.failure(error)) + } + } + case .failure(let error): + completion?(.failure(error)) + } + } + } + func sendArticleStatus(for account: Account, completion: @escaping ((Result) -> Void)) { // Ensure remote articles have the same status as they do locally. let send = FeedlySendArticleStatusesOperation(database: database, service: caller, log: log) diff --git a/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift b/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift index 2006f2973..456c8b738 100644 --- a/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift +++ b/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift @@ -96,6 +96,10 @@ final class LocalAccountDelegate: AccountDelegate { } + func syncArticleStatus(for account: Account, completion: ((Result) -> Void)? = nil) { + completion?(.success(())) + } + func sendArticleStatus(for account: Account, completion: @escaping ((Result) -> Void)) { completion(.success(())) } diff --git a/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift b/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift index b13ba7da1..b415d03d6 100644 --- a/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift +++ b/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift @@ -114,6 +114,24 @@ final class NewsBlurAccountDelegate: AccountDelegate { } } + func syncArticleStatus(for account: Account, completion: ((Result) -> Void)? = nil) { + sendArticleStatus(for: account) { result in + switch result { + case .success: + self.refreshArticleStatus(for: account) { result in + switch result { + case .success: + completion?(.success(())) + case .failure(let error): + completion?(.failure(error)) + } + } + case .failure(let error): + completion?(.failure(error)) + } + } + } + func sendArticleStatus(for account: Account, completion: @escaping (Result) -> ()) { os_log(.debug, log: log, "Sending story statuses...") diff --git a/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift b/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift index 6afb25e87..84d8b7353 100644 --- a/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift +++ b/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift @@ -131,6 +131,29 @@ final class ReaderAPIAccountDelegate: AccountDelegate { } + func syncArticleStatus(for account: Account, completion: ((Result) -> Void)? = nil) { + guard variant != .inoreader else { + completion?(.success(())) + return + } + + sendArticleStatus(for: account) { result in + switch result { + case .success: + self.refreshArticleStatus(for: account) { result in + switch result { + case .success: + completion?(.success(())) + case .failure(let error): + completion?(.failure(error)) + } + } + case .failure(let error): + completion?(.failure(error)) + } + } + } + func sendArticleStatus(for account: Account, completion: @escaping ((Result) -> Void)) { os_log(.debug, log: log, "Sending article statuses...")