diff --git a/Modules/Account/Sources/Account/Account.swift b/Modules/Account/Sources/Account/Account.swift index 9fdd1921d..b2a500155 100644 --- a/Modules/Account/Sources/Account/Account.swift +++ b/Modules/Account/Sources/Account/Account.swift @@ -628,7 +628,14 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, } public func removeFolder(_ folder: Folder, completion: @escaping (Result) -> Void) { - delegate.removeFolder(for: self, with: folder, completion: completion) + Task { @MainActor in + do { + try await delegate.removeFolder(for: self, with: folder) + completion(.success(())) + } catch { + completion(.failure(error)) + } + } } public func renameFolder(_ folder: Folder, to name: String) async throws { diff --git a/Modules/Account/Sources/Account/AccountDelegate.swift b/Modules/Account/Sources/Account/AccountDelegate.swift index a5d27c7da..d2d11e48a 100644 --- a/Modules/Account/Sources/Account/AccountDelegate.swift +++ b/Modules/Account/Sources/Account/AccountDelegate.swift @@ -34,7 +34,7 @@ protocol AccountDelegate { @MainActor func createFolder(for account: Account, name: String) async throws -> Folder @MainActor func renameFolder(for account: Account, with folder: Folder, to name: String) async throws - func removeFolder(for account: Account, with folder: Folder, completion: @escaping (Result) -> Void) + @MainActor func removeFolder(for account: Account, with folder: Folder) async throws @MainActor func createFeed(for account: Account, url: String, name: String?, container: Container, validateFeed: Bool) async throws -> Feed @MainActor func renameFeed(for account: Account, with feed: Feed, to name: String) async throws diff --git a/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift b/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift index aa1878aac..5bae6b17c 100644 --- a/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift +++ b/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift @@ -340,7 +340,15 @@ final class CloudKitAccountDelegate: AccountDelegate { } } - func removeFolder(for account: Account, with folder: Folder, completion: @escaping (Result) -> Void) { + @MainActor func removeFolder(for account: Account, with folder: Folder) async throws { + try await withCheckedThrowingContinuation { continuation in + removeFolder(for: account, with: folder) { result in + continuation.resume(with: result) + } + } + } + + private func removeFolder(for account: Account, with folder: Folder, completion: @escaping (Result) -> Void) { syncProgress.addToNumberOfTasksAndRemaining(2) accountZone.findFeedExternalIDs(for: folder) { result in diff --git a/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift b/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift index 94cf77860..3facd530b 100644 --- a/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift +++ b/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift @@ -265,7 +265,15 @@ final class FeedbinAccountDelegate: AccountDelegate { } - func removeFolder(for account: Account, with folder: Folder, completion: @escaping (Result) -> Void) { + @MainActor func removeFolder(for account: Account, with folder: Folder) async throws { + try await withCheckedThrowingContinuation { continuation in + removeFolder(for: account, with: folder) { result in + continuation.resume(with: result) + } + } + } + + private func removeFolder(for account: Account, with folder: Folder, completion: @escaping (Result) -> Void) { // Feedbin uses tags and if at least one feed isn't tagged, then the folder doesn't exist on their system guard folder.hasAtLeastOneFeed() else { diff --git a/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift b/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift index 9a09aea07..31ca09db5 100644 --- a/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift +++ b/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift @@ -331,7 +331,15 @@ final class FeedlyAccountDelegate: AccountDelegate { folder.name = name } - func removeFolder(for account: Account, with folder: Folder, completion: @escaping (Result) -> Void) { + @MainActor func removeFolder(for account: Account, with folder: Folder) async throws { + try await withCheckedThrowingContinuation { continuation in + removeFolder(for: account, with: folder) { result in + continuation.resume(with: result) + } + } + } + + private func removeFolder(for account: Account, with folder: Folder, completion: @escaping (Result) -> Void) { guard let id = folder.externalID else { return DispatchQueue.main.async { completion(.failure(FeedlyAccountDelegateError.unableToRemoveFolder(folder.nameForDisplay))) diff --git a/Modules/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift b/Modules/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift index 0cc4ea70c..953605d4a 100644 --- a/Modules/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift +++ b/Modules/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift @@ -128,9 +128,8 @@ final class LocalAccountDelegate: AccountDelegate { folder.name = name } - func removeFolder(for account: Account, with folder: Folder, completion: @escaping (Result) -> Void) { + @MainActor func removeFolder(for account: Account, with folder: Folder) async throws { account.removeFolderFromTree(folder) - completion(.success(())) } @MainActor func restoreFolder(for account: Account, folder: Folder) async throws { diff --git a/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift b/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift index a87e21702..7fab03d60 100644 --- a/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift +++ b/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift @@ -420,7 +420,15 @@ final class NewsBlurAccountDelegate: AccountDelegate { folder.name = name } - func removeFolder(for account: Account, with folder: Folder, completion: @escaping (Result) -> ()) { + @MainActor func removeFolder(for account: Account, with folder: Folder) async throws { + try await withCheckedThrowingContinuation { continuation in + removeFolder(for: account, with: folder) { result in + continuation.resume(with: result) + } + } + } + + private func removeFolder(for account: Account, with folder: Folder, completion: @escaping (Result) -> ()) { guard let folderToRemove = folder.name 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 d8cd3c4af..a58f543dd 100644 --- a/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift +++ b/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift @@ -322,7 +322,15 @@ final class ReaderAPIAccountDelegate: AccountDelegate { } - func removeFolder(for account: Account, with folder: Folder, completion: @escaping (Result) -> Void) { + @MainActor func removeFolder(for account: Account, with folder: Folder) async throws { + try await withCheckedThrowingContinuation { continuation in + removeFolder(for: account, with: folder) { result in + continuation.resume(with: result) + } + } + } + + private func removeFolder(for account: Account, with folder: Folder, completion: @escaping (Result) -> Void) { let group = DispatchGroup()