Remove feeds in folder

This commit is contained in:
Anh Do 2020-03-14 21:09:42 -04:00
parent e6659eea10
commit ec855364bc
No known key found for this signature in database
GPG Key ID: 451E3092F917B62D
3 changed files with 19 additions and 6 deletions

View File

@ -11,7 +11,7 @@ import Foundation
enum NewsBlurFolderChange {
case add(String)
case rename(String, String)
case delete(String)
case delete(String, [String])
}
extension NewsBlurFolderChange: NewsBlurDataConvertible {
@ -27,11 +27,15 @@ extension NewsBlurFolderChange: NewsBlurDataConvertible {
URLQueryItem(name: "new_folder_name", value: to),
URLQueryItem(name: "in_folder", value: ""), // root folder
]
case .delete(let name):
return [
case .delete(let name, let feedIDs):
var queryItems = [
URLQueryItem(name: "folder_to_delete", value: name),
URLQueryItem(name: "in_folder", value: ""), // root folder
]
queryItems.append(contentsOf: feedIDs.map { id in
URLQueryItem(name: "feed_id", value: id)
})
return queryItems
}
}()

View File

@ -205,8 +205,8 @@ final class NewsBlurAPICaller: NSObject {
sendUpdates(endpoint: "reader/rename_folder", payload: NewsBlurFolderChange.rename(folder, name), completion: completion)
}
func removeFolder(named name: String, completion: @escaping (Result<Void, Error>) -> Void) {
sendUpdates(endpoint: "reader/delete_folder", payload: NewsBlurFolderChange.delete(name), completion: completion)
func removeFolder(named name: String, feedIDs: [String], completion: @escaping (Result<Void, Error>) -> Void) {
sendUpdates(endpoint: "reader/delete_folder", payload: NewsBlurFolderChange.delete(name, feedIDs), completion: completion)
}
}

View File

@ -358,9 +358,18 @@ final class NewsBlurAccountDelegate: AccountDelegate {
return
}
var feedIDs: [String] = []
for feed in folder.topLevelWebFeeds {
if feed.folderRelationship?.count ?? 0 > 1 {
clearFolderRelationship(for: feed, withFolderName: folderToRemove)
} else if let subscriptionID = feed.subscriptionID {
feedIDs.append(subscriptionID)
}
}
refreshProgress.addToNumberOfTasksAndRemaining(1)
caller.removeFolder(named: folderToRemove) { result in
caller.removeFolder(named: folderToRemove, feedIDs: feedIDs) { result in
self.refreshProgress.completeTask()
switch result {