Modify Feedbin feed deletes so that they emulate how the local account feed deletes work.
This commit is contained in:
parent
7bec55c90b
commit
1352dda8aa
@ -396,10 +396,13 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
|||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
feedMetadata[feed.url] = nil
|
|
||||||
delegate.removeFeed(for: self, with: feed, from: container, completion: completion)
|
delegate.removeFeed(for: self, with: feed, from: container, completion: completion)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func moveFeed(_ feed: Feed, from: Container, to: Container, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||||
|
delegate.moveFeed(for: self, with: feed, from: from, to: to, completion: completion)
|
||||||
|
}
|
||||||
|
|
||||||
public func renameFeed(_ feed: Feed, to name: String, completion: @escaping (Result<Void, Error>) -> Void) {
|
public func renameFeed(_ feed: Feed, to name: String, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||||
delegate.renameFeed(for: self, with: feed, to: name, completion: completion)
|
delegate.renameFeed(for: self, with: feed, to: name, completion: completion)
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ protocol AccountDelegate {
|
|||||||
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 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)
|
||||||
func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> Void)
|
func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> Void)
|
||||||
|
@ -341,35 +341,28 @@ 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 {
|
||||||
// This error should never happen
|
deleteTagging(for: account, with: feed, from: container, completion: completion)
|
||||||
guard let subscriptionID = feed.subscriptionID else {
|
} else {
|
||||||
completion(.failure(FeedbinAccountDelegateError.invalidParameter))
|
deleteSubscription(for: account, with: feed, from: container, completion: completion)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
caller.deleteSubscription(subscriptionID: subscriptionID) { result in
|
|
||||||
switch result {
|
func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||||
case .success:
|
if from is Account {
|
||||||
DispatchQueue.main.async {
|
addFeed(for: account, with: feed, to: to, completion: completion)
|
||||||
account.removeFeed(feed)
|
} else {
|
||||||
if let folders = account.folders {
|
deleteTagging(for: account, with: feed, from: from) { result in
|
||||||
for folder in folders {
|
switch result {
|
||||||
folder.removeFeed(feed)
|
case .success:
|
||||||
}
|
self.addFeed(for: account, with: feed, to: to, completion: completion)
|
||||||
}
|
case .failure(let error):
|
||||||
completion(.success(()))
|
completion(.failure(error))
|
||||||
}
|
|
||||||
case .failure(let error):
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
let wrappedError = AccountError.wrappedError(error: error, account: account)
|
|
||||||
completion(.failure(wrappedError))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func addFeed(for account: Account, with feed: Feed, to container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
|
func addFeed(for account: Account, with feed: Feed, to container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||||
|
|
||||||
if let folder = container as? Folder, let feedID = Int(feed.feedID) {
|
if let folder = container as? Folder, let feedID = Int(feed.feedID) {
|
||||||
@ -390,43 +383,16 @@ final class FeedbinAccountDelegate: AccountDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if let account = container as? Account {
|
|
||||||
account.addFeedIfNotInAnyFolder(feed)
|
|
||||||
}
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
if let account = container as? Account {
|
||||||
|
account.addFeedIfNotInAnyFolder(feed)
|
||||||
|
}
|
||||||
completion(.success(()))
|
completion(.success(()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeFeed(for account: Account, from container: Container, with feed: Feed, completion: @escaping (Result<Void, Error>) -> Void) {
|
|
||||||
|
|
||||||
if let folder = container as? Folder, let feedTaggingID = feed.folderRelationship?[folder.name ?? ""] {
|
|
||||||
caller.deleteTagging(taggingID: feedTaggingID) { result in
|
|
||||||
switch result {
|
|
||||||
case .success:
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
folder.removeFeed(feed)
|
|
||||||
account.addFeedIfNotInAnyFolder(feed)
|
|
||||||
completion(.success(()))
|
|
||||||
}
|
|
||||||
case .failure(let error):
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
let wrappedError = AccountError.wrappedError(error: error, account: account)
|
|
||||||
completion(.failure(wrappedError))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if let account = container as? Account {
|
|
||||||
account.removeFeed(feed)
|
|
||||||
}
|
|
||||||
completion(.success(()))
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
||||||
|
|
||||||
createFeed(for: account, url: feed.url, name: feed.editedName, container: container) { result in
|
createFeed(for: account, url: feed.url, name: feed.editedName, container: container) { result in
|
||||||
@ -1148,5 +1114,63 @@ private extension FeedbinAccountDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func deleteTagging(for account: Account, with feed: Feed, from container: Container?, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||||
|
|
||||||
|
if let folder = container as? Folder, let feedTaggingID = feed.folderRelationship?[folder.name ?? ""] {
|
||||||
|
caller.deleteTagging(taggingID: feedTaggingID) { result in
|
||||||
|
switch result {
|
||||||
|
case .success:
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
feed.folderRelationship?.removeValue(forKey: folder.name ?? "")
|
||||||
|
folder.removeFeed(feed)
|
||||||
|
account.addFeedIfNotInAnyFolder(feed)
|
||||||
|
completion(.success(()))
|
||||||
|
}
|
||||||
|
case .failure(let error):
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
let wrappedError = AccountError.wrappedError(error: error, account: account)
|
||||||
|
completion(.failure(wrappedError))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if let account = container as? Account {
|
||||||
|
account.removeFeed(feed)
|
||||||
|
}
|
||||||
|
completion(.success(()))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func deleteSubscription(for account: Account, with feed: Feed, from container: Container?, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||||
|
|
||||||
|
// This error should never happen
|
||||||
|
guard let subscriptionID = feed.subscriptionID else {
|
||||||
|
completion(.failure(FeedbinAccountDelegateError.invalidParameter))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
caller.deleteSubscription(subscriptionID: subscriptionID) { result in
|
||||||
|
switch result {
|
||||||
|
case .success:
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
account.removeFeed(feed)
|
||||||
|
if let folders = account.folders {
|
||||||
|
for folder in folders {
|
||||||
|
folder.removeFeed(feed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
completion(.success(()))
|
||||||
|
}
|
||||||
|
case .failure(let error):
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
let wrappedError = AccountError.wrappedError(error: error, account: account)
|
||||||
|
completion(.failure(wrappedError))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -127,6 +127,12 @@ final class LocalAccountDelegate: AccountDelegate {
|
|||||||
completion(.success(()))
|
completion(.success(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||||
|
from.removeFeed(feed)
|
||||||
|
to.addFeed(feed)
|
||||||
|
completion(.success(()))
|
||||||
|
}
|
||||||
|
|
||||||
func addFeed(for account: Account, with feed: Feed, to container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
|
func addFeed(for account: Account, with feed: Feed, to container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||||
container.addFeed(feed)
|
container.addFeed(feed)
|
||||||
completion(.success(()))
|
completion(.success(()))
|
||||||
|
@ -307,18 +307,10 @@ private extension SidebarOutlineDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BatchUpdate.shared.start()
|
BatchUpdate.shared.start()
|
||||||
source.account?.removeFeed(feed, from: source) { result in
|
source.account?.moveFeed(feed, from: source, to: destination) { result in
|
||||||
switch result {
|
switch result {
|
||||||
case .success:
|
case .success:
|
||||||
destination.account?.addFeed(feed, to: destination) { result in
|
BatchUpdate.shared.end()
|
||||||
BatchUpdate.shared.end()
|
|
||||||
switch result {
|
|
||||||
case .success:
|
|
||||||
break
|
|
||||||
case .failure(let error):
|
|
||||||
NSApplication.shared.presentError(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case .failure(let error):
|
case .failure(let error):
|
||||||
NSApplication.shared.presentError(error)
|
NSApplication.shared.presentError(error)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user