diff --git a/Account/Sources/Account/Account.swift b/Account/Sources/Account/Account.swift index 1d28a8597..fc2054a95 100644 --- a/Account/Sources/Account/Account.swift +++ b/Account/Sources/Account/Account.swift @@ -629,8 +629,9 @@ public enum FetchType { try await delegate.removeFeed(for: self, with: feed, from: container) } - public func moveFeed(_ feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> Void) { - delegate.moveFeed(for: self, with: feed, from: from, to: to, completion: completion) + public func moveFeed(_ feed: Feed, from: Container, to: Container) async throws { + + try await delegate.moveFeed(for: self, with: feed, from: from, to: to) } public func renameFeed(_ feed: Feed, to name: String) async throws { diff --git a/Account/Sources/Account/AccountDelegate.swift b/Account/Sources/Account/AccountDelegate.swift index 1d40c7ed2..6b0f30872 100644 --- a/Account/Sources/Account/AccountDelegate.swift +++ b/Account/Sources/Account/AccountDelegate.swift @@ -40,7 +40,7 @@ import Secrets func renameFeed(for account: Account, with feed: Feed, to name: String) async throws func addFeed(for account: Account, with: Feed, to container: Container) async throws func removeFeed(for account: Account, with feed: Feed, from container: Container) async throws - func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> Void) + func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container) async throws func restoreFeed(for account: Account, feed: Feed, container: Container) async throws func restoreFolder(for account: Account, folder: Folder) async throws diff --git a/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift b/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift index dfa45eff9..0c21b4fe6 100644 --- a/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift +++ b/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift @@ -320,7 +320,21 @@ enum CloudKitAccountDelegateError: LocalizedError { } } - func moveFeed(for account: Account, with feed: Feed, from fromContainer: Container, to toContainer: Container, completion: @escaping (Result) -> Void) { + func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container) async throws { + + try await withCheckedThrowingContinuation { continuation in + self.moveFeed(for: account, with: feed, from: from, to: to) { result in + switch result { + case .success: + continuation.resume() + case .failure(let error): + continuation.resume(throwing: error) + } + } + } + } + + private func moveFeed(for account: Account, with feed: Feed, from fromContainer: Container, to toContainer: Container, completion: @escaping (Result) -> Void) { refreshProgress.addToNumberOfTasksAndRemaining(1) accountZone.moveFeed(feed, from: fromContainer, to: toContainer) { result in self.refreshProgress.completeTask() diff --git a/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift b/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift index 53d9b9154..3566e1313 100644 --- a/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift +++ b/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift @@ -564,7 +564,21 @@ final class FeedbinAccountDelegate: AccountDelegate { } } - func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> Void) { + func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container) async throws { + + try await withCheckedThrowingContinuation { continuation in + self.moveFeed(for: account, with: feed, from: from, to: to) { result in + switch result { + case .success: + continuation.resume() + case .failure(let error): + continuation.resume(throwing: error) + } + } + } + } + + private func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> Void) { if from is Account { addFeed(for: account, with: feed, to: to, completion: completion) } else { diff --git a/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift b/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift index a103ce664..7fe1e0bf5 100644 --- a/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift +++ b/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift @@ -575,6 +575,20 @@ final class FeedlyAccountDelegate: AccountDelegate { folder.removeFeed(feed) } + func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container) async throws { + + try await withCheckedThrowingContinuation { continuation in + self.moveFeed(for: account, with: feed, from: from, to: to) { result in + switch result { + case .success: + continuation.resume() + case .failure(let error): + continuation.resume(throwing: error) + } + } + } + } + @MainActor func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> Void) { guard let from = from as? Folder, let to = to as? Folder else { return DispatchQueue.main.async { diff --git a/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift b/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift index 97afbf4e3..089e0d2e4 100644 --- a/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift +++ b/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift @@ -101,12 +101,12 @@ final class LocalAccountDelegate: AccountDelegate { container.removeFeed(feed) } - func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> Void) { + func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container) async throws { + from.removeFeed(feed) to.addFeed(feed) - completion(.success(())) } - + func addFeed(for account: Account, with feed: Feed, to container: any Container) async throws { container.addFeed(feed) diff --git a/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift b/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift index ece731373..47b561d60 100644 --- a/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift +++ b/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift @@ -629,7 +629,21 @@ final class NewsBlurAccountDelegate: AccountDelegate { deleteFeed(for: account, with: feed, from: container, completion: completion) } - func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> ()) { + func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container) async throws { + + try await withCheckedThrowingContinuation { continuation in + self.moveFeed(for: account, with: feed, from: from, to: to) { result in + switch result { + case .success: + continuation.resume() + case .failure(let error): + continuation.resume(throwing: error) + } + } + } + } + + private func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> ()) { guard let feedID = feed.externalID else { completion(.failure(NewsBlurError.invalidParameter)) return diff --git a/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift b/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift index 925c03624..3bf88103f 100644 --- a/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift +++ b/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift @@ -605,7 +605,21 @@ final class ReaderAPIAccountDelegate: AccountDelegate { } } - func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> Void) { + func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container) async throws { + + try await withCheckedThrowingContinuation { continuation in + self.moveFeed(for: account, with: feed, from: from, to: to) { result in + switch result { + case .success: + continuation.resume() + case .failure(let error): + continuation.resume(throwing: error) + } + } + } + } + + private func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> Void) { if from is Account { addFeed(for: account, with: feed, to: to, completion: completion) } else { diff --git a/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift b/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift index 43bdb8c76..03cf2ccea 100644 --- a/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift +++ b/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift @@ -331,12 +331,14 @@ private extension SidebarOutlineDataSource { } BatchUpdate.shared.start() - source.account?.moveFeed(feed, from: source, to: destination) { result in - BatchUpdate.shared.end() - switch result { - case .success: - break - case .failure(let error): + + Task { @MainActor in + + do { + try await source.account?.moveFeed(feed, from: source, to: destination) + BatchUpdate.shared.end() + } catch { + BatchUpdate.shared.end() NSApplication.shared.presentError(error) } } diff --git a/iOS/Feeds/FeedsViewController+Drop.swift b/iOS/Feeds/FeedsViewController+Drop.swift index 11e022fc5..b7c2282a6 100644 --- a/iOS/Feeds/FeedsViewController+Drop.swift +++ b/iOS/Feeds/FeedsViewController+Drop.swift @@ -104,12 +104,14 @@ extension SidebarViewController: UITableViewDropDelegate { guard sourceContainer !== destinationContainer else { return } BatchUpdate.shared.start() - sourceContainer.account?.moveFeed(feed, from: sourceContainer, to: destinationContainer) { result in - BatchUpdate.shared.end() - switch result { - case .success: - break - case .failure(let error): + + Task { @MainActor in + + do { + try await sourceContainer.account?.moveFeed(feed, from: sourceContainer, to: destinationContainer) + BatchUpdate.shared.end() + } catch { + BatchUpdate.shared.end() self.presentError(error) } }