Drop the completion block from unread-count-fetching.
This commit is contained in:
parent
0949aefa93
commit
d401378dca
@ -676,8 +676,9 @@ public enum FetchType {
|
|||||||
structureDidChange()
|
structureDidChange()
|
||||||
}
|
}
|
||||||
|
|
||||||
public func updateUnreadCounts(for feeds: Set<Feed>, completion: VoidCompletionBlock? = nil) {
|
public func updateUnreadCounts(for feeds: Set<Feed>) {
|
||||||
fetchUnreadCounts(for: feeds, completion: completion)
|
|
||||||
|
fetchUnreadCounts(for: feeds)
|
||||||
}
|
}
|
||||||
|
|
||||||
@MainActor public func articles(for fetchType: FetchType) async throws -> Set<Article> {
|
@MainActor public func articles(for fetchType: FetchType) async throws -> Set<Article> {
|
||||||
@ -1111,13 +1112,13 @@ public enum FetchType {
|
|||||||
|
|
||||||
// MARK: - Hashable
|
// MARK: - Hashable
|
||||||
|
|
||||||
public func hash(into hasher: inout Hasher) {
|
nonisolated public func hash(into hasher: inout Hasher) {
|
||||||
hasher.combine(accountID)
|
hasher.combine(accountID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Equatable
|
// MARK: - Equatable
|
||||||
|
|
||||||
public class func ==(lhs: Account, rhs: Account) -> Bool {
|
nonisolated public class func ==(lhs: Account, rhs: Account) -> Bool {
|
||||||
return lhs === rhs
|
return lhs === rhs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1416,66 +1417,66 @@ private extension Account {
|
|||||||
/// Fetch unread counts for zero or more feeds.
|
/// Fetch unread counts for zero or more feeds.
|
||||||
///
|
///
|
||||||
/// Uses the most efficient method based on how many feeds were passed in.
|
/// Uses the most efficient method based on how many feeds were passed in.
|
||||||
func fetchUnreadCounts(for feeds: Set<Feed>, completion: VoidCompletionBlock?) {
|
func fetchUnreadCounts(for feeds: Set<Feed>) {
|
||||||
if feeds.isEmpty {
|
|
||||||
completion?()
|
guard !feeds.isEmpty else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if feeds.count == 1, let feed = feeds.first {
|
if feeds.count == 1, let feed = feeds.first {
|
||||||
fetchUnreadCount(feed, completion)
|
fetchUnreadCount(feed)
|
||||||
}
|
}
|
||||||
else if feeds.count < 10 {
|
else if feeds.count < 10 {
|
||||||
fetchUnreadCounts(feeds, completion)
|
fetchUnreadCounts(feeds)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fetchAllUnreadCounts(completion)
|
fetchAllUnreadCounts()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchUnreadCount(_ feed: Feed, _ completion: VoidCompletionBlock?) {
|
func fetchUnreadCount(_ feed: Feed) {
|
||||||
database.fetchUnreadCount(feed.feedID) { result in
|
|
||||||
Task { @MainActor in
|
Task { @MainActor in
|
||||||
if let unreadCount = try? result.get() {
|
if let unreadCount = try? await database.unreadCount(feedID: feed.feedID) {
|
||||||
feed.unreadCount = unreadCount
|
feed.unreadCount = unreadCount
|
||||||
}
|
}
|
||||||
completion?()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchUnreadCounts(_ feeds: Set<Feed>, _ completion: VoidCompletionBlock?) {
|
func fetchUnreadCounts(_ feeds: Set<Feed>) {
|
||||||
|
|
||||||
|
Task { @MainActor in
|
||||||
|
|
||||||
let feedIDs = Set(feeds.map { $0.feedID })
|
let feedIDs = Set(feeds.map { $0.feedID })
|
||||||
database.fetchUnreadCounts(for: feedIDs) { result in
|
guard let unreadCountDictionary = try? await database.unreadCounts(feedIDs: feedIDs) else {
|
||||||
|
|
||||||
Task { @MainActor in
|
|
||||||
if let unreadCountDictionary = try? result.get() {
|
|
||||||
self.processUnreadCounts(unreadCountDictionary: unreadCountDictionary, feeds: feeds)
|
|
||||||
}
|
|
||||||
completion?()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func fetchAllUnreadCounts(_ completion: VoidCompletionBlock? = nil) {
|
|
||||||
fetchingAllUnreadCounts = true
|
|
||||||
database.fetchAllUnreadCounts { result in
|
|
||||||
|
|
||||||
Task { @MainActor in
|
|
||||||
guard let unreadCountDictionary = try? result.get() else {
|
|
||||||
completion?()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
self.processUnreadCounts(unreadCountDictionary: unreadCountDictionary, feeds: self.flattenedFeeds())
|
|
||||||
|
|
||||||
|
self.processUnreadCounts(unreadCountDictionary: unreadCountDictionary, feeds: feeds)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func fetchAllUnreadCounts() {
|
||||||
|
|
||||||
|
guard !fetchingAllUnreadCounts else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fetchingAllUnreadCounts = true
|
||||||
|
|
||||||
|
Task { @MainActor in
|
||||||
|
|
||||||
|
let unreadCountDictionary = try? await database.allUnreadCounts()
|
||||||
self.fetchingAllUnreadCounts = false
|
self.fetchingAllUnreadCounts = false
|
||||||
|
|
||||||
|
if let unreadCountDictionary {
|
||||||
|
self.processUnreadCounts(unreadCountDictionary: unreadCountDictionary, feeds: self.flattenedFeeds())
|
||||||
|
}
|
||||||
self.updateUnreadCount()
|
self.updateUnreadCount()
|
||||||
|
|
||||||
if !self.isUnreadCountsInitialized {
|
if !self.isUnreadCountsInitialized {
|
||||||
self.isUnreadCountsInitialized = true
|
self.isUnreadCountsInitialized = true
|
||||||
self.postUnreadCountDidInitializeNotification()
|
self.postUnreadCountDidInitializeNotification()
|
||||||
}
|
}
|
||||||
completion?()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user