Add methods for fetching unread count since a certain date to Database.framework.
This commit is contained in:
parent
e681007bbe
commit
19673f5c8a
|
@ -142,6 +142,28 @@ final class ArticlesTable: DatabaseTable {
|
|||
}
|
||||
}
|
||||
|
||||
func fetchUnreadCount(_ feeds: Set<Feed>, _ since: Date, _ callback: @escaping (Int) -> Void) {
|
||||
|
||||
// Get unread count for today, for instance.
|
||||
|
||||
let feedIDs = feeds.feedIDs()
|
||||
queue.fetch { (database) in
|
||||
|
||||
let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))!
|
||||
let sql = "select count(*) from articles natural join statuses where feedID in \(placeholders) and datePublished > ? and read=0 and userDeleted=0;"
|
||||
|
||||
var parameters = [Any]()
|
||||
parameters += Array(feedIDs) as [Any]
|
||||
parameters += [since] as [Any]
|
||||
|
||||
let unreadCount = self.numberWithSQLAndParameters(sql, parameters, in: database)
|
||||
|
||||
DispatchQueue.main.async() {
|
||||
callback(unreadCount)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Status
|
||||
|
||||
func mark(_ articles: Set<Article>, _ statusKey: ArticleStatus.Key, _ flag: Bool) -> Set<ArticleStatus>? {
|
||||
|
|
|
@ -61,6 +61,11 @@ public final class Database {
|
|||
articlesTable.fetchUnreadCounts(feeds, completion)
|
||||
}
|
||||
|
||||
public func fetchUnreadCount(for feeds: Set<Feed>, since: Date, callback: @escaping (Int) -> Void) {
|
||||
|
||||
articlesTable.fetchUnreadCount(feeds, since, callback)
|
||||
}
|
||||
|
||||
// MARK: - Saving and Updating Articles
|
||||
|
||||
public func update(feed: Feed, parsedFeed: ParsedFeed, completion: @escaping UpdateArticlesWithFeedCompletionBlock) {
|
||||
|
|
Loading…
Reference in New Issue