Fix add new feed to keep sidebar consistent.

This commit is contained in:
Maurice Parker 2020-04-17 08:58:06 -05:00
parent 95f1f64aa7
commit 8331d37dc1
1 changed files with 7 additions and 1 deletions

View File

@ -192,6 +192,7 @@ final class LocalAccountDelegate: AccountDelegate {
// Use the standard feed finder to download and process the RSS feed
refreshProgress.addToNumberOfTasksAndRemaining(1)
BatchUpdate.shared.start()
FeedFinder.find(url: url) { result in
switch result {
@ -199,34 +200,39 @@ final class LocalAccountDelegate: AccountDelegate {
guard let bestFeedSpecifier = FeedSpecifier.bestFeed(in: feedSpecifiers),
let url = URL(string: bestFeedSpecifier.urlString) else {
self.refreshProgress.completeTask()
BatchUpdate.shared.end()
completion(.failure(AccountError.createErrorNotFound))
return
}
if account.hasWebFeed(withURL: bestFeedSpecifier.urlString) {
self.refreshProgress.completeTask()
BatchUpdate.shared.end()
completion(.failure(AccountError.createErrorAlreadySubscribed))
return
}
let feed = account.createWebFeed(with: nil, url: url.absoluteString, webFeedID: url.absoluteString, homePageURL: nil)
feed.editedName = name
container.addWebFeed(feed)
InitialFeedDownloader.download(url) { parsedFeed in
self.refreshProgress.completeTask()
if let parsedFeed = parsedFeed {
account.update(feed, with: parsedFeed, {_ in
container.addWebFeed(feed)
BatchUpdate.shared.end()
completion(.success(feed))
})
} else {
BatchUpdate.shared.end()
completion(.failure(AccountError.createErrorNotFound))
}
}
case .failure:
BatchUpdate.shared.end()
self.refreshProgress.completeTask()
completion(.failure(AccountError.createErrorNotFound))
}