diff --git a/Account/Sources/Account/Account.swift b/Account/Sources/Account/Account.swift index dd0f4dc16..3f27c6b22 100644 --- a/Account/Sources/Account/Account.swift +++ b/Account/Sources/Account/Account.swift @@ -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) { - delegate.renameFeed(for: self, with: feed, to: name, completion: completion) - } - public func restoreFeed(_ feed: Feed, container: Container, completion: @escaping (Result) -> Void) { delegate.restoreFeed(for: self, feed: feed, container: container, completion: completion) } diff --git a/Account/Sources/Account/AccountDelegate.swift b/Account/Sources/Account/AccountDelegate.swift index fbbe0333b..1c4629b83 100644 --- a/Account/Sources/Account/AccountDelegate.swift +++ b/Account/Sources/Account/AccountDelegate.swift @@ -38,7 +38,6 @@ import Secrets func createFeed(for account: Account, url: String, name: String?, container: Container, validateFeed: Bool, completion: @escaping (Result) -> 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) func addFeed(for account: Account, with: Feed, to container: Container, completion: @escaping (Result) -> Void) func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result) -> Void) func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> Void) diff --git a/Account/Sources/Account/AccountDelegates/FeedbinAccountDelegate.swift b/Account/Sources/Account/AccountDelegates/FeedbinAccountDelegate.swift index 0ebda2bbb..8a1760d93 100644 --- a/Account/Sources/Account/AccountDelegates/FeedbinAccountDelegate.swift +++ b/Account/Sources/Account/AccountDelegates/FeedbinAccountDelegate.swift @@ -1092,34 +1092,33 @@ private extension FeedbinAccountDelegate { func createFeed( account: Account, subscription sub: FeedbinSubscription, name: String?, container: Container, completion: @escaping (Result) -> 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) -> Void) { diff --git a/Account/Sources/Account/AccountDelegates/NewsBlurAccountDelegate+Internal.swift b/Account/Sources/Account/AccountDelegates/NewsBlurAccountDelegate+Internal.swift index 3b52f05a4..b93d06dfb 100644 --- a/Account/Sources/Account/AccountDelegates/NewsBlurAccountDelegate+Internal.swift +++ b/Account/Sources/Account/AccountDelegates/NewsBlurAccountDelegate+Internal.swift @@ -390,34 +390,36 @@ extension NewsBlurAccountDelegate { } } - func createFeed(account: Account, newsBlurFeed: NewsBlurFeed?, name: String?, container: Container, completion: @escaping (Result) -> Void) { + func createFeed(account: Account, newsBlurFeed: NewsBlurFeed?, name: String?, container: Container, completion: @escaping (Result) -> 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)) } } } diff --git a/Account/Sources/Account/Feed.swift b/Account/Sources/Account/Feed.swift index 1224638d8..f6c35e163 100644 --- a/Account/Sources/Account/Feed.swift +++ b/Account/Sources/Account/Feed.swift @@ -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) { - guard let account = account else { return } - account.renameFeed(self, to: newName, completion: completion) - } - // MARK: - UnreadCountProvider public var unreadCount: Int { diff --git a/Account/Sources/Account/Folder.swift b/Account/Sources/Account/Folder.swift index a83c44a19..c92216b8c 100644 --- a/Account/Sources/Account/Folder.swift +++ b/Account/Sources/Account/Folder.swift @@ -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 diff --git a/Mac/Inspector/FeedInspectorViewController.swift b/Mac/Inspector/FeedInspectorViewController.swift index 2643fb4a8..95fb3582e 100644 --- a/Mac/Inspector/FeedInspectorViewController.swift +++ b/Mac/Inspector/FeedInspectorViewController.swift @@ -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) } } } - }