From 887e35068e7ab089273cabc5027d2abc5b6f9daf Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Tue, 26 Mar 2024 20:49:47 -0700 Subject: [PATCH] Convert receiveRemoteNotification to async/await. --- Account/Sources/Account/Account.swift | 10 +--------- Account/Sources/Account/AccountDelegate.swift | 2 +- .../Account/CloudKit/CloudKitAccountDelegate.swift | 11 ++++++++++- .../Account/Feedbin/FeedbinAccountDelegate.swift | 3 +-- .../Account/Feedly/FeedlyAccountDelegate.swift | 3 +-- .../Account/LocalAccount/LocalAccountDelegate.swift | 3 +-- .../Account/NewsBlur/NewsBlurAccountDelegate.swift | 5 ++--- .../Account/ReaderAPI/ReaderAPIAccountDelegate.swift | 5 ++--- 8 files changed, 19 insertions(+), 23 deletions(-) diff --git a/Account/Sources/Account/Account.swift b/Account/Sources/Account/Account.swift index e97b93e5c..6c306df6d 100644 --- a/Account/Sources/Account/Account.swift +++ b/Account/Sources/Account/Account.swift @@ -408,17 +408,9 @@ public enum FetchType { grantingType.requestOAuthAccessToken(with: response, transport: transport, secretsProvider: secretsProvider, completion: completion) } - - private func receiveRemoteNotification(userInfo: [AnyHashable : Any], completion: @escaping () -> Void) { - delegate.receiveRemoteNotification(for: self, userInfo: userInfo, completion: completion) - } public func receiveRemoteNotification(userInfo: [AnyHashable: Any]) async { - await withCheckedContinuation { continuation in - self.receiveRemoteNotification(userInfo: userInfo) { - continuation.resume() - } - } + await delegate.receiveRemoteNotification(for: self, userInfo: userInfo) } public func refreshAll() async throws { diff --git a/Account/Sources/Account/AccountDelegate.swift b/Account/Sources/Account/AccountDelegate.swift index 371fff7d0..e18be7ede 100644 --- a/Account/Sources/Account/AccountDelegate.swift +++ b/Account/Sources/Account/AccountDelegate.swift @@ -23,7 +23,7 @@ import Secrets var refreshProgress: DownloadProgress { get } - func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any], completion: @escaping () -> Void) + func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any]) async func refreshAll(for account: Account) async throws func syncArticleStatus(for account: Account) async throws diff --git a/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift b/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift index 7b28bc416..1a20a648b 100644 --- a/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift +++ b/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift @@ -69,7 +69,16 @@ enum CloudKitAccountDelegateError: LocalizedError { database = SyncDatabase(databasePath: databasePath) } - func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any], completion: @escaping () -> Void) { + func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any]) async { + + await withCheckedContinuation { continuation in + self.receiveRemoteNotification(for: account, userInfo: userInfo) { + continuation.resume() + } + } + } + + private func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any], completion: @escaping () -> Void) { let op = CloudKitRemoteNotificationOperation(accountZone: accountZone, articlesZone: articlesZone, userInfo: userInfo) op.completionBlock = { mainThreadOperaion in completion() diff --git a/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift b/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift index 0f99dbe8d..87611430a 100644 --- a/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift +++ b/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift @@ -75,8 +75,7 @@ final class FeedbinAccountDelegate: AccountDelegate { } - func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any], completion: @escaping () -> Void) { - completion() + func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any]) async { } func refreshAll(for account: Account) async throws { diff --git a/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift b/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift index 1e739cd60..2edddcbf2 100644 --- a/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift +++ b/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift @@ -104,8 +104,7 @@ final class FeedlyAccountDelegate: AccountDelegate { // MARK: Account API - func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any], completion: @escaping () -> Void) { - completion() + func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any]) async { } func refreshAll(for account: Account) async throws { diff --git a/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift b/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift index 793c86fe8..56838d7f0 100644 --- a/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift +++ b/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift @@ -40,8 +40,7 @@ final class LocalAccountDelegate: AccountDelegate { let refreshProgress = DownloadProgress(numberOfTasks: 0) - func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any], completion: @escaping () -> Void) { - completion() + func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any]) async { } func refreshAll(for account: Account) async throws { diff --git a/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift b/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift index 4f7d4ab44..6dd0d8324 100644 --- a/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift +++ b/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift @@ -57,10 +57,9 @@ final class NewsBlurAccountDelegate: AccountDelegate { database = SyncDatabase(databasePath: dataFolder.appending("/DB.sqlite3")) } - func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any], completion: @escaping () -> Void) { - completion() + func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any]) async { } - + func refreshAll(for account: Account) async throws { try await withCheckedThrowingContinuation { continuation in diff --git a/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift b/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift index 67c866a65..1bbcc5d26 100644 --- a/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift +++ b/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift @@ -101,10 +101,9 @@ final class ReaderAPIAccountDelegate: AccountDelegate { self.variant = variant } - func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any], completion: @escaping () -> Void) { - completion() + func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any]) async { } - + func refreshAll(for account: Account) async throws { try await withCheckedThrowingContinuation { continuation in