From 98fb69cb55b862a0e55d297f76f1e9fc2f4cd8cd Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Thu, 6 Nov 2025 21:00:43 -0800 Subject: [PATCH] Convert to async/await. --- Modules/Account/Sources/Account/Account.swift | 9 ++++++++- Modules/Account/Sources/Account/AccountDelegate.swift | 2 +- .../Account/CloudKit/CloudKitAccountDelegate.swift | 10 +++++++++- .../Account/Feedbin/FeedbinAccountDelegate.swift | 10 +++++++++- .../Sources/Account/Feedly/FeedlyAccountDelegate.swift | 10 +++++++++- .../Account/LocalAccount/LocalAccountDelegate.swift | 3 +-- .../Account/NewsBlur/NewsBlurAccountDelegate.swift | 10 +++++++++- .../Account/ReaderAPI/ReaderAPIAccountDelegate.swift | 10 +++++++++- 8 files changed, 55 insertions(+), 9 deletions(-) diff --git a/Modules/Account/Sources/Account/Account.swift b/Modules/Account/Sources/Account/Account.swift index 7749decb9..86937c696 100644 --- a/Modules/Account/Sources/Account/Account.swift +++ b/Modules/Account/Sources/Account/Account.swift @@ -595,7 +595,14 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, } public func renameFeed(_ feed: Feed, to name: String, completion: @escaping (Result) -> Void) { - delegate.renameFeed(for: self, with: feed, to: name, completion: completion) + Task { @MainActor in + do { + try await delegate.renameFeed(for: self, with: feed, to: name) + completion(.success(())) + } catch { + completion(.failure(error)) + } + } } public func restoreFeed(_ feed: Feed, container: Container, completion: @escaping (Result) -> Void) { diff --git a/Modules/Account/Sources/Account/AccountDelegate.swift b/Modules/Account/Sources/Account/AccountDelegate.swift index 68ff75720..233238a18 100644 --- a/Modules/Account/Sources/Account/AccountDelegate.swift +++ b/Modules/Account/Sources/Account/AccountDelegate.swift @@ -37,7 +37,7 @@ protocol AccountDelegate { func removeFolder(for account: Account, with folder: Folder, completion: @escaping (Result) -> Void) @MainActor func createFeed(for account: Account, url: String, name: String?, container: Container, validateFeed: Bool) async throws -> Feed - func renameFeed(for account: Account, with feed: Feed, to name: String, completion: @escaping (Result) -> Void) + @MainActor func renameFeed(for account: Account, with feed: Feed, to name: String) async throws func addFeed(for account: Account, with: Feed, to container: Container, completion: @escaping (Result) -> Void) func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result) -> Void) func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> Void) diff --git a/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift b/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift index 99d5ac952..3736d3ce1 100644 --- a/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift +++ b/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift @@ -214,7 +214,15 @@ final class CloudKitAccountDelegate: AccountDelegate { } } - func renameFeed(for account: Account, with feed: Feed, to name: String, completion: @escaping (Result) -> Void) { + @MainActor func renameFeed(for account: Account, with feed: Feed, to name: String) async throws { + try await withCheckedThrowingContinuation { continuation in + renameFeed(for: account, with: feed, to: name) { result in + continuation.resume(with: result) + } + } + } + + private func renameFeed(for account: Account, with feed: Feed, to name: String, completion: @escaping (Result) -> Void) { let editedName = name.isEmpty ? nil : name syncProgress.addToNumberOfTasksAndRemaining(1) accountZone.renameFeed(feed, editedName: editedName) { result in diff --git a/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift b/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift index 65f560ec5..137150f20 100644 --- a/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift +++ b/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift @@ -359,7 +359,15 @@ final class FeedbinAccountDelegate: AccountDelegate { } - func renameFeed(for account: Account, with feed: Feed, to name: String, completion: @escaping (Result) -> Void) { + @MainActor func renameFeed(for account: Account, with feed: Feed, to name: String) async throws { + try await withCheckedThrowingContinuation { continuation in + renameFeed(for: account, with: feed, to: name) { result in + continuation.resume(with: result) + } + } + } + + private func renameFeed(for account: Account, with feed: Feed, to name: String, completion: @escaping (Result) -> Void) { // This error should never happen guard let subscriptionID = feed.externalID else { diff --git a/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift b/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift index af7a34612..0921676b3 100644 --- a/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift +++ b/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift @@ -385,7 +385,15 @@ final class FeedlyAccountDelegate: AccountDelegate { } } - func renameFeed(for account: Account, with feed: Feed, to name: String, completion: @escaping (Result) -> Void) { + @MainActor func renameFeed(for account: Account, with feed: Feed, to name: String) async throws { + try await withCheckedThrowingContinuation { continuation in + renameFeed(for: account, with: feed, to: name) { result in + continuation.resume(with: result) + } + } + } + + private func renameFeed(for account: Account, with feed: Feed, to name: String, completion: @escaping (Result) -> Void) { let folderCollectionIds = account.folders?.filter { $0.has(feed) }.compactMap { $0.externalID } guard let collectionIds = folderCollectionIds, let collectionId = collectionIds.first else { completion(.failure(FeedlyAccountDelegateError.unableToRenameFeed(feed.nameForDisplay, name))) diff --git a/Modules/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift b/Modules/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift index 83f5b7744..06bf3493c 100644 --- a/Modules/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift +++ b/Modules/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift @@ -120,9 +120,8 @@ final class LocalAccountDelegate: AccountDelegate { } } - func renameFeed(for account: Account, with feed: Feed, to name: String, completion: @escaping (Result) -> Void) { + @MainActor func renameFeed(for account: Account, with feed: Feed, to name: String) async throws { feed.editedName = name - completion(.success(())) } func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result) -> Void) { diff --git a/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift b/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift index e5c2afb7b..0c2a21b10 100644 --- a/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift +++ b/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift @@ -477,7 +477,15 @@ final class NewsBlurAccountDelegate: AccountDelegate { } } - func renameFeed(for account: Account, with feed: Feed, to name: String, completion: @escaping (Result) -> ()) { + @MainActor func renameFeed(for account: Account, with feed: Feed, to name: String) async throws { + try await withCheckedThrowingContinuation { continuation in + renameFeed(for: account, with: feed, to: name) { result in + continuation.resume(with: result) + } + } + } + + private func renameFeed(for account: Account, with feed: Feed, to name: String, completion: @escaping (Result) -> ()) { guard let feedID = feed.externalID else { completion(.failure(NewsBlurError.invalidParameter)) return diff --git a/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift b/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift index 259e1c56f..b84457821 100644 --- a/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift +++ b/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift @@ -442,7 +442,15 @@ final class ReaderAPIAccountDelegate: AccountDelegate { } - func renameFeed(for account: Account, with feed: Feed, to name: String, completion: @escaping (Result) -> Void) { + @MainActor func renameFeed(for account: Account, with feed: Feed, to name: String) async throws { + try await withCheckedThrowingContinuation { continuation in + renameFeed(for: account, with: feed, to: name) { result in + continuation.resume(with: result) + } + } + } + + private func renameFeed(for account: Account, with feed: Feed, to name: String, completion: @escaping (Result) -> Void) { // This error should never happen guard let subscriptionID = feed.externalID else {