mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Continue adopting async/await.
This commit is contained in:
@@ -887,6 +887,21 @@ public enum FetchType {
|
||||
}
|
||||
}
|
||||
|
||||
/// Mark articleIDs statuses based on statusKey and flag.
|
||||
/// Will create statuses in the database and in memory as needed. Sends a .StatusesDidChange notification.
|
||||
func markArticleIDs(_ articleIDs: Set<String>, statusKey: ArticleStatus.Key, flag: Bool) async throws {
|
||||
guard !articleIDs.isEmpty else {
|
||||
return
|
||||
}
|
||||
|
||||
try await database.markArticleIDs(articleIDs, statusKey: statusKey, flag: flag)
|
||||
noteStatusesForArticleIDsDidChange(articleIDs: articleIDs, statusKey: statusKey, flag: flag)
|
||||
}
|
||||
|
||||
func markArticleIDsAsRead(_ articleIDs: Set<String>) async throws {
|
||||
try await markArticleIDs(articleIDs, statusKey: .read, flag: true)
|
||||
}
|
||||
|
||||
/// Mark articleIDs as read. Will create statuses in the database and in memory as needed. Sends a .StatusesDidChange notification.
|
||||
/// Returns a set of new article statuses.
|
||||
func markAsRead(_ articleIDs: Set<String>, completion: DatabaseCompletionBlock? = nil) {
|
||||
|
||||
@@ -1290,7 +1290,7 @@ private extension FeedbinAccountDelegate {
|
||||
|
||||
// Mark articles as read
|
||||
let deltaReadArticleIDs = currentUnreadArticleIDs.subtracting(updatableFeedbinUnreadArticleIDs)
|
||||
account.markAsRead(deltaReadArticleIDs)
|
||||
try await account.markArticleIDsAsRead(deltaReadArticleIDs)
|
||||
} catch let error {
|
||||
self.logger.error("Sync Articles Read Status failed: \(error.localizedDescription, privacy: .public)")
|
||||
}
|
||||
|
||||
@@ -338,7 +338,7 @@ extension NewsBlurAccountDelegate {
|
||||
|
||||
// Mark articles as read
|
||||
let deltaReadArticleIDs = currentUnreadArticleIDs.subtracting(updatableNewsBlurUnreadStoryHashes)
|
||||
account.markAsRead(deltaReadArticleIDs)
|
||||
try await account.markArticleIDsAsRead(deltaReadArticleIDs)
|
||||
} catch let error {
|
||||
self.logger.error("Sync story read status failed: \(error.localizedDescription, privacy: .public)")
|
||||
}
|
||||
|
||||
@@ -1099,7 +1099,7 @@ private extension ReaderAPIAccountDelegate {
|
||||
|
||||
// Mark articles as read
|
||||
let deltaReadArticleIDs = currentUnreadArticleIDs.subtracting(updatableReaderUnreadArticleIDs)
|
||||
account.markAsRead(deltaReadArticleIDs)
|
||||
try await account.markArticleIDsAsRead(deltaReadArticleIDs)
|
||||
} catch let error {
|
||||
self.logger.error("Sync Article Read Status failed: \(error.localizedDescription, privacy: .public)")
|
||||
}
|
||||
|
||||
@@ -257,6 +257,10 @@ public typealias ArticleStatusesResultBlock = (ArticleStatusesResult) -> Void
|
||||
return articlesTable.mark(articles, statusKey, flag, completion)
|
||||
}
|
||||
|
||||
public func markArticleIDs(_ articleIDs: Set<String>, statusKey: ArticleStatus.Key, flag: Bool) async throws {
|
||||
try await articlesTable.markArticleIDs(articleIDs, statusKey, flag)
|
||||
}
|
||||
|
||||
public func mark(articleIDs: Set<String>, statusKey: ArticleStatus.Key, flag: Bool, completion: DatabaseCompletionBlock?) {
|
||||
articlesTable.mark(articleIDs, statusKey, flag, completion)
|
||||
}
|
||||
|
||||
@@ -493,6 +493,23 @@ final class ArticlesTable: DatabaseTable {
|
||||
}
|
||||
}
|
||||
|
||||
func markArticleIDs(_ articleIDs: Set<String>, _ statusKey: ArticleStatus.Key, _ flag: Bool) async throws {
|
||||
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
Task { @MainActor in
|
||||
queue.runInTransaction { databaseResult in
|
||||
switch databaseResult {
|
||||
case .success(let database):
|
||||
self.statusesTable.mark(articleIDs, statusKey, flag, database)
|
||||
continuation.resume()
|
||||
case .failure(let databaseError):
|
||||
continuation.resume(throwing: databaseError)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func mark(_ articleIDs: Set<String>, _ statusKey: ArticleStatus.Key, _ flag: Bool, _ completion: DatabaseCompletionBlock?) {
|
||||
queue.runInTransaction { databaseResult in
|
||||
switch databaseResult {
|
||||
|
||||
Reference in New Issue
Block a user