2019-07-06 05:06:31 +02:00
|
|
|
//
|
|
|
|
// SmartFeedDelegate.swift
|
|
|
|
// NetNewsWire
|
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 6/25/19.
|
|
|
|
// Copyright © 2019 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import Account
|
|
|
|
import Articles
|
2019-12-17 07:45:59 +01:00
|
|
|
import ArticlesDatabase
|
2019-07-06 05:06:31 +02:00
|
|
|
import RSCore
|
|
|
|
|
2019-11-15 13:19:14 +01:00
|
|
|
protocol SmartFeedDelegate: FeedIdentifiable, DisplayNameProvider, ArticleFetcher, SmallIconProvider {
|
2019-07-06 05:06:31 +02:00
|
|
|
var fetchType: FetchType { get }
|
2019-12-17 07:45:59 +01:00
|
|
|
func fetchUnreadCount(for: Account, completion: @escaping SingleUnreadCountCompletionBlock)
|
2019-07-06 05:06:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
extension SmartFeedDelegate {
|
|
|
|
|
2019-12-17 07:45:59 +01:00
|
|
|
func fetchArticles() throws -> Set<Article> {
|
|
|
|
return try AccountManager.shared.fetchArticles(fetchType)
|
2019-07-06 05:06:31 +02:00
|
|
|
}
|
|
|
|
|
2019-12-17 07:45:59 +01:00
|
|
|
func fetchArticlesAsync(_ completion: @escaping ArticleSetResultBlock) {
|
2019-12-15 02:01:34 +01:00
|
|
|
AccountManager.shared.fetchArticlesAsync(fetchType, completion)
|
2019-07-06 05:06:31 +02:00
|
|
|
}
|
|
|
|
|
2019-12-17 07:45:59 +01:00
|
|
|
func fetchUnreadArticles() throws -> Set<Article> {
|
|
|
|
return try fetchArticles().unreadArticles()
|
2019-07-06 05:06:31 +02:00
|
|
|
}
|
|
|
|
|
2019-12-17 07:45:59 +01:00
|
|
|
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))
|
|
|
|
}
|
|
|
|
}
|
2019-07-06 05:06:31 +02:00
|
|
|
}
|
|
|
|
}
|