Make Account and AccountDelegate interfaces more consistent by requiring the container parameter on removeFeed. Resolves #802

This commit is contained in:
Maurice Parker 2019-07-17 15:41:21 -05:00
parent 48c5b67f57
commit 4fc1998cf3
6 changed files with 18 additions and 7 deletions

View File

@ -401,7 +401,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
return feed return feed
} }
public func removeFeed(_ feed: Feed, from container: Container?, completion: @escaping (Result<Void, Error>) -> Void) { public func removeFeed(_ feed: Feed, from container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
delegate.removeFeed(for: self, with: feed, from: container, completion: completion) delegate.removeFeed(for: self, with: feed, from: container, completion: completion)
} }

View File

@ -36,7 +36,7 @@ protocol AccountDelegate {
func createFeed(for account: Account, url: String, name: String?, container: Container, completion: @escaping (Result<Feed, Error>) -> Void) func createFeed(for account: Account, url: String, name: String?, container: Container, completion: @escaping (Result<Feed, Error>) -> Void)
func renameFeed(for account: Account, with feed: Feed, to name: String, completion: @escaping (Result<Void, Error>) -> Void) 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 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 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) 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 restoreFeed(for account: Account, feed: Feed, container: Container, completion: @escaping (Result<Void, Error>) -> Void)

View File

@ -392,7 +392,7 @@ 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: Container, completion: @escaping (Result<Void, Error>) -> Void) {
if feed.folderRelationship?.count ?? 0 > 1 { if feed.folderRelationship?.count ?? 0 > 1 {
deleteTagging(for: account, with: feed, from: container, completion: completion) deleteTagging(for: account, with: feed, from: container, completion: completion)
} else { } else {

View File

@ -139,8 +139,8 @@ final class LocalAccountDelegate: AccountDelegate {
completion(.success(())) completion(.success(()))
} }
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, completion: @escaping (Result<Void, Error>) -> Void) {
container?.removeFeed(feed) container.removeFeed(feed)
completion(.success(())) completion(.success(()))
} }

View File

@ -58,8 +58,10 @@ class ScriptableAccount: NSObject, UniqueIdScriptingObject, ScriptingObjectConta
var container: Container? = nil var container: Container? = nil
if let scriptableFolder = scriptableFeed.container as? ScriptableFolder { if let scriptableFolder = scriptableFeed.container as? ScriptableFolder {
container = scriptableFolder.folder container = scriptableFolder.folder
} else {
container = account
} }
account.removeFeed(scriptableFeed.feed, from: container) { result in account.removeFeed(scriptableFeed.feed, from: container!) { result in
} }
} }
} }

View File

@ -153,19 +153,28 @@ private struct SidebarItemSpecifier {
func delete(completion: @escaping () -> Void) { func delete(completion: @escaping () -> Void) {
if let feed = feed { if let feed = feed {
guard let container = path.resolveContainer() else {
completion()
return
}
BatchUpdate.shared.start() BatchUpdate.shared.start()
account?.removeFeed(feed, from: path.resolveContainer()) { result in account?.removeFeed(feed, from: container) { result in
BatchUpdate.shared.end() BatchUpdate.shared.end()
completion() completion()
self.checkResult(result) self.checkResult(result)
} }
} else if let folder = folder { } else if let folder = folder {
BatchUpdate.shared.start() BatchUpdate.shared.start()
account?.removeFolder(folder) { result in account?.removeFolder(folder) { result in
BatchUpdate.shared.end() BatchUpdate.shared.end()
completion() completion()
self.checkResult(result) self.checkResult(result)
} }
} }
} }