Convert account.rename to async/await.

This commit is contained in:
Brent Simmons
2023-10-07 11:30:38 -07:00
parent f042c97156
commit 490095fd73
7 changed files with 43 additions and 52 deletions

View File

@@ -630,10 +630,6 @@ public enum FetchType {
try await delegate.renameFeed(for: self, feed: feed, name: name)
}
public func renameFeed(_ feed: Feed, to name: String, completion: @escaping (Result<Void, Error>) -> Void) {
delegate.renameFeed(for: self, with: feed, to: name, completion: completion)
}
public func restoreFeed(_ feed: Feed, container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
delegate.restoreFeed(for: self, feed: feed, container: container, completion: completion)
}

View File

@@ -38,7 +38,6 @@ 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, feed: Feed, name: String) async throws
func renameFeed(for account: Account, with feed: Feed, to name: String, completion: @escaping (Result<Void, Error>) -> Void)
func addFeed(for account: Account, with: Feed, to container: Container, completion: @escaping (Result<Void, Error>) -> Void)
func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result<Void, Error>) -> Void)
func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result<Void, Error>) -> Void)

View File

@@ -1092,34 +1092,33 @@ private extension FeedbinAccountDelegate {
func createFeed( account: Account, subscription sub: FeedbinSubscription, name: String?, container: Container, completion: @escaping (Result<Feed, Error>) -> Void) {
DispatchQueue.main.async {
let feed = account.createFeed(with: sub.name, url: sub.url, feedID: String(sub.feedID), homePageURL: sub.homePageURL)
feed.externalID = String(sub.subscriptionID)
feed.iconURL = sub.jsonFeed?.icon
feed.faviconURL = sub.jsonFeed?.favicon
account.addFeed(feed, to: container) { result in
switch result {
case .success:
if let name = name {
account.renameFeed(feed, to: name) { result in
switch result {
case .success:
Task { @MainActor in
switch result {
case .success:
if let name {
do {
try await account.rename(feed, to: name)
self.initialFeedDownload(account: account, feed: feed, completion: completion)
case .failure(let error):
} catch {
completion(.failure(error))
}
}
} else {
self.initialFeedDownload(account: account, feed: feed, completion: completion)
else {
self.initialFeedDownload(account: account, feed: feed, completion: completion)
}
case .failure(let error):
completion(.failure(error))
}
case .failure(let error):
completion(.failure(error))
}
}
}
}
func initialFeedDownload( account: Account, feed: Feed, completion: @escaping (Result<Feed, Error>) -> Void) {

View File

@@ -390,34 +390,36 @@ extension NewsBlurAccountDelegate {
}
}
func createFeed(account: Account, newsBlurFeed: NewsBlurFeed?, name: String?, container: Container, completion: @escaping (Result<Feed, Error>) -> Void) {
func createFeed(account: Account, newsBlurFeed: NewsBlurFeed?, name: String?, container: Container, completion: @escaping (Result<Feed, Error>) -> Void) {
guard let newsBlurFeed = newsBlurFeed else {
completion(.failure(NewsBlurError.invalidParameter))
return
}
DispatchQueue.main.async {
let feed = account.createFeed(with: newsBlurFeed.name, url: newsBlurFeed.feedURL, feedID: String(newsBlurFeed.feedID), homePageURL: newsBlurFeed.homePageURL)
feed.externalID = String(newsBlurFeed.feedID)
feed.faviconURL = newsBlurFeed.faviconURL
feed.externalID = String(newsBlurFeed.feedID)
feed.faviconURL = newsBlurFeed.faviconURL
account.addFeed(feed, to: container) { result in
switch result {
case .success:
if let name = name {
account.renameFeed(feed, to: name) { result in
switch result {
case .success:
Task { @MainActor in
switch result {
case .success:
if let name {
do {
try await account.rename(feed, to: name)
self.initialFeedDownload(account: account, feed: feed, completion: completion)
case .failure(let error):
} catch {
completion(.failure(error))
}
}
} else {
self.initialFeedDownload(account: account, feed: feed, completion: completion)
else {
self.initialFeedDownload(account: account, feed: feed, completion: completion)
}
case .failure(let error):
completion(.failure(error))
}
case .failure(let error):
completion(.failure(error))
}
}
}

View File

@@ -11,7 +11,7 @@ import RSCore
import RSWeb
import Articles
public final class Feed: FeedProtocol, Renamable, Hashable, ObservableObject {
public final class Feed: FeedProtocol, Hashable, ObservableObject {
public var defaultReadFilterType: ReadFilterType {
return .none
@@ -217,11 +217,6 @@ public final class Feed: FeedProtocol, Renamable, Hashable, ObservableObject {
try await account.rename(self, to: newName)
}
@MainActor public func rename(to newName: String, completion: @escaping (Result<Void, Error>) -> Void) {
guard let account = account else { return }
account.renameFeed(self, to: newName, completion: completion)
}
// MARK: - UnreadCountProvider
public var unreadCount: Int {

View File

@@ -10,7 +10,7 @@ import Foundation
import Articles
import RSCore
public final class Folder: FeedProtocol, Renamable, Container, Hashable {
public final class Folder: FeedProtocol, Container, Hashable {
public var defaultReadFilterType: ReadFilterType {
return .read

View File

@@ -205,20 +205,20 @@ private extension FeedInspectorViewController {
}
func renameFeedIfNecessary() {
guard let feed = feed,
guard let feed,
let account = feed.account,
let nameTextField = nameTextField,
feed.nameForDisplay != nameTextField.stringValue else {
let newName = nameTextField?.stringValue,
feed.nameForDisplay != newName else {
return
}
account.renameFeed(feed, to: nameTextField.stringValue) { [weak self] result in
if case .failure(let error) = result {
self?.presentError(error)
} else {
self?.windowTitle = feed.nameForDisplay
Task { @MainActor in
do {
try await account.rename(feed, to: newName)
self.windowTitle = feed.nameForDisplay
} catch {
self.presentError(error)
}
}
}
}