mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Convert fetchUnreadArticleIDs to async await.
This commit is contained in:
@@ -749,8 +749,9 @@ public enum FetchType {
|
||||
try await database.starredAndUnreadCount(feedIDs: allFeedIDs()) ?? 0
|
||||
}
|
||||
|
||||
public func fetchUnreadArticleIDs(_ completion: @escaping ArticleIDsCompletionBlock) {
|
||||
database.fetchUnreadArticleIDsAsync(completion: completion)
|
||||
public func fetchUnreadArticleIDs() async throws -> Set<String>? {
|
||||
|
||||
try await database.unreadArticleIDs()
|
||||
}
|
||||
|
||||
public func fetchStarredArticleIDs(_ completion: @escaping ArticleIDsCompletionBlock) {
|
||||
|
||||
@@ -1505,41 +1505,33 @@ private extension FeedbinAccountDelegate {
|
||||
|
||||
let pendingArticleIDs = (try await self.database.selectPendingReadStatusArticleIDs()) ?? Set<String>()
|
||||
|
||||
@MainActor func process(_ pendingArticleIDs: Set<String>) {
|
||||
let feedbinUnreadArticleIDs = Set(articleIDs.map { String($0) } )
|
||||
let updatableFeedbinUnreadArticleIDs = feedbinUnreadArticleIDs.subtracting(pendingArticleIDs)
|
||||
|
||||
let feedbinUnreadArticleIDs = Set(articleIDs.map { String($0) } )
|
||||
let updatableFeedbinUnreadArticleIDs = feedbinUnreadArticleIDs.subtracting(pendingArticleIDs)
|
||||
|
||||
account.fetchUnreadArticleIDs { articleIDsResult in
|
||||
MainActor.assumeIsolated {
|
||||
guard let currentUnreadArticleIDs = try? articleIDsResult.get() else {
|
||||
return
|
||||
}
|
||||
|
||||
let group = DispatchGroup()
|
||||
|
||||
// Mark articles as unread
|
||||
let deltaUnreadArticleIDs = updatableFeedbinUnreadArticleIDs.subtracting(currentUnreadArticleIDs)
|
||||
group.enter()
|
||||
account.markAsUnread(deltaUnreadArticleIDs) { _ in
|
||||
group.leave()
|
||||
}
|
||||
|
||||
// Mark articles as read
|
||||
let deltaReadArticleIDs = currentUnreadArticleIDs.subtracting(updatableFeedbinUnreadArticleIDs)
|
||||
group.enter()
|
||||
account.markAsRead(deltaReadArticleIDs) { _ in
|
||||
group.leave()
|
||||
}
|
||||
|
||||
group.notify(queue: DispatchQueue.main) {
|
||||
completion()
|
||||
}
|
||||
}
|
||||
}
|
||||
guard let currentUnreadArticleIDs = try await account.fetchUnreadArticleIDs() else {
|
||||
completion()
|
||||
return
|
||||
}
|
||||
|
||||
process(pendingArticleIDs)
|
||||
let group = DispatchGroup()
|
||||
|
||||
// Mark articles as unread
|
||||
let deltaUnreadArticleIDs = updatableFeedbinUnreadArticleIDs.subtracting(currentUnreadArticleIDs)
|
||||
group.enter()
|
||||
account.markAsUnread(deltaUnreadArticleIDs) { _ in
|
||||
group.leave()
|
||||
}
|
||||
|
||||
// Mark articles as read
|
||||
let deltaReadArticleIDs = currentUnreadArticleIDs.subtracting(updatableFeedbinUnreadArticleIDs)
|
||||
group.enter()
|
||||
account.markAsRead(deltaReadArticleIDs) { _ in
|
||||
group.leave()
|
||||
}
|
||||
|
||||
group.notify(queue: DispatchQueue.main) {
|
||||
completion()
|
||||
}
|
||||
|
||||
} catch {
|
||||
os_log(.error, log: self.log, "Sync Article Read Status failed: %@.", error.localizedDescription)
|
||||
|
||||
@@ -96,20 +96,19 @@ final class FeedlyIngestUnreadArticleIdsOperation: FeedlyOperation {
|
||||
didFinish()
|
||||
return
|
||||
}
|
||||
|
||||
account.fetchUnreadArticleIDs { result in
|
||||
MainActor.assumeIsolated {
|
||||
switch result {
|
||||
case .success(let localUnreadArticleIDs):
|
||||
self.processUnreadArticleIDs(localUnreadArticleIDs)
|
||||
|
||||
case .failure(let error):
|
||||
self.didFinish(with: error)
|
||||
Task { @MainActor in
|
||||
|
||||
do {
|
||||
if let localUnreadArticleIDs = try await account.fetchUnreadArticleIDs() {
|
||||
self.processUnreadArticleIDs(localUnreadArticleIDs)
|
||||
}
|
||||
} catch {
|
||||
self.didFinish(with: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func processUnreadArticleIDs(_ localUnreadArticleIDs: Set<String>) {
|
||||
guard !isCanceled else {
|
||||
didFinish()
|
||||
|
||||
@@ -325,7 +325,7 @@ extension NewsBlurAccountDelegate {
|
||||
|
||||
func syncStoryReadState(account: Account, hashes: [NewsBlurStoryHash]?, completion: @escaping (() -> Void)) {
|
||||
|
||||
guard let hashes = hashes else {
|
||||
guard let hashes else {
|
||||
completion()
|
||||
return
|
||||
}
|
||||
@@ -334,41 +334,33 @@ extension NewsBlurAccountDelegate {
|
||||
do {
|
||||
let pendingArticleIDs = (try await self.database.selectPendingReadStatusArticleIDs()) ?? Set<String>()
|
||||
|
||||
@MainActor func process(_ pendingStoryHashes: Set<String>) {
|
||||
let newsBlurUnreadStoryHashes = Set(hashes.map { $0.hash } )
|
||||
let updatableNewsBlurUnreadStoryHashes = newsBlurUnreadStoryHashes.subtracting(pendingArticleIDs)
|
||||
|
||||
let newsBlurUnreadStoryHashes = Set(hashes.map { $0.hash } )
|
||||
let updatableNewsBlurUnreadStoryHashes = newsBlurUnreadStoryHashes.subtracting(pendingStoryHashes)
|
||||
|
||||
account.fetchUnreadArticleIDs { articleIDsResult in
|
||||
MainActor.assumeIsolated {
|
||||
guard let currentUnreadArticleIDs = try? articleIDsResult.get() else {
|
||||
return
|
||||
}
|
||||
|
||||
let group = DispatchGroup()
|
||||
|
||||
// Mark articles as unread
|
||||
let deltaUnreadArticleIDs = updatableNewsBlurUnreadStoryHashes.subtracting(currentUnreadArticleIDs)
|
||||
group.enter()
|
||||
account.markAsUnread(deltaUnreadArticleIDs) { _ in
|
||||
group.leave()
|
||||
}
|
||||
|
||||
// Mark articles as read
|
||||
let deltaReadArticleIDs = currentUnreadArticleIDs.subtracting(updatableNewsBlurUnreadStoryHashes)
|
||||
group.enter()
|
||||
account.markAsRead(deltaReadArticleIDs) { _ in
|
||||
group.leave()
|
||||
}
|
||||
|
||||
group.notify(queue: DispatchQueue.main) {
|
||||
completion()
|
||||
}
|
||||
}
|
||||
}
|
||||
guard let currentUnreadArticleIDs = try await account.fetchUnreadArticleIDs() else {
|
||||
completion()
|
||||
return
|
||||
}
|
||||
|
||||
process(pendingArticleIDs)
|
||||
let group = DispatchGroup()
|
||||
|
||||
// Mark articles as unread
|
||||
let deltaUnreadArticleIDs = updatableNewsBlurUnreadStoryHashes.subtracting(currentUnreadArticleIDs)
|
||||
group.enter()
|
||||
account.markAsUnread(deltaUnreadArticleIDs) { _ in
|
||||
group.leave()
|
||||
}
|
||||
|
||||
// Mark articles as read
|
||||
let deltaReadArticleIDs = currentUnreadArticleIDs.subtracting(updatableNewsBlurUnreadStoryHashes)
|
||||
group.enter()
|
||||
account.markAsRead(deltaReadArticleIDs) { _ in
|
||||
group.leave()
|
||||
}
|
||||
|
||||
group.notify(queue: DispatchQueue.main) {
|
||||
completion()
|
||||
}
|
||||
} catch {
|
||||
os_log(.error, log: self.log, "Sync Story Read Status failed: %@.", error.localizedDescription)
|
||||
}
|
||||
|
||||
@@ -1302,53 +1302,44 @@ private extension ReaderAPIAccountDelegate {
|
||||
completion()
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Task { @MainActor in
|
||||
do {
|
||||
|
||||
|
||||
let pendingArticleIDs = (try await self.database.selectPendingReadStatusArticleIDs()) ?? Set<String>()
|
||||
|
||||
@MainActor func process(_ pendingArticleIDs: Set<String>) {
|
||||
let updatableReaderUnreadArticleIDs = Set(articleIDs).subtracting(pendingArticleIDs)
|
||||
|
||||
account.fetchUnreadArticleIDs { articleIDsResult in
|
||||
|
||||
MainActor.assumeIsolated {
|
||||
guard let currentUnreadArticleIDs = try? articleIDsResult.get() else {
|
||||
return
|
||||
}
|
||||
|
||||
let group = DispatchGroup()
|
||||
|
||||
// Mark articles as unread
|
||||
let deltaUnreadArticleIDs = updatableReaderUnreadArticleIDs.subtracting(currentUnreadArticleIDs)
|
||||
group.enter()
|
||||
account.markAsUnread(deltaUnreadArticleIDs) { _ in
|
||||
group.leave()
|
||||
}
|
||||
|
||||
// Mark articles as read
|
||||
let deltaReadArticleIDs = currentUnreadArticleIDs.subtracting(updatableReaderUnreadArticleIDs)
|
||||
group.enter()
|
||||
account.markAsRead(deltaReadArticleIDs) { _ in
|
||||
group.leave()
|
||||
}
|
||||
|
||||
group.notify(queue: DispatchQueue.main) {
|
||||
completion()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let updatableReaderUnreadArticleIDs = Set(articleIDs).subtracting(pendingArticleIDs)
|
||||
|
||||
guard let currentUnreadArticleIDs = try await account.fetchUnreadArticleIDs() else {
|
||||
completion()
|
||||
return
|
||||
}
|
||||
|
||||
let group = DispatchGroup()
|
||||
|
||||
// Mark articles as unread
|
||||
let deltaUnreadArticleIDs = updatableReaderUnreadArticleIDs.subtracting(currentUnreadArticleIDs)
|
||||
group.enter()
|
||||
account.markAsUnread(deltaUnreadArticleIDs) { _ in
|
||||
group.leave()
|
||||
}
|
||||
|
||||
// Mark articles as read
|
||||
let deltaReadArticleIDs = currentUnreadArticleIDs.subtracting(updatableReaderUnreadArticleIDs)
|
||||
group.enter()
|
||||
account.markAsRead(deltaReadArticleIDs) { _ in
|
||||
group.leave()
|
||||
}
|
||||
|
||||
group.notify(queue: DispatchQueue.main) {
|
||||
completion()
|
||||
}
|
||||
|
||||
process(pendingArticleIDs)
|
||||
|
||||
} catch {
|
||||
os_log(.error, log: self.log, "Sync Article Read Status failed: %@.", error.localizedDescription)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func syncArticleStarredState(account: Account, articleIDs: [String]?, completion: @escaping (() -> Void)) {
|
||||
guard let articleIDs = articleIDs else {
|
||||
completion()
|
||||
|
||||
Reference in New Issue
Block a user