Add ArticleFetcher protocol. Add Feed and Folder extensions for it.

This commit is contained in:
Brent Simmons 2018-02-04 10:57:41 -08:00
parent 27c5ffa5eb
commit a6db249ab6
5 changed files with 67 additions and 20 deletions

View File

@ -333,7 +333,14 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
validateUnreadCount(feed, articles)
return articles
}
public func fetchUnreadArticles(for feed: Feed) -> Set<Article> {
let articles = database.fetchUnreadArticles(for: Set([feed]))
validateUnreadCount(feed, articles)
return articles
}
public func fetchArticles(folder: Folder) -> Set<Article> {
let feeds = folder.flattenedFeeds()

View File

@ -28,6 +28,7 @@
84C3654A1F899F3B001EC85C /* CombinedRefreshProgress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C365491F899F3B001EC85C /* CombinedRefreshProgress.swift */; };
84C8B3F41F89DE430053CCA6 /* DataExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C8B3F31F89DE430053CCA6 /* DataExtensions.swift */; };
84CAD7161FDF2E22000F0755 /* FeedbinArticle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84CAD7151FDF2E22000F0755 /* FeedbinArticle.swift */; };
84F73CF1202788D90000BCEF /* ArticleFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F73CF0202788D80000BCEF /* ArticleFetcher.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -128,6 +129,7 @@
84C365491F899F3B001EC85C /* CombinedRefreshProgress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CombinedRefreshProgress.swift; sourceTree = "<group>"; };
84C8B3F31F89DE430053CCA6 /* DataExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataExtensions.swift; sourceTree = "<group>"; };
84CAD7151FDF2E22000F0755 /* FeedbinArticle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedbinArticle.swift; sourceTree = "<group>"; };
84F73CF0202788D80000BCEF /* ArticleFetcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArticleFetcher.swift; sourceTree = "<group>"; };
D511EEB5202422BB00712EC3 /* Account_project_debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Account_project_debug.xcconfig; sourceTree = "<group>"; };
D511EEB6202422BB00712EC3 /* Account_target.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Account_target.xcconfig; sourceTree = "<group>"; };
D511EEB7202422BB00712EC3 /* Account_project_release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Account_project_release.xcconfig; sourceTree = "<group>"; };
@ -237,6 +239,7 @@
84B99C9E1FAE8D3200ECDEDB /* ContainerPath.swift */,
84C365491F899F3B001EC85C /* CombinedRefreshProgress.swift */,
84C8B3F31F89DE430053CCA6 /* DataExtensions.swift */,
84F73CF0202788D80000BCEF /* ArticleFetcher.swift */,
8419740D1F6DD25F006346C4 /* Container.swift */,
8419742B1F6DDE84006346C4 /* LocalAccount */,
84245C7D1FDDD2580074AFBB /* Feedbin */,
@ -476,6 +479,7 @@
84C3654A1F899F3B001EC85C /* CombinedRefreshProgress.swift in Sources */,
8469F81C1F6DD15E0084783E /* Account.swift in Sources */,
846E77451F6EF9B900A165E2 /* Container.swift in Sources */,
84F73CF1202788D90000BCEF /* ArticleFetcher.swift in Sources */,
84245C7F1FDDD2580074AFBB /* FeedbinAccountDelegate.swift in Sources */,
841974251F6DDCE4006346C4 /* AccountDelegate.swift in Sources */,
846E77541F6F00E300A165E2 /* AccountManager.swift in Sources */,

View File

@ -0,0 +1,55 @@
//
// ArticleFetcher.swift
// Account
//
// Created by Brent Simmons on 2/4/18.
// Copyright © 2018 Ranchero Software, LLC. All rights reserved.
//
import Foundation
import Data
public protocol ArticleFetcher {
func fetchArticles() -> Set<Article>
func fetchUnreadArticles() -> Set<Article>
}
extension Feed: ArticleFetcher {
public func fetchArticles() -> Set<Article> {
guard let account = account else {
assertionFailure("Expected feed.account, but got nil.")
return Set<Article>()
}
return account.fetchArticles(for: self)
}
public func fetchUnreadArticles() -> Set<Article> {
guard let account = account else {
assertionFailure("Expected feed.account, but got nil.")
return Set<Article>()
}
return account.fetchUnreadArticles(for: self)
}
}
extension Folder: ArticleFetcher {
public func fetchArticles() -> Set<Article> {
return fetchUnreadArticles()
}
public func fetchUnreadArticles() -> Set<Article> {
guard let account = account else {
assertionFailure("Expected folder.account, but got nil.")
return Set<Article>()
}
return account.fetchArticles(folder: self)
}
}

View File

@ -23,15 +23,6 @@ public extension Feed {
}
}
public func fetchArticles() -> Set<Article> {
guard let account = account else {
assertionFailure("Expected feed.account.")
return Set<Article>()
}
return account.fetchArticles(for: self)
}
public func takeSettings(from parsedFeed: ParsedFeed) {
var didChangeAtLeastOneSetting = false

View File

@ -26,16 +26,6 @@ public final class Folder: DisplayNameProvider, Container, UnreadCountProvider,
static var incrementingID = 0
public let hashValue: Int
// MARK: - Fetching Articles
public func fetchArticles() -> Set<Article> {
guard let account = account else {
return Set<Article>()
}
return account.fetchArticles(folder: self)
}
// MARK: - DisplayNameProvider
public var nameForDisplay: String {