NetNewsWire/Shared/SmartFeeds/SmartFeedDelegate.swift
2024-03-24 18:49:39 -07:00

52 lines
1.3 KiB
Swift

//
// SmartFeedDelegate.swift
// NetNewsWire
//
// Created by Brent Simmons on 6/25/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import Foundation
import Account
import Articles
import ArticlesDatabase
import Database
import Core
protocol SmartFeedDelegate: SidebarItemIdentifiable, DisplayNameProvider, ArticleFetcher, SmallIconProvider {
var fetchType: FetchType { get }
func unreadCount(account: Account) async -> Int
// func fetchUnreadCount(for: Account, completion: @escaping SingleUnreadCountCompletionBlock)
}
extension SmartFeedDelegate {
@MainActor func fetchArticles() async throws -> Set<Article> {
try await AccountManager.shared.fetchArticles(fetchType: fetchType)
}
@MainActor func fetchArticlesAsync(_ completion: @escaping ArticleSetResultBlock) {
AccountManager.shared.fetchArticlesAsync(fetchType, completion)
}
@MainActor func fetchUnreadArticles() async throws -> Set<Article> {
try await AccountManager.shared.fetchArticles(fetchType: fetchType)
}
@MainActor func fetchUnreadArticlesAsync(_ completion: @escaping ArticleSetResultBlock) {
fetchArticlesAsync{ articleSetResult in
switch articleSetResult {
case .success(let articles):
completion(.success(articles.unreadArticles()))
case .failure(let error):
completion(.failure(error))
}
}
}
}