Update set unraed articles operation to honour database errors.

This commit is contained in:
Kiel Gillard 2019-12-18 09:42:08 +11:00
parent 7ddcb2fc8e
commit 5a9b138a9d
1 changed files with 32 additions and 3 deletions

View File

@ -53,11 +53,40 @@ private extension FeedlySetUnreadArticlesOperation {
} }
let remoteUnreadArticleIDs = allUnreadIdsProvider.entryIds let remoteUnreadArticleIDs = allUnreadIdsProvider.entryIds
account.markAsUnread(remoteUnreadArticleIDs) guard !remoteUnreadArticleIDs.isEmpty else {
didFinish()
return
}
let group = DispatchGroup()
final class ReadStatusResults {
var markAsUnreadError: Error?
var markAsReadError: Error?
}
let results = ReadStatusResults()
group.enter()
account.markAsUnread(remoteUnreadArticleIDs) { error in
results.markAsUnreadError = error
group.leave()
}
let articleIDsToMarkRead = localUnreadArticleIDs.subtracting(remoteUnreadArticleIDs) let articleIDsToMarkRead = localUnreadArticleIDs.subtracting(remoteUnreadArticleIDs)
account.markAsRead(articleIDsToMarkRead) group.enter()
account.markAsRead(articleIDsToMarkRead) { error in
results.markAsReadError = error
group.leave()
}
didFinish() group.notify(queue: .main) {
let markingError = results.markAsReadError ?? results.markAsUnreadError
guard let error = markingError else {
self.didFinish()
return
}
self.didFinish(error)
}
} }
} }