From 4fc1998cf3d6ca58b276136f57935849693b2f07 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Wed, 17 Jul 2019 15:41:21 -0500 Subject: [PATCH] Make Account and AccountDelegate interfaces more consistent by requiring the container parameter on removeFeed. Resolves #802 --- Frameworks/Account/Account.swift | 2 +- Frameworks/Account/AccountDelegate.swift | 2 +- .../Account/Feedbin/FeedbinAccountDelegate.swift | 2 +- .../Account/LocalAccount/LocalAccountDelegate.swift | 4 ++-- Mac/Scriptability/Account+Scriptability.swift | 4 +++- Shared/Commands/DeleteCommand.swift | 11 ++++++++++- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index 20347183b..cf29c7700 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -401,7 +401,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, return feed } - public func removeFeed(_ feed: Feed, from container: Container?, completion: @escaping (Result) -> Void) { + public func removeFeed(_ feed: Feed, from container: Container, completion: @escaping (Result) -> Void) { delegate.removeFeed(for: self, with: feed, from: container, completion: completion) } diff --git a/Frameworks/Account/AccountDelegate.swift b/Frameworks/Account/AccountDelegate.swift index 6c9cef9e2..3764186a0 100644 --- a/Frameworks/Account/AccountDelegate.swift +++ b/Frameworks/Account/AccountDelegate.swift @@ -36,7 +36,7 @@ protocol AccountDelegate { func createFeed(for account: Account, url: String, name: String?, container: Container, completion: @escaping (Result) -> Void) 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 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) func restoreFeed(for account: Account, feed: Feed, container: Container, completion: @escaping (Result) -> Void) diff --git a/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift b/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift index 8d28bc646..4286c04ed 100644 --- a/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift +++ b/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift @@ -392,7 +392,7 @@ final class FeedbinAccountDelegate: AccountDelegate { } - func removeFeed(for account: Account, with feed: Feed, from container: Container?, completion: @escaping (Result) -> Void) { + func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result) -> Void) { if feed.folderRelationship?.count ?? 0 > 1 { deleteTagging(for: account, with: feed, from: container, completion: completion) } else { diff --git a/Frameworks/Account/LocalAccount/LocalAccountDelegate.swift b/Frameworks/Account/LocalAccount/LocalAccountDelegate.swift index f54c12ad7..30d69a5d8 100644 --- a/Frameworks/Account/LocalAccount/LocalAccountDelegate.swift +++ b/Frameworks/Account/LocalAccount/LocalAccountDelegate.swift @@ -139,8 +139,8 @@ final class LocalAccountDelegate: AccountDelegate { completion(.success(())) } - func removeFeed(for account: Account, with feed: Feed, from container: Container?, completion: @escaping (Result) -> Void) { - container?.removeFeed(feed) + func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result) -> Void) { + container.removeFeed(feed) completion(.success(())) } diff --git a/Mac/Scriptability/Account+Scriptability.swift b/Mac/Scriptability/Account+Scriptability.swift index 80637f6be..a89e59522 100644 --- a/Mac/Scriptability/Account+Scriptability.swift +++ b/Mac/Scriptability/Account+Scriptability.swift @@ -58,8 +58,10 @@ class ScriptableAccount: NSObject, UniqueIdScriptingObject, ScriptingObjectConta var container: Container? = nil if let scriptableFolder = scriptableFeed.container as? ScriptableFolder { container = scriptableFolder.folder + } else { + container = account } - account.removeFeed(scriptableFeed.feed, from: container) { result in + account.removeFeed(scriptableFeed.feed, from: container!) { result in } } } diff --git a/Shared/Commands/DeleteCommand.swift b/Shared/Commands/DeleteCommand.swift index cb7f6f3cc..972ffcc8c 100644 --- a/Shared/Commands/DeleteCommand.swift +++ b/Shared/Commands/DeleteCommand.swift @@ -153,19 +153,28 @@ private struct SidebarItemSpecifier { func delete(completion: @escaping () -> Void) { if let feed = feed { + + guard let container = path.resolveContainer() else { + completion() + return + } + BatchUpdate.shared.start() - account?.removeFeed(feed, from: path.resolveContainer()) { result in + 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) } + } }