diff --git a/Evergreen/SmartFeeds/StarredFeedDelegate.swift b/Evergreen/SmartFeeds/StarredFeedDelegate.swift index e09ca4db9..9d2f3bc2f 100644 --- a/Evergreen/SmartFeeds/StarredFeedDelegate.swift +++ b/Evergreen/SmartFeeds/StarredFeedDelegate.swift @@ -24,8 +24,11 @@ struct StarredFeedDelegate: SmartFeedDelegate { func fetchArticles() -> Set
{ - // TODO - return Set
() + var articles = Set
() + for account in AccountManager.shared.accounts { + articles.formUnion(account.fetchStarredArticles()) + } + return articles } func fetchUnreadArticles() -> Set
{ diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index 44c334222..4853ddea2 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -364,6 +364,11 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, return database.fetchTodayArticles(for: flattenedFeeds()) } + public func fetchStarredArticles() -> Set
{ + + return database.fetchStarredArticles(for: flattenedFeeds()) + } + private func validateUnreadCount(_ feed: Feed, _ articles: Set
) { // articles must contain all the unread articles for the feed. diff --git a/Frameworks/Database/ArticlesTable.swift b/Frameworks/Database/ArticlesTable.swift index 8bc0aeccb..ea251ab70 100644 --- a/Frameworks/Database/ArticlesTable.swift +++ b/Frameworks/Database/ArticlesTable.swift @@ -77,6 +77,11 @@ final class ArticlesTable: DatabaseTable { return fetchTodayArticles(feeds.feedIDs()) } + public func fetchStarredArticles(for feeds: Set) -> Set
{ + + return fetchStarredArticles(feeds.feedIDs()) + } + // MARK: Updating func update(_ feed: Feed, _ parsedFeed: ParsedFeed, _ completion: @escaping UpdateArticlesWithFeedCompletionBlock) { @@ -405,6 +410,28 @@ private extension ArticlesTable { return articles } + func fetchStarredArticles(_ feedIDs: Set) -> Set
{ + + if feedIDs.isEmpty { + return Set
() + } + + var articles = Set
() + + queue.fetchSync { (database) in + + // select * from articles natural join statuses where feedID in ('http://ranchero.com/xml/rss.xml') and starred = 1 and userDeleted = 0; + + let parameters = feedIDs.map { $0 as AnyObject } + let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))! + let whereClause = "feedID in \(placeholders) and starred = 1 and userDeleted = 0" + articles = self.fetchArticlesWithWhereClause(database, whereClause: whereClause, parameters: parameters, withLimits: false) + } + + return articles + } + + func articlesWithSQL(_ sql: String, _ parameters: [AnyObject], _ database: FMDatabase) -> Set
{ guard let resultSet = database.executeQuery(sql, withArgumentsIn: parameters) else { diff --git a/Frameworks/Database/Database.swift b/Frameworks/Database/Database.swift index 9eb372c1c..3fc0624aa 100644 --- a/Frameworks/Database/Database.swift +++ b/Frameworks/Database/Database.swift @@ -62,6 +62,11 @@ public final class Database { return articlesTable.fetchTodayArticles(for: feeds) } + public func fetchStarredArticles(for feeds: Set) -> Set
{ + + return articlesTable.fetchStarredArticles(for: feeds) + } + // MARK: - Unread Counts public func fetchUnreadCounts(for feeds: Set, _ completion: @escaping UnreadCountCompletionBlock) {