2018-02-04 10:57:41 -08:00
|
|
|
//
|
|
|
|
// ArticleFetcher.swift
|
2019-07-08 22:58:19 -07:00
|
|
|
// NetNewsWire
|
2018-02-04 10:57:41 -08:00
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 2/4/18.
|
|
|
|
// Copyright © 2018 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
2018-07-23 18:29:08 -07:00
|
|
|
import Articles
|
2018-02-04 10:57:41 -08:00
|
|
|
|
|
|
|
public protocol ArticleFetcher {
|
|
|
|
|
|
|
|
func fetchArticles() -> Set<Article>
|
2019-12-14 18:01:34 -07:00
|
|
|
func fetchArticlesAsync(_ completion: @escaping ArticleSetBlock)
|
2018-02-04 10:57:41 -08:00
|
|
|
func fetchUnreadArticles() -> Set<Article>
|
2019-12-14 18:01:34 -07:00
|
|
|
func fetchUnreadArticlesAsync(_ completion: @escaping ArticleSetBlock)
|
2018-02-04 10:57:41 -08:00
|
|
|
}
|
|
|
|
|
2019-11-14 20:11:41 -06:00
|
|
|
extension WebFeed: ArticleFetcher {
|
2019-11-14 15:06:32 -06:00
|
|
|
|
2018-02-04 10:57:41 -08:00
|
|
|
public func fetchArticles() -> Set<Article> {
|
2019-11-14 20:11:41 -06:00
|
|
|
return account?.fetchArticles(.webFeed(self)) ?? Set<Article>()
|
2019-07-05 20:06:31 -07:00
|
|
|
}
|
2018-02-04 10:57:41 -08:00
|
|
|
|
2019-12-14 18:01:34 -07:00
|
|
|
public func fetchArticlesAsync(_ completion: @escaping ArticleSetBlock) {
|
2018-02-04 10:57:41 -08:00
|
|
|
guard let account = account else {
|
|
|
|
assertionFailure("Expected feed.account, but got nil.")
|
2019-12-14 18:01:34 -07:00
|
|
|
completion(Set<Article>())
|
2019-07-05 20:06:31 -07:00
|
|
|
return
|
2018-02-04 10:57:41 -08:00
|
|
|
}
|
2019-12-14 18:01:34 -07:00
|
|
|
account.fetchArticlesAsync(.webFeed(self), completion)
|
2018-02-04 10:57:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public func fetchUnreadArticles() -> Set<Article> {
|
2019-08-12 09:43:29 -07:00
|
|
|
return fetchArticles().unreadArticles()
|
2019-07-05 20:06:31 -07:00
|
|
|
}
|
2018-02-04 10:57:41 -08:00
|
|
|
|
2019-12-14 18:01:34 -07:00
|
|
|
public func fetchUnreadArticlesAsync(_ completion: @escaping ArticleSetBlock) {
|
2019-08-12 09:43:29 -07:00
|
|
|
guard let account = account else {
|
|
|
|
assertionFailure("Expected feed.account, but got nil.")
|
2019-12-14 18:01:34 -07:00
|
|
|
completion(Set<Article>())
|
2019-08-12 09:43:29 -07:00
|
|
|
return
|
|
|
|
}
|
2019-12-14 18:01:34 -07:00
|
|
|
account.fetchArticlesAsync(.webFeed(self)) { completion($0.unreadArticles()) }
|
2018-02-04 10:57:41 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Folder: ArticleFetcher {
|
2019-11-14 15:06:32 -06:00
|
|
|
|
2018-02-04 10:57:41 -08:00
|
|
|
public func fetchArticles() -> Set<Article> {
|
2019-11-22 10:21:30 -06:00
|
|
|
guard let account = account else {
|
|
|
|
assertionFailure("Expected folder.account, but got nil.")
|
|
|
|
return Set<Article>()
|
|
|
|
}
|
|
|
|
return account.fetchArticles(.folder(self, false))
|
2018-02-04 10:57:41 -08:00
|
|
|
}
|
|
|
|
|
2019-12-14 18:01:34 -07:00
|
|
|
public func fetchArticlesAsync(_ completion: @escaping ArticleSetBlock) {
|
2019-11-22 10:21:30 -06:00
|
|
|
guard let account = account else {
|
|
|
|
assertionFailure("Expected folder.account, but got nil.")
|
2019-12-14 18:01:34 -07:00
|
|
|
completion(Set<Article>())
|
2019-11-22 10:21:30 -06:00
|
|
|
return
|
|
|
|
}
|
2019-12-14 18:01:34 -07:00
|
|
|
account.fetchArticlesAsync(.folder(self, false), completion)
|
2019-07-05 20:06:31 -07:00
|
|
|
}
|
2018-02-04 10:57:41 -08:00
|
|
|
|
2019-07-05 20:06:31 -07:00
|
|
|
public func fetchUnreadArticles() -> Set<Article> {
|
2018-02-04 10:57:41 -08:00
|
|
|
guard let account = account else {
|
|
|
|
assertionFailure("Expected folder.account, but got nil.")
|
|
|
|
return Set<Article>()
|
|
|
|
}
|
2019-11-22 10:21:30 -06:00
|
|
|
return account.fetchArticles(.folder(self, true))
|
2019-07-05 20:06:31 -07:00
|
|
|
}
|
2018-02-04 10:57:41 -08:00
|
|
|
|
2019-12-14 18:01:34 -07:00
|
|
|
public func fetchUnreadArticlesAsync(_ completion: @escaping ArticleSetBlock) {
|
2019-07-05 20:06:31 -07:00
|
|
|
guard let account = account else {
|
|
|
|
assertionFailure("Expected folder.account, but got nil.")
|
2019-12-14 18:01:34 -07:00
|
|
|
completion(Set<Article>())
|
2019-07-05 20:06:31 -07:00
|
|
|
return
|
|
|
|
}
|
2019-12-14 18:01:34 -07:00
|
|
|
account.fetchArticlesAsync(.folder(self, true), completion)
|
2018-02-04 10:57:41 -08:00
|
|
|
}
|
|
|
|
}
|