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
|
|
|
}
|
|
|
|
|
2019-11-15 03:11:41 +01:00
|
|
|
extension WebFeed: ArticleFetcher {
|
2019-11-14 22:06:32 +01:00
|
|
|
|
2018-02-04 19:57:41 +01:00
|
|
|
public func fetchArticles() -> Set<Article> {
|
2019-11-15 03:11:41 +01:00
|
|
|
return account?.fetchArticles(.webFeed(self)) ?? Set<Article>()
|
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 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-11-15 03:11:41 +01:00
|
|
|
account.fetchArticlesAsync(.webFeed(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
|
|
|
|
}
|
2019-11-15 03:11:41 +01:00
|
|
|
account.fetchArticlesAsync(.webFeed(self)) { callback($0.unreadArticles()) }
|
2018-02-04 19:57:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Folder: ArticleFetcher {
|
2019-11-14 22:06:32 +01:00
|
|
|
|
2018-02-04 19:57:41 +01:00
|
|
|
public func fetchArticles() -> Set<Article> {
|
2019-11-22 17:21:30 +01: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 19:57:41 +01:00
|
|
|
}
|
|
|
|
|
2019-07-06 05:06:31 +02:00
|
|
|
public func fetchArticlesAsync(_ callback: @escaping ArticleSetBlock) {
|
2019-11-22 17:21:30 +01:00
|
|
|
guard let account = account else {
|
|
|
|
assertionFailure("Expected folder.account, but got nil.")
|
|
|
|
callback(Set<Article>())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
account.fetchArticlesAsync(.folder(self, false), callback)
|
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 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-11-22 17:21:30 +01:00
|
|
|
return account.fetchArticles(.folder(self, true))
|
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) {
|
|
|
|
guard let account = account else {
|
|
|
|
assertionFailure("Expected folder.account, but got nil.")
|
|
|
|
callback(Set<Article>())
|
|
|
|
return
|
|
|
|
}
|
2019-11-22 17:21:30 +01:00
|
|
|
account.fetchArticlesAsync(.folder(self, true), callback)
|
2018-02-04 19:57:41 +01:00
|
|
|
}
|
|
|
|
}
|