From a6db249ab6f2a26c0bd3a53364a8362f2aa8d4d5 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 4 Feb 2018 10:57:41 -0800 Subject: [PATCH] Add ArticleFetcher protocol. Add Feed and Folder extensions for it. --- Frameworks/Account/Account.swift | 9 ++- .../Account/Account.xcodeproj/project.pbxproj | 4 ++ Frameworks/Account/ArticleFetcher.swift | 55 +++++++++++++++++++ Frameworks/Account/DataExtensions.swift | 9 --- Frameworks/Account/Folder.swift | 10 ---- 5 files changed, 67 insertions(+), 20 deletions(-) create mode 100644 Frameworks/Account/ArticleFetcher.swift diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index 4f723d5aa..b547ef459 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -333,7 +333,14 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, validateUnreadCount(feed, articles) return articles } - + + public func fetchUnreadArticles(for feed: Feed) -> Set
{ + + let articles = database.fetchUnreadArticles(for: Set([feed])) + validateUnreadCount(feed, articles) + return articles + } + public func fetchArticles(folder: Folder) -> Set
{ let feeds = folder.flattenedFeeds() diff --git a/Frameworks/Account/Account.xcodeproj/project.pbxproj b/Frameworks/Account/Account.xcodeproj/project.pbxproj index c4934b57f..41d7dbda3 100644 --- a/Frameworks/Account/Account.xcodeproj/project.pbxproj +++ b/Frameworks/Account/Account.xcodeproj/project.pbxproj @@ -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 = ""; }; 84C8B3F31F89DE430053CCA6 /* DataExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataExtensions.swift; sourceTree = ""; }; 84CAD7151FDF2E22000F0755 /* FeedbinArticle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedbinArticle.swift; sourceTree = ""; }; + 84F73CF0202788D80000BCEF /* ArticleFetcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArticleFetcher.swift; sourceTree = ""; }; D511EEB5202422BB00712EC3 /* Account_project_debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Account_project_debug.xcconfig; sourceTree = ""; }; D511EEB6202422BB00712EC3 /* Account_target.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Account_target.xcconfig; sourceTree = ""; }; D511EEB7202422BB00712EC3 /* Account_project_release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Account_project_release.xcconfig; sourceTree = ""; }; @@ -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 */, diff --git a/Frameworks/Account/ArticleFetcher.swift b/Frameworks/Account/ArticleFetcher.swift new file mode 100644 index 000000000..0b8188b03 --- /dev/null +++ b/Frameworks/Account/ArticleFetcher.swift @@ -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
+ func fetchUnreadArticles() -> Set
+} + +extension Feed: ArticleFetcher { + + public func fetchArticles() -> Set
{ + + guard let account = account else { + assertionFailure("Expected feed.account, but got nil.") + return Set
() + } + return account.fetchArticles(for: self) + } + + public func fetchUnreadArticles() -> Set
{ + + guard let account = account else { + assertionFailure("Expected feed.account, but got nil.") + return Set
() + } + return account.fetchUnreadArticles(for: self) + } +} + +extension Folder: ArticleFetcher { + + public func fetchArticles() -> Set
{ + + return fetchUnreadArticles() + } + + public func fetchUnreadArticles() -> Set
{ + + guard let account = account else { + assertionFailure("Expected folder.account, but got nil.") + return Set
() + } + + return account.fetchArticles(folder: self) + } +} diff --git a/Frameworks/Account/DataExtensions.swift b/Frameworks/Account/DataExtensions.swift index 9e565a73a..7f813cba7 100644 --- a/Frameworks/Account/DataExtensions.swift +++ b/Frameworks/Account/DataExtensions.swift @@ -23,15 +23,6 @@ public extension Feed { } } - public func fetchArticles() -> Set
{ - - guard let account = account else { - assertionFailure("Expected feed.account.") - return Set
() - } - return account.fetchArticles(for: self) - } - public func takeSettings(from parsedFeed: ParsedFeed) { var didChangeAtLeastOneSetting = false diff --git a/Frameworks/Account/Folder.swift b/Frameworks/Account/Folder.swift index 442ada83f..85d411b06 100644 --- a/Frameworks/Account/Folder.swift +++ b/Frameworks/Account/Folder.swift @@ -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
{ - - guard let account = account else { - return Set
() - } - return account.fetchArticles(folder: self) - } - // MARK: - DisplayNameProvider public var nameForDisplay: String {