Convert markArticles to async await.

This commit is contained in:
Brent Simmons 2024-03-26 18:48:44 -07:00
parent bf58443fe1
commit 402ee970cc
11 changed files with 105 additions and 23 deletions

View File

@ -519,9 +519,17 @@ public enum FetchType {
func loadOPMLItems(_ items: [RSOPMLItem]) {
addOPMLItems(OPMLNormalizer.normalize(items))
}
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)
public func markArticles(_ articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) {
Task { @MainActor in
try? await self.markArticles(articles, statusKey: statusKey, flag: flag)
}
}
public func markArticles(_ articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) async throws {
try await delegate.markArticles(for: self, articles: articles, statusKey: statusKey, flag: flag)
}
func existingContainer(withExternalID externalID: String) -> Container? {

View File

@ -45,8 +45,7 @@ import Secrets
func restoreFeed(for account: Account, feed: Feed, 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, completion: @escaping (Result<Void, Error>) -> Void)
func markArticles(for account: Account, articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) async throws
// Called at the end of accounts init method.
func accountDidInitialize(_ account: Account)

View File

@ -444,7 +444,21 @@ enum CloudKitAccountDelegateError: LocalizedError {
}
}
func markArticles(for account: Account, articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool, completion: @escaping (Result<Void, Error>) -> Void) {
func markArticles(for account: Account, articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) async throws {
try await withCheckedThrowingContinuation { continuation in
self.markArticles(for: account, articles: articles, statusKey: statusKey, flag: flag) { result in
switch result {
case .success:
continuation.resume()
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}
private 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):

View File

@ -590,7 +590,21 @@ final class FeedbinAccountDelegate: AccountDelegate {
}
func markArticles(for account: Account, articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool, completion: @escaping (Result<Void, Error>) -> Void) {
func markArticles(for account: Account, articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) async throws {
try await withCheckedThrowingContinuation { continuation in
self.markArticles(for: account, articles: articles, statusKey: statusKey, flag: flag) { result in
switch result {
case .success:
continuation.resume()
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}
private 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):

View File

@ -552,7 +552,21 @@ final class FeedlyAccountDelegate: AccountDelegate {
}
}
func markArticles(for account: Account, articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool, completion: @escaping (Result<Void, Error>) -> Void) {
func markArticles(for account: Account, articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) async throws {
try await withCheckedThrowingContinuation { continuation in
self.markArticles(for: account, articles: articles, statusKey: statusKey, flag: flag) { result in
switch result {
case .success:
continuation.resume()
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}
private 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):

View File

@ -170,12 +170,16 @@ final class LocalAccountDelegate: AccountDelegate {
completion(.success(()))
}
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 markArticles(for account: Account, articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) async throws {
try await withCheckedThrowingContinuation { continuation in
account.update(articles, statusKey: statusKey, flag: flag) { result in
switch result {
case .success:
continuation.resume()
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}

View File

@ -631,7 +631,21 @@ final class NewsBlurAccountDelegate: AccountDelegate {
}
}
func markArticles(for account: Account, articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool, completion: @escaping (Result<Void, Error>) -> Void) {
func markArticles(for account: Account, articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) async throws {
try await withCheckedThrowingContinuation { continuation in
self.markArticles(for: account, articles: articles, statusKey: statusKey, flag: flag) { result in
switch result {
case .success:
continuation.resume()
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}
private 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):

View File

@ -656,7 +656,21 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
}
func markArticles(for account: Account, articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool, completion: @escaping (Result<Void, Error>) -> Void) {
func markArticles(for account: Account, articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) async throws {
try await withCheckedThrowingContinuation { continuation in
self.markArticles(for: account, articles: articles, statusKey: statusKey, flag: flag) { result in
switch result {
case .success:
continuation.resume()
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}
private 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):

View File

@ -1001,7 +1001,7 @@ private extension AppDelegate {
return
}
account.markArticles(articles, statusKey: .read, flag: true) { _ in }
try? await account.markArticles(articles, statusKey: .read, flag: true)
}
}
@ -1022,7 +1022,7 @@ private extension AppDelegate {
return
}
account.markArticles(articles, statusKey: .starred, flag: true) { _ in }
try? await account.markArticles(articles, statusKey: .starred, flag: true)
}
}
}

View File

@ -23,11 +23,12 @@ import Account
continue
}
group.enter()
account.markArticles(accountArticles, statusKey: statusKey, flag: flag) { _ in
Task { @MainActor in
try? await account.markArticles(accountArticles, statusKey: statusKey, flag: flag)
group.leave()
}
}
group.notify(queue: .main) {
completion?()
}

View File

@ -449,11 +449,11 @@ private extension AppDelegate {
return
}
account.markArticles(articles, statusKey: .read, flag: true) { _ in }
try? await account.markArticles(articles, statusKey: .read, flag: true)
self.prepareAccountsForBackground()
try? await account.syncArticleStatus
try? await account.syncArticleStatus()
if !self.accountManager.isSuspended {
try? WidgetDataEncoder.shared.encodeWidgetData()
self.prepareAccountsForBackground()
@ -486,7 +486,7 @@ private extension AppDelegate {
return
}
account.markArticles(articles, statusKey: .starred, flag: true) { _ in }
try? await account.markArticles(articles, statusKey: .starred, flag: true)
try? await account.syncArticleStatus()
if !self.accountManager.isSuspended {