Move feed

This commit is contained in:
Anh Do 2020-03-21 22:17:01 -04:00
parent fe7cbe3bd3
commit 1e66860f34
No known key found for this signature in database
GPG Key ID: 451E3092F917B62D
3 changed files with 45 additions and 2 deletions

View File

@ -12,6 +12,7 @@ enum NewsBlurFeedChange {
case add(String, String?)
case rename(String, String)
case delete(String, String?)
case move(String, String?, String?)
}
extension NewsBlurFeedChange: NewsBlurDataConvertible {
@ -34,6 +35,12 @@ extension NewsBlurFeedChange: NewsBlurDataConvertible {
URLQueryItem(name: "feed_id", value: feedID),
folder != nil ? URLQueryItem(name: "in_folder", value: folder) : nil,
].compactMap { $0 }
case .move(let feedID, let from, let to):
return [
URLQueryItem(name: "feed_id", value: feedID),
URLQueryItem(name: "in_folder", value: from ?? ""),
URLQueryItem(name: "to_folder", value: to ?? ""),
]
}
}()

View File

@ -262,4 +262,18 @@ final class NewsBlurAPICaller: NSObject {
}
}
}
func moveFeed(feedID: String, from: String?, to: String?, completion: @escaping (Result<Void, Error>) -> Void) {
sendUpdates(
endpoint: "reader/move_feed_to_folder",
payload: NewsBlurFeedChange.move(feedID, from, to)
) { result in
switch result {
case .success:
completion(.success(()))
case .failure(let error):
completion(.failure(error))
}
}
}
}

View File

@ -429,7 +429,6 @@ final class NewsBlurAccountDelegate: AccountDelegate {
}
func renameWebFeed(for account: Account, with feed: WebFeed, to name: String, completion: @escaping (Result<Void, Error>) -> ()) {
// This error should never happen
guard let feedID = feed.externalID else {
completion(.failure(NewsBlurError.invalidParameter))
return
@ -480,7 +479,30 @@ final class NewsBlurAccountDelegate: AccountDelegate {
}
func moveWebFeed(for account: Account, with feed: WebFeed, from: Container, to: Container, completion: @escaping (Result<Void, Error>) -> ()) {
completion(.success(()))
guard let feedID = feed.externalID else {
completion(.failure(NewsBlurError.invalidParameter))
return
}
refreshProgress.addToNumberOfTasksAndRemaining(1)
caller.moveFeed(
feedID: feedID,
from: (from as? Folder)?.name,
to: (to as? Folder)?.name
) { result in
self.refreshProgress.completeTask()
switch result {
case .success:
from.removeWebFeed(feed)
to.addWebFeed(feed)
completion(.success(()))
case .failure(let error):
completion(.failure(error))
}
}
}
func restoreWebFeed(for account: Account, feed: WebFeed, container: Container, completion: @escaping (Result<Void, Error>) -> ()) {