diff --git a/Account/Sources/Account/Account.swift b/Account/Sources/Account/Account.swift index 6e9bd4107..e97b93e5c 100644 --- a/Account/Sources/Account/Account.swift +++ b/Account/Sources/Account/Account.swift @@ -519,9 +519,17 @@ public enum FetchType { func loadOPMLItems(_ items: [RSOPMLItem]) { addOPMLItems(OPMLNormalizer.normalize(items)) } - - public func markArticles(_ articles: Set
, statusKey: ArticleStatus.Key, flag: Bool, completion: @escaping (Result) -> Void) { - delegate.markArticles(for: self, articles: articles, statusKey: statusKey, flag: flag, completion: completion) + + public func markArticles(_ articles: Set
, statusKey: ArticleStatus.Key, flag: Bool) { + + Task { @MainActor in + try? await self.markArticles(articles, statusKey: statusKey, flag: flag) + } + } + + public func markArticles(_ articles: Set
, statusKey: ArticleStatus.Key, flag: Bool) async throws { + + try await delegate.markArticles(for: self, articles: articles, statusKey: statusKey, flag: flag) } func existingContainer(withExternalID externalID: String) -> Container? { diff --git a/Account/Sources/Account/AccountDelegate.swift b/Account/Sources/Account/AccountDelegate.swift index 3d7eb27e9..371fff7d0 100644 --- a/Account/Sources/Account/AccountDelegate.swift +++ b/Account/Sources/Account/AccountDelegate.swift @@ -45,8 +45,7 @@ import Secrets func restoreFeed(for account: Account, feed: Feed, container: Container, 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, completion: @escaping (Result) -> Void) - + func markArticles(for account: Account, articles: Set
, statusKey: ArticleStatus.Key, flag: Bool) async throws // Called at the end of account’s init method. func accountDidInitialize(_ account: Account) diff --git a/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift b/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift index d7b9ad1ab..7b28bc416 100644 --- a/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift +++ b/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift @@ -444,7 +444,21 @@ enum CloudKitAccountDelegateError: LocalizedError { } } - func markArticles(for account: Account, articles: Set
, statusKey: ArticleStatus.Key, flag: Bool, completion: @escaping (Result) -> Void) { + func markArticles(for account: Account, articles: Set
, statusKey: ArticleStatus.Key, flag: Bool) async throws { + + try await withCheckedThrowingContinuation { continuation in + self.markArticles(for: account, articles: articles, statusKey: statusKey, flag: flag) { result in + switch result { + case .success: + continuation.resume() + case .failure(let error): + continuation.resume(throwing: error) + } + } + } + } + + private func markArticles(for account: Account, articles: Set
, statusKey: ArticleStatus.Key, flag: Bool, completion: @escaping (Result) -> Void) { account.update(articles, statusKey: statusKey, flag: flag) { result in switch result { case .success(let articles): diff --git a/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift b/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift index ea1e7071c..0f99dbe8d 100644 --- a/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift +++ b/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift @@ -590,7 +590,21 @@ final class FeedbinAccountDelegate: AccountDelegate { } - func markArticles(for account: Account, articles: Set
, statusKey: ArticleStatus.Key, flag: Bool, completion: @escaping (Result) -> Void) { + func markArticles(for account: Account, articles: Set
, statusKey: ArticleStatus.Key, flag: Bool) async throws { + + try await withCheckedThrowingContinuation { continuation in + self.markArticles(for: account, articles: articles, statusKey: statusKey, flag: flag) { result in + switch result { + case .success: + continuation.resume() + case .failure(let error): + continuation.resume(throwing: error) + } + } + } + } + + private func markArticles(for account: Account, articles: Set
, statusKey: ArticleStatus.Key, flag: Bool, completion: @escaping (Result) -> Void) { account.update(articles, statusKey: statusKey, flag: flag) { result in switch result { case .success(let articles): diff --git a/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift b/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift index 0fe2ece64..1e739cd60 100644 --- a/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift +++ b/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift @@ -552,7 +552,21 @@ final class FeedlyAccountDelegate: AccountDelegate { } } - func markArticles(for account: Account, articles: Set
, statusKey: ArticleStatus.Key, flag: Bool, completion: @escaping (Result) -> Void) { + func markArticles(for account: Account, articles: Set
, statusKey: ArticleStatus.Key, flag: Bool) async throws { + + try await withCheckedThrowingContinuation { continuation in + self.markArticles(for: account, articles: articles, statusKey: statusKey, flag: flag) { result in + switch result { + case .success: + continuation.resume() + case .failure(let error): + continuation.resume(throwing: error) + } + } + } + } + + private func markArticles(for account: Account, articles: Set
, statusKey: ArticleStatus.Key, flag: Bool, completion: @escaping (Result) -> Void) { account.update(articles, statusKey: statusKey, flag: flag) { result in switch result { case .success(let articles): diff --git a/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift b/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift index 937ed7cbe..793c86fe8 100644 --- a/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift +++ b/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift @@ -170,12 +170,16 @@ final class LocalAccountDelegate: AccountDelegate { completion(.success(())) } - func markArticles(for account: Account, articles: Set
, statusKey: ArticleStatus.Key, flag: Bool, completion: @escaping (Result) -> Void) { - account.update(articles, statusKey: statusKey, flag: flag) { result in - if case .failure(let error) = result { - completion(.failure(error)) - } else { - completion(.success(())) + func markArticles(for account: Account, articles: Set
, statusKey: ArticleStatus.Key, flag: Bool) async throws { + + try await withCheckedThrowingContinuation { continuation in + account.update(articles, statusKey: statusKey, flag: flag) { result in + switch result { + case .success: + continuation.resume() + case .failure(let error): + continuation.resume(throwing: error) + } } } } diff --git a/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift b/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift index 3ddf00ce5..4f7d4ab44 100644 --- a/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift +++ b/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift @@ -631,7 +631,21 @@ final class NewsBlurAccountDelegate: AccountDelegate { } } - func markArticles(for account: Account, articles: Set
, statusKey: ArticleStatus.Key, flag: Bool, completion: @escaping (Result) -> Void) { + func markArticles(for account: Account, articles: Set
, statusKey: ArticleStatus.Key, flag: Bool) async throws { + + try await withCheckedThrowingContinuation { continuation in + self.markArticles(for: account, articles: articles, statusKey: statusKey, flag: flag) { result in + switch result { + case .success: + continuation.resume() + case .failure(let error): + continuation.resume(throwing: error) + } + } + } + } + + private func markArticles(for account: Account, articles: Set
, statusKey: ArticleStatus.Key, flag: Bool, completion: @escaping (Result) -> Void) { account.update(articles, statusKey: statusKey, flag: flag) { result in switch result { case .success(let articles): diff --git a/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift b/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift index acd251cff..67c866a65 100644 --- a/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift +++ b/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift @@ -656,7 +656,21 @@ final class ReaderAPIAccountDelegate: AccountDelegate { } - func markArticles(for account: Account, articles: Set
, statusKey: ArticleStatus.Key, flag: Bool, completion: @escaping (Result) -> Void) { + func markArticles(for account: Account, articles: Set
, statusKey: ArticleStatus.Key, flag: Bool) async throws { + + try await withCheckedThrowingContinuation { continuation in + self.markArticles(for: account, articles: articles, statusKey: statusKey, flag: flag) { result in + switch result { + case .success: + continuation.resume() + case .failure(let error): + continuation.resume(throwing: error) + } + } + } + } + + private func markArticles(for account: Account, articles: Set
, statusKey: ArticleStatus.Key, flag: Bool, completion: @escaping (Result) -> Void) { account.update(articles, statusKey: statusKey, flag: flag) { result in switch result { case .success(let articles): diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index 5ab16d2a4..92898ebb1 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -1001,7 +1001,7 @@ private extension AppDelegate { return } - account.markArticles(articles, statusKey: .read, flag: true) { _ in } + try? await account.markArticles(articles, statusKey: .read, flag: true) } } @@ -1022,7 +1022,7 @@ private extension AppDelegate { return } - account.markArticles(articles, statusKey: .starred, flag: true) { _ in } + try? await account.markArticles(articles, statusKey: .starred, flag: true) } } } diff --git a/Shared/Extensions/ArticleUtilities.swift b/Shared/Extensions/ArticleUtilities.swift index 4e6bddc14..b2cbec712 100644 --- a/Shared/Extensions/ArticleUtilities.swift +++ b/Shared/Extensions/ArticleUtilities.swift @@ -23,11 +23,12 @@ import Account continue } group.enter() - account.markArticles(accountArticles, statusKey: statusKey, flag: flag) { _ in + Task { @MainActor in + try? await account.markArticles(accountArticles, statusKey: statusKey, flag: flag) group.leave() } } - + group.notify(queue: .main) { completion?() } diff --git a/iOS/AppDelegate.swift b/iOS/AppDelegate.swift index edb649c5c..a7b0bf016 100644 --- a/iOS/AppDelegate.swift +++ b/iOS/AppDelegate.swift @@ -449,11 +449,11 @@ private extension AppDelegate { return } - account.markArticles(articles, statusKey: .read, flag: true) { _ in } + try? await account.markArticles(articles, statusKey: .read, flag: true) self.prepareAccountsForBackground() - try? await account.syncArticleStatus + try? await account.syncArticleStatus() if !self.accountManager.isSuspended { try? WidgetDataEncoder.shared.encodeWidgetData() self.prepareAccountsForBackground() @@ -486,7 +486,7 @@ private extension AppDelegate { return } - account.markArticles(articles, statusKey: .starred, flag: true) { _ in } + try? await account.markArticles(articles, statusKey: .starred, flag: true) try? await account.syncArticleStatus() if !self.accountManager.isSuspended {