Add completion callbacks so that we can ensure that unreads have been marked before determining the next unread. Fixes #2993

This commit is contained in:
Maurice Parker
2021-04-12 19:41:01 -05:00
parent 3a1b3f96bb
commit c95daa208f
14 changed files with 60 additions and 41 deletions

View File

@@ -529,7 +529,7 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
}
func markArticles(for account: Account, articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) {
func markArticles(for account: Account, articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool, completion: @escaping (Result<Void, Error>) -> Void) {
account.update(articles, statusKey: statusKey, flag: flag) { result in
switch result {
case .success(let articles):
@@ -540,12 +540,12 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
self.database.insertStatuses(syncStatuses) { _ in
self.database.selectPendingCount { result in
if let count = try? result.get(), count > 100 {
self.sendArticleStatus(for: account) { _ in }
self.sendArticleStatus(for: account, completion: completion)
}
}
}
case .failure(let error):
os_log(.error, log: self.log, "Error marking article status: %@", error.localizedDescription)
completion(.failure(error))
}
}
}