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