Convert restoreFolder to async/await.
This commit is contained in:
parent
8eb5a02849
commit
934a8c89fa
@ -651,8 +651,8 @@ public enum FetchType {
|
||||
delegate.renameFolder(for: self, with: folder, to: name, completion: completion)
|
||||
}
|
||||
|
||||
public func restoreFolder(_ folder: Folder, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
delegate.restoreFolder(for: self, folder: folder, completion: completion)
|
||||
public func restoreFolder(_ folder: Folder) async throws {
|
||||
try await delegate.restoreFolder(for: self, folder: folder)
|
||||
}
|
||||
|
||||
func clearFeedMetadata(_ feed: Feed) {
|
||||
|
@ -43,7 +43,7 @@ import Secrets
|
||||
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, completion: @escaping (Result<Void, Error>) -> Void)
|
||||
func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> Void)
|
||||
func restoreFolder(for account: Account, folder: Folder) async throws
|
||||
|
||||
func markArticles(for account: Account, articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) async throws
|
||||
// Called at the end of account’s init method.
|
||||
|
@ -435,7 +435,21 @@ enum CloudKitAccountDelegateError: LocalizedError {
|
||||
|
||||
}
|
||||
|
||||
func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
func restoreFolder(for account: Account, folder: Folder) async throws {
|
||||
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
self.restoreFolder(for: account, folder: folder) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume()
|
||||
case .failure(let error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
guard let name = folder.name else {
|
||||
completion(.failure(LocalAccountDelegateError.invalidParameter))
|
||||
return
|
||||
|
@ -575,7 +575,21 @@ final class FeedbinAccountDelegate: AccountDelegate {
|
||||
|
||||
}
|
||||
|
||||
func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
func restoreFolder(for account: Account, folder: Folder) async throws {
|
||||
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
self.restoreFolder(for: account, folder: folder) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume()
|
||||
case .failure(let error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
|
||||
let group = DispatchGroup()
|
||||
|
||||
|
@ -555,7 +555,21 @@ final class FeedlyAccountDelegate: AccountDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
func restoreFolder(for account: Account, folder: Folder) async throws {
|
||||
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
self.restoreFolder(for: account, folder: folder) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume()
|
||||
case .failure(let error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
let group = DispatchGroup()
|
||||
|
||||
for feed in folder.topLevelFeeds {
|
||||
|
@ -135,9 +135,8 @@ final class LocalAccountDelegate: AccountDelegate {
|
||||
completion(.success(()))
|
||||
}
|
||||
|
||||
func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
func restoreFolder(for account: Account, folder: Folder) async throws {
|
||||
account.addFolder(folder)
|
||||
completion(.success(()))
|
||||
}
|
||||
|
||||
func markArticles(for account: Account, articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) async throws {
|
||||
|
@ -603,7 +603,21 @@ final class NewsBlurAccountDelegate: AccountDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> ()) {
|
||||
func restoreFolder(for account: Account, folder: Folder) async throws {
|
||||
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
self.restoreFolder(for: account, folder: folder) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume()
|
||||
case .failure(let error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> ()) {
|
||||
guard let folderName = folder.name else {
|
||||
completion(.failure(NewsBlurError.invalidParameter))
|
||||
return
|
||||
|
@ -627,7 +627,21 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
|
||||
|
||||
}
|
||||
|
||||
func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
func restoreFolder(for account: Account, folder: Folder) async throws {
|
||||
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
self.restoreFolder(for: account, folder: folder) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume()
|
||||
case .failure(let error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
|
||||
let group = DispatchGroup()
|
||||
|
||||
|
@ -46,7 +46,7 @@ import Core
|
||||
}
|
||||
|
||||
func perform() {
|
||||
|
||||
|
||||
let group = DispatchGroup()
|
||||
itemSpecifiers.forEach {
|
||||
group.enter()
|
||||
@ -54,14 +54,14 @@ import Core
|
||||
group.leave()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
group.notify(queue: DispatchQueue.main) {
|
||||
self.treeController?.rebuild()
|
||||
self.registerUndo()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
func undo() {
|
||||
itemSpecifiers.forEach { $0.restore() }
|
||||
registerRedo()
|
||||
@ -137,36 +137,36 @@ import Core
|
||||
|
||||
self.account = account!
|
||||
self.path = ContainerPath(account: account!, folders: node.containingFolders())
|
||||
|
||||
|
||||
self.errorHandler = errorHandler
|
||||
|
||||
|
||||
}
|
||||
|
||||
func delete(completion: @escaping () -> Void) {
|
||||
|
||||
if let feed = feed {
|
||||
|
||||
|
||||
guard let container = path.resolveContainer() else {
|
||||
completion()
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
BatchUpdate.shared.start()
|
||||
account?.removeFeed(feed, from: container) { result in
|
||||
BatchUpdate.shared.end()
|
||||
completion()
|
||||
self.checkResult(result)
|
||||
}
|
||||
|
||||
|
||||
} else if let folder = folder {
|
||||
|
||||
|
||||
BatchUpdate.shared.start()
|
||||
account?.removeFolder(folder) { result in
|
||||
BatchUpdate.shared.end()
|
||||
completion()
|
||||
self.checkResult(result)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -185,31 +185,36 @@ import Core
|
||||
guard let account = account, let feed = feed, let container = path.resolveContainer() else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
BatchUpdate.shared.start()
|
||||
account.restoreFeed(feed, container: container) { result in
|
||||
BatchUpdate.shared.end()
|
||||
self.checkResult(result)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private func restoreFolder() {
|
||||
|
||||
guard let account = account, let folder = folder else {
|
||||
guard let account, let folder else {
|
||||
return
|
||||
}
|
||||
|
||||
BatchUpdate.shared.start()
|
||||
account.restoreFolder(folder) { result in
|
||||
BatchUpdate.shared.end()
|
||||
self.checkResult(result)
|
||||
|
||||
Task { @MainActor in
|
||||
BatchUpdate.shared.start()
|
||||
do {
|
||||
try await account.restoreFolder(folder)
|
||||
BatchUpdate.shared.end()
|
||||
|
||||
} catch {
|
||||
BatchUpdate.shared.end()
|
||||
self.errorHandler(error)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private func checkResult(_ result: Result<Void, Error>) {
|
||||
|
||||
|
||||
switch result {
|
||||
case .success:
|
||||
break
|
||||
@ -218,11 +223,11 @@ import Core
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private extension Node {
|
||||
|
||||
|
||||
func parentFolder() -> Folder? {
|
||||
|
||||
guard let parentNode = self.parent else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user