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

@@ -536,8 +536,8 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
addOPMLItems(OPMLNormalizer.normalize(items))
}
public func markArticles(_ articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) {
delegate.markArticles(for: self, articles: articles, statusKey: statusKey, flag: flag)
public func markArticles(_ articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool, completion: @escaping (Result<Void, Error>) -> Void) {
delegate.markArticles(for: self, articles: articles, statusKey: statusKey, flag: flag, completion: completion)
}
func existingContainer(withExternalID externalID: String) -> Container? {

View File

@@ -44,7 +44,7 @@ protocol AccountDelegate {
func restoreWebFeed(for account: Account, feed: WebFeed, container: Container, completion: @escaping (Result<Void, Error>) -> Void)
func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> Void)
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)
// Called at the end of accounts init method.
func accountDidInitialize(_ account: Account)

View File

@@ -387,7 +387,7 @@ final class CloudKitAccountDelegate: 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):
@@ -398,12 +398,12 @@ final class CloudKitAccountDelegate: AccountDelegate {
self.database.insertStatuses(syncStatuses) { _ in
self.database.selectPendingCount { result in
if let count = try? result.get(), count > 100 {
self.sendArticleStatus(for: account, showProgress: false) { _ in }
self.sendArticleStatus(for: account, showProgress: false, completion: completion)
}
}
}
case .failure(let error):
os_log(.error, log: self.log, "Error marking article status: %@", error.localizedDescription)
completion(.failure(error))
}
}
}

View File

@@ -454,7 +454,7 @@ final class FeedWranglerAccountDelegate: AccountDelegate {
fatalError()
}
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):
@@ -465,12 +465,12 @@ final class FeedWranglerAccountDelegate: 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))
}
}
}

View File

@@ -536,7 +536,7 @@ final class FeedbinAccountDelegate: 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):
@@ -547,12 +547,12 @@ final class FeedbinAccountDelegate: 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))
}
}
}

View File

@@ -487,7 +487,7 @@ final class FeedlyAccountDelegate: 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):
@@ -498,12 +498,12 @@ final class FeedlyAccountDelegate: 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))
}
}
}

View File

@@ -209,8 +209,14 @@ final class LocalAccountDelegate: AccountDelegate {
completion(.success(()))
}
func markArticles(for account: Account, articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) {
account.update(articles, statusKey: statusKey, flag: flag) { _ in }
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
if case .failure(let error) = result {
completion(.failure(error))
} else {
completion(.success(()))
}
}
}
func accountDidInitialize(_ account: Account) {

View File

@@ -564,7 +564,7 @@ final class NewsBlurAccountDelegate: 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):
@@ -575,12 +575,12 @@ final class NewsBlurAccountDelegate: 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))
}
}
}

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))
}
}
}