2018-02-04 19:57:41 +01:00
|
|
|
//
|
|
|
|
// ArticleFetcher.swift
|
2019-07-09 07:58:19 +02:00
|
|
|
// NetNewsWire
|
2018-02-04 19:57:41 +01:00
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 2/4/18.
|
|
|
|
// Copyright © 2018 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
2018-07-24 03:29:08 +02:00
|
|
|
import Articles
|
2018-02-04 19:57:41 +01:00
|
|
|
|
|
|
|
public protocol ArticleFetcher {
|
|
|
|
|
|
|
|
func fetchArticles() -> Set<Article>
|
2019-07-06 05:06:31 +02:00
|
|
|
func fetchArticlesAsync(_ callback: @escaping ArticleSetBlock)
|
2018-02-04 19:57:41 +01:00
|
|
|
func fetchUnreadArticles() -> Set<Article>
|
2019-07-06 05:06:31 +02:00
|
|
|
func fetchUnreadArticlesAsync(_ callback: @escaping ArticleSetBlock)
|
2018-02-04 19:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
extension Feed: ArticleFetcher {
|
|
|
|
|
|
|
|
public func fetchArticles() -> Set<Article> {
|
2019-07-06 05:06:31 +02:00
|
|
|
return account?.fetchArticles(.feed(self)) ?? Set<Article>()
|
|
|
|
}
|
2018-02-04 19:57:41 +01:00
|
|
|
|
2019-07-06 05:06:31 +02:00
|
|
|
public func fetchArticlesAsync(_ callback: @escaping ArticleSetBlock) {
|
2018-02-04 19:57:41 +01:00
|
|
|
guard let account = account else {
|
|
|
|
assertionFailure("Expected feed.account, but got nil.")
|
2019-07-06 05:06:31 +02:00
|
|
|
callback(Set<Article>())
|
|
|
|
return
|
2018-02-04 19:57:41 +01:00
|
|
|
}
|
2019-07-06 05:06:31 +02:00
|
|
|
account.fetchArticlesAsync(.feed(self), callback)
|
2018-02-04 19:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public func fetchUnreadArticles() -> Set<Article> {
|
2019-08-12 18:43:29 +02:00
|
|
|
return fetchArticles().unreadArticles()
|
2019-07-06 05:06:31 +02:00
|
|
|
}
|
2018-02-04 19:57:41 +01:00
|
|
|
|
2019-07-06 05:06:31 +02:00
|
|
|
public func fetchUnreadArticlesAsync(_ callback: @escaping ArticleSetBlock) {
|
2019-08-12 18:43:29 +02:00
|
|
|
guard let account = account else {
|
|
|
|
assertionFailure("Expected feed.account, but got nil.")
|
|
|
|
callback(Set<Article>())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
account.fetchArticlesAsync(.feed(self)) { callback($0.unreadArticles()) }
|
2018-02-04 19:57:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Folder: ArticleFetcher {
|
|
|
|
|
|
|
|
public func fetchArticles() -> Set<Article> {
|
|
|
|
return fetchUnreadArticles()
|
|
|
|
}
|
|
|
|
|
2019-07-06 05:06:31 +02:00
|
|
|
public func fetchArticlesAsync(_ callback: @escaping ArticleSetBlock) {
|
|
|
|
fetchUnreadArticlesAsync(callback)
|
|
|
|
}
|
2018-02-04 19:57:41 +01:00
|
|
|
|
2019-07-06 05:06:31 +02:00
|
|
|
public func fetchUnreadArticles() -> Set<Article> {
|
2018-02-04 19:57:41 +01:00
|
|
|
guard let account = account else {
|
|
|
|
assertionFailure("Expected folder.account, but got nil.")
|
|
|
|
return Set<Article>()
|
|
|
|
}
|
2019-07-06 05:06:31 +02:00
|
|
|
return account.fetchArticles(.unreadForFolder(self))
|
|
|
|
}
|
2018-02-04 19:57:41 +01:00
|
|
|
|
2019-07-06 05:06:31 +02:00
|
|
|
public func fetchUnreadArticlesAsync(_ callback: @escaping ArticleSetBlock) {
|
|
|
|
guard let account = account else {
|
|
|
|
assertionFailure("Expected folder.account, but got nil.")
|
|
|
|
callback(Set<Article>())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
account.fetchArticlesAsync(.unreadForFolder(self), callback)
|
2018-02-04 19:57:41 +01:00
|
|
|
}
|
|
|
|
}
|