Update set starred articles operation to honour database errors.

This commit is contained in:
Kiel Gillard 2019-12-18 09:45:30 +11:00
parent 5a9b138a9d
commit 40dacd6522
1 changed files with 33 additions and 6 deletions

View File

@ -52,14 +52,41 @@ private extension FeedlySetStarredArticlesOperation {
return return
} }
// Mark as starred
let remoteStarredArticleIDs = allStarredEntryIdsProvider.entryIds let remoteStarredArticleIDs = allStarredEntryIdsProvider.entryIds
account.mark(articleIDs: remoteStarredArticleIDs, statusKey: .starred, flag: true) guard !remoteStarredArticleIDs.isEmpty else {
didFinish()
return
}
let group = DispatchGroup()
final class StarredStatusResults {
var markAsStarredError: Error?
var markAsUnstarredError: Error?
}
let results = StarredStatusResults()
group.enter()
account.markAsStarred(remoteStarredArticleIDs) { error in
results.markAsStarredError = error
group.leave()
}
// Mark as unstarred
let deltaUnstarredArticleIDs = localStarredArticleIDs.subtracting(remoteStarredArticleIDs) let deltaUnstarredArticleIDs = localStarredArticleIDs.subtracting(remoteStarredArticleIDs)
account.mark(articleIDs: deltaUnstarredArticleIDs, statusKey: .starred, flag: false) group.enter()
account.markAsUnstarred(deltaUnstarredArticleIDs) { error in
results.markAsUnstarredError = error
group.leave()
}
didFinish() group.notify(queue: .main) {
let markingError = results.markAsStarredError ?? results.markAsUnstarredError
guard let error = markingError else {
self.didFinish()
return
}
self.didFinish(error)
}
} }
} }