Convert removeFeed to async await.

This commit is contained in:
Brent Simmons
2024-03-28 09:28:16 -07:00
parent c5441bddc3
commit 4a4ece71f9
11 changed files with 119 additions and 44 deletions

View File

@@ -624,8 +624,9 @@ public enum FetchType {
return feed
}
public func removeFeed(_ feed: Feed, from container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
delegate.removeFeed(for: self, with: feed, from: container, completion: completion)
public func removeFeed(_ feed: Feed, from container: Container) async throws {
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) {

View File

@@ -39,7 +39,7 @@ import Secrets
func createFeed(for account: Account, url: String, name: String?, container: Container, validateFeed: Bool, completion: @escaping (Result<Feed, Error>) -> Void)
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, completion: @escaping (Result<Void, Error>) -> Void)
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 restoreFeed(for account: Account, feed: Feed, container: Container) async throws

View File

@@ -285,7 +285,22 @@ enum CloudKitAccountDelegateError: LocalizedError {
}
}
func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
func removeFeed(for account: Account, with feed: Feed, from container: any Container) async throws {
try await withCheckedThrowingContinuation { continuation in
self.removeFeed(for: account, with: feed, from: container) { result in
switch result {
case .success:
continuation.resume()
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}
private func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
removeFeedFromCloud(for: account, with: feed, from: container) { result in
switch result {
case .success:

View File

@@ -541,7 +541,22 @@ final class FeedbinAccountDelegate: AccountDelegate {
}
func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
func removeFeed(for account: Account, with feed: Feed, from container: any Container) async throws {
try await withCheckedThrowingContinuation { continuation in
self.removeFeed(for: account, with: feed, from: container) { result in
switch result {
case .success:
continuation.resume()
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}
private func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
if feed.folderRelationship?.count ?? 0 > 1 {
deleteTagging(for: account, with: feed, from: container, completion: completion)
} else {

View File

@@ -540,7 +540,22 @@ final class FeedlyAccountDelegate: AccountDelegate {
}
}
func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
func removeFeed(for account: Account, with feed: Feed, from container: any Container) async throws {
try await withCheckedThrowingContinuation { continuation in
self.removeFeed(for: account, with: feed, from: container) { result in
switch result {
case .success:
continuation.resume()
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}
private func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
guard let folder = container as? Folder, let collectionId = folder.externalID else {
return DispatchQueue.main.async {
completion(.failure(FeedlyAccountDelegateError.unableToRemoveFeed(feed.nameForDisplay)))

View File

@@ -96,9 +96,9 @@ final class LocalAccountDelegate: AccountDelegate {
feed.editedName = name
}
func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
func removeFeed(for account: Account, with feed: Feed, from container: any Container) async throws {
container.removeFeed(feed)
completion(.success(()))
}
func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result<Void, Error>) -> Void) {

View File

@@ -610,7 +610,22 @@ final class NewsBlurAccountDelegate: AccountDelegate {
completion(.success(()))
}
func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result<Void, Error>) -> ()) {
func removeFeed(for account: Account, with feed: Feed, from container: any Container) async throws {
try await withCheckedThrowingContinuation { continuation in
self.removeFeed(for: account, with: feed, from: container) { result in
switch result {
case .success:
continuation.resume()
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}
private func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result<Void, Error>) -> ()) {
deleteFeed(for: account, with: feed, from: container, completion: completion)
}

View File

@@ -560,7 +560,22 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
}
func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
func removeFeed(for account: Account, with feed: Feed, from container: any Container) async throws {
try await withCheckedThrowingContinuation { continuation in
self.removeFeed(for: account, with: feed, from: container) { result in
switch result {
case .success:
continuation.resume()
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}
private func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
guard let subscriptionID = feed.externalID else {
completion(.failure(ReaderAPIAccountDelegateError.invalidParameter))
return

View File

@@ -51,11 +51,12 @@ import Core
}
@MainActor func deleteElement(_ element:ScriptingObject) {
if let scriptableFeed = element as? ScriptableFeed {
BatchUpdate.shared.perform {
folder.account?.removeFeed(scriptableFeed.feed, from: folder) { result in }
}
}
// TODO: fix this
// if let scriptableFeed = element as? ScriptableFeed {
// BatchUpdate.shared.perform {
// folder.account?.removeFeed(scriptableFeed.feed, from: folder) { result in }
// }
// }
}
// MARK: --- handle NSCreateCommand ---

View File

@@ -152,12 +152,19 @@ import Core
}
BatchUpdate.shared.start()
account?.removeFeed(feed, from: container) { result in
BatchUpdate.shared.end()
completion()
self.checkResult(result)
Task { @MainActor in
do {
try await account?.removeFeed(feed, from: container)
BatchUpdate.shared.end()
completion()
} catch {
BatchUpdate.shared.end()
completion()
self.errorHandler(error)
}
}
} else if let folder = folder {
BatchUpdate.shared.start()

View File

@@ -125,17 +125,8 @@ extension SidebarViewController: UITableViewDropDelegate {
do {
try await destinationContainer.account?.addFeed(existingFeed, to: destinationContainer)
sourceContainer.account?.removeFeed(feed, from: sourceContainer) { result in
BatchUpdate.shared.end()
switch result {
case .success:
break
case .failure(let error):
self.presentError(error)
}
}
try await sourceContainer.account?.removeFeed(feed, from: sourceContainer)
BatchUpdate.shared.end()
} catch {
BatchUpdate.shared.end()
self.presentError(error)
@@ -148,23 +139,23 @@ extension SidebarViewController: UITableViewDropDelegate {
destinationContainer.account?.createFeed(url: feed.url, name: feed.editedName, container: destinationContainer, validateFeed: false) { result in
switch result {
case .success:
sourceContainer.account?.removeFeed(feed, from: sourceContainer) { result in
BatchUpdate.shared.end()
switch result {
case .success:
break
case .failure(let error):
Task { @MainActor in
do {
try await sourceContainer.account?.removeFeed(feed, from: sourceContainer)
BatchUpdate.shared.end()
} catch {
BatchUpdate.shared.end()
self.presentError(error)
}
}
case .failure(let error):
BatchUpdate.shared.end()
self.presentError(error)
case .failure(let error):
BatchUpdate.shared.end()
self.presentError(error)
}
}
}
}
}
}