Convert moveFeed to async await.

This commit is contained in:
Brent Simmons 2024-04-02 20:17:03 -07:00
parent 3e37388604
commit 323d0404f2
10 changed files with 97 additions and 22 deletions

View File

@ -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, Error>) -> 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 {

View File

@ -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, Error>) -> 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

View File

@ -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, Error>) -> 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, Error>) -> Void) {
refreshProgress.addToNumberOfTasksAndRemaining(1)
accountZone.moveFeed(feed, from: fromContainer, to: toContainer) { result in
self.refreshProgress.completeTask()

View File

@ -564,7 +564,21 @@ final class FeedbinAccountDelegate: AccountDelegate {
}
}
func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result<Void, Error>) -> 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, Error>) -> Void) {
if from is Account {
addFeed(for: account, with: feed, to: to, completion: completion)
} else {

View File

@ -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, Error>) -> Void) {
guard let from = from as? Folder, let to = to as? Folder else {
return DispatchQueue.main.async {

View File

@ -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, Error>) -> 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)

View File

@ -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<Void, Error>) -> ()) {
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, Error>) -> ()) {
guard let feedID = feed.externalID else {
completion(.failure(NewsBlurError.invalidParameter))
return

View File

@ -605,7 +605,21 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
}
}
func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result<Void, Error>) -> 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, Error>) -> Void) {
if from is Account {
addFeed(for: account, with: feed, to: to, completion: completion)
} else {

View File

@ -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)
}
}

View File

@ -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)
}
}