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

@@ -13,15 +13,24 @@ import Account
// These handle multiple accounts.
func markArticles(_ articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) {
func markArticles(_ articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool, completion: (() -> Void)? = nil) {
let d: [String: Set<Article>] = accountAndArticlesDictionary(articles)
let group = DispatchGroup()
for (accountID, accountArticles) in d {
guard let account = AccountManager.shared.existingAccount(with: accountID) else {
continue
}
account.markArticles(accountArticles, statusKey: statusKey, flag: flag)
group.enter()
account.markArticles(accountArticles, statusKey: statusKey, flag: flag) { _ in
group.leave()
}
}
group.notify(queue: .main) {
completion?()
}
}