Fetch articles for the Today smart feed.
This commit is contained in:
parent
d6d2b8d26c
commit
5aeb914ab6
|
@ -23,8 +23,11 @@ struct TodayFeedDelegate: SmartFeedDelegate {
|
||||||
|
|
||||||
func fetchArticles() -> Set<Article> {
|
func fetchArticles() -> Set<Article> {
|
||||||
|
|
||||||
// TODO
|
var articles = Set<Article>()
|
||||||
return Set<Article>()
|
for account in AccountManager.shared.accounts {
|
||||||
|
articles.formUnion(account.fetchTodayArticles())
|
||||||
|
}
|
||||||
|
return articles
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchUnreadArticles() -> Set<Article> {
|
func fetchUnreadArticles() -> Set<Article> {
|
||||||
|
|
|
@ -359,6 +359,11 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||||
return articles
|
return articles
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func fetchTodayArticles() -> Set<Article> {
|
||||||
|
|
||||||
|
return database.fetchTodayArticles(for: flattenedFeeds())
|
||||||
|
}
|
||||||
|
|
||||||
private func validateUnreadCount(_ feed: Feed, _ articles: Set<Article>) {
|
private func validateUnreadCount(_ feed: Feed, _ articles: Set<Article>) {
|
||||||
|
|
||||||
// articles must contain all the unread articles for the feed.
|
// articles must contain all the unread articles for the feed.
|
||||||
|
|
|
@ -72,6 +72,11 @@ final class ArticlesTable: DatabaseTable {
|
||||||
return fetchUnreadArticles(feeds.feedIDs())
|
return fetchUnreadArticles(feeds.feedIDs())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func fetchTodayArticles(for feeds: Set<Feed>) -> Set<Article> {
|
||||||
|
|
||||||
|
return fetchTodayArticles(feeds.feedIDs())
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Updating
|
// MARK: Updating
|
||||||
|
|
||||||
func update(_ feed: Feed, _ parsedFeed: ParsedFeed, _ completion: @escaping UpdateArticlesWithFeedCompletionBlock) {
|
func update(_ feed: Feed, _ parsedFeed: ParsedFeed, _ completion: @escaping UpdateArticlesWithFeedCompletionBlock) {
|
||||||
|
@ -328,9 +333,15 @@ private extension ArticlesTable {
|
||||||
// * Must not be deleted.
|
// * Must not be deleted.
|
||||||
// * Must be either 1) starred or 2) dateArrived must be newer than cutoff date.
|
// * Must be either 1) starred or 2) dateArrived must be newer than cutoff date.
|
||||||
|
|
||||||
let sql = withLimits ? "select * from articles natural join statuses where \(whereClause) and userDeleted=0 and (starred=1 or dateArrived>?);" : "select * from articles natural join statuses where \(whereClause);"
|
if withLimits {
|
||||||
|
let sql = "select * from articles natural join statuses where \(whereClause) and userDeleted=0 and (starred=1 or dateArrived>?);"
|
||||||
return articlesWithSQL(sql, parameters + [articleCutoffDate as AnyObject], database)
|
return articlesWithSQL(sql, parameters + [articleCutoffDate as AnyObject], database)
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
let sql = "select * from articles natural join statuses where \(whereClause);"
|
||||||
|
return articlesWithSQL(sql, parameters, database)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func fetchUnreadCount(_ feedID: String, _ database: FMDatabase) -> Int {
|
func fetchUnreadCount(_ feedID: String, _ database: FMDatabase) -> Int {
|
||||||
|
|
||||||
|
@ -369,6 +380,31 @@ private extension ArticlesTable {
|
||||||
return articles
|
return articles
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fetchTodayArticles(_ feedIDs: Set<String>) -> Set<Article> {
|
||||||
|
|
||||||
|
if feedIDs.isEmpty {
|
||||||
|
return Set<Article>()
|
||||||
|
}
|
||||||
|
|
||||||
|
var articles = Set<Article>()
|
||||||
|
|
||||||
|
queue.fetchSync { (database) in
|
||||||
|
|
||||||
|
// select * from articles natural join statuses where feedID in ('http://ranchero.com/xml/rss.xml') and (datePublished > ? || (datePublished is null and dateArrived > ?)
|
||||||
|
//
|
||||||
|
// datePublished may be nil, so we fall back to dateArrived.
|
||||||
|
|
||||||
|
let startOfToday = NSCalendar.startOfToday()
|
||||||
|
let parameters = feedIDs.map { $0 as AnyObject } + [startOfToday as AnyObject, startOfToday as AnyObject]
|
||||||
|
let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))!
|
||||||
|
let whereClause = "feedID in \(placeholders) and (datePublished > ? or (datePublished is null and dateArrived > ?)) and userDeleted = 0"
|
||||||
|
// let whereClause = "feedID in \(placeholders) and datePublished > ? and userDeleted = 0"
|
||||||
|
articles = self.fetchArticlesWithWhereClause(database, whereClause: whereClause, parameters: parameters, withLimits: false)
|
||||||
|
}
|
||||||
|
|
||||||
|
return articles
|
||||||
|
}
|
||||||
|
|
||||||
func articlesWithSQL(_ sql: String, _ parameters: [AnyObject], _ database: FMDatabase) -> Set<Article> {
|
func articlesWithSQL(_ sql: String, _ parameters: [AnyObject], _ database: FMDatabase) -> Set<Article> {
|
||||||
|
|
||||||
guard let resultSet = database.executeQuery(sql, withArgumentsIn: parameters) else {
|
guard let resultSet = database.executeQuery(sql, withArgumentsIn: parameters) else {
|
||||||
|
|
|
@ -57,6 +57,11 @@ public final class Database {
|
||||||
return articlesTable.fetchUnreadArticles(for: feeds)
|
return articlesTable.fetchUnreadArticles(for: feeds)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func fetchTodayArticles(for feeds: Set<Feed>) -> Set<Article> {
|
||||||
|
|
||||||
|
return articlesTable.fetchTodayArticles(for: feeds)
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Unread Counts
|
// MARK: - Unread Counts
|
||||||
|
|
||||||
public func fetchUnreadCounts(for feeds: Set<Feed>, _ completion: @escaping UnreadCountCompletionBlock) {
|
public func fetchUnreadCounts(for feeds: Set<Feed>, _ completion: @escaping UnreadCountCompletionBlock) {
|
||||||
|
|
|
@ -23,7 +23,7 @@ extension Article {
|
||||||
let authors = Author.authorsWithParsedAuthors(parsedItem.authors)
|
let authors = Author.authorsWithParsedAuthors(parsedItem.authors)
|
||||||
let attachments = Attachment.attachmentsWithParsedAttachments(parsedItem.attachments)
|
let attachments = Attachment.attachmentsWithParsedAttachments(parsedItem.attachments)
|
||||||
|
|
||||||
self.init(accountID: accountID, articleID: parsedItem.syncServiceID, feedID: feedID, uniqueID: parsedItem.uniqueID, title: parsedItem.title, contentHTML: parsedItem.contentHTML, contentText: parsedItem.contentText, url: parsedItem.url, externalURL: parsedItem.externalURL, summary: parsedItem.summary, imageURL: parsedItem.imageURL, bannerImageURL: parsedItem.bannerImageURL, datePublished: parsedItem.datePublished, dateModified: parsedItem.dateModified, authors: authors, attachments: attachments, status: status)
|
self.init(accountID: accountID, articleID: parsedItem.syncServiceID, feedID: feedID, uniqueID: parsedItem.uniqueID, title: parsedItem.title, contentHTML: parsedItem.contentHTML, contentText: parsedItem.contentText, url: parsedItem.url, externalURL: parsedItem.externalURL, summary: parsedItem.summary, imageURL: parsedItem.imageURL, bannerImageURL: parsedItem.bannerImageURL, datePublished: parsedItem.datePublished ?? parsedItem.dateModified, dateModified: parsedItem.dateModified, authors: authors, attachments: attachments, status: status)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func addPossibleStringChangeWithKeyPath(_ comparisonKeyPath: KeyPath<Article,String?>, _ otherArticle: Article, _ key: String, _ dictionary: NSMutableDictionary) {
|
private func addPossibleStringChangeWithKeyPath(_ comparisonKeyPath: KeyPath<Article,String?>, _ otherArticle: Article, _ key: String, _ dictionary: NSMutableDictionary) {
|
||||||
|
|
Loading…
Reference in New Issue