Merge branch 'main' into localize_strings

# Conflicts:
#	Shared/Timer/AccountRefreshTimer.swift
This commit is contained in:
Stuart Breckenridge
2023-01-04 15:17:14 +08:00
22 changed files with 593 additions and 142 deletions

View File

@@ -653,6 +653,22 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
fetchUnreadCounts(for: webFeeds, completion: completion)
}
public func fetchUnreadArticlesBetween(limit: Int?, before: Date?, after: Date?) throws -> Set<Article> {
return try fetchUnreadArticlesBetween(forContainer: self, limit: limit, before: before, after: after)
}
public func fetchUnreadArticlesBetween(folder: Folder, limit: Int?, before: Date?, after: Date?) throws -> Set<Article> {
return try fetchUnreadArticlesBetween(forContainer: folder, limit: limit, before: before, after: after)
}
public func fetchUnreadArticlesBetween(webFeeds: Set<WebFeed>, limit: Int?, before: Date?, after: Date?) throws -> Set<Article> {
return try fetchUnreadArticlesBetween(feeds: webFeeds, limit: limit, before: before, after: after)
}
public func fetchArticlesBetween(articleIDs: Set<String>, before: Date?, after: Date?) throws -> Set<Article> {
return try database.fetchArticlesBetween(articleIDs: articleIDs, before: before, after: after)
}
public func fetchArticles(_ fetchType: FetchType) throws -> Set<Article> {
switch fetchType {
case .starred(let limit):
@@ -1150,6 +1166,17 @@ private extension Account {
return articles
}
func fetchUnreadArticlesBetween(forContainer container: Container, limit: Int?, before: Date?, after: Date?) throws -> Set<Article> {
let feeds = container.flattenedWebFeeds()
let articles = try database.fetchUnreadArticlesBetween(feeds.webFeedIDs(), limit, before, after)
return articles
}
func fetchUnreadArticlesBetween(feeds: Set<WebFeed>, limit: Int?, before: Date?, after: Date?) throws -> Set<Article> {
let articles = try database.fetchUnreadArticlesBetween(feeds.webFeedIDs(), limit, before, after)
return articles
}
func fetchUnreadArticlesAsync(forContainer container: Container, limit: Int?, _ completion: @escaping ArticleSetResultBlock) {
let webFeeds = container.flattenedWebFeeds()
database.fetchUnreadArticlesAsync(webFeeds.webFeedIDs(), limit) { [weak self] (articleSetResult) in

View File

@@ -368,6 +368,16 @@ public final class AccountManager: UnreadCountProvider {
}
}
}
public func fetchUnreadArticlesBetween(limit: Int? = nil, before: Date? = nil, after: Date? = nil) throws -> Set<Article> {
precondition(Thread.isMainThread)
var articles = Set<Article>()
for account in activeAccounts {
articles.formUnion(try account.fetchUnreadArticlesBetween(limit: limit, before: before, after: after))
}
return articles
}
// MARK: - Fetching Article Counts

View File

@@ -15,6 +15,7 @@ public protocol ArticleFetcher {
func fetchArticles() throws -> Set<Article>
func fetchArticlesAsync(_ completion: @escaping ArticleSetResultBlock)
func fetchUnreadArticles() throws -> Set<Article>
func fetchUnreadArticlesBetween(before: Date?, after: Date?) throws -> Set<Article>
func fetchUnreadArticlesAsync(_ completion: @escaping ArticleSetResultBlock)
}
@@ -37,6 +38,10 @@ extension WebFeed: ArticleFetcher {
return try fetchArticles().unreadArticles()
}
public func fetchUnreadArticlesBetween(before: Date? = nil, after: Date? = nil) throws -> Set<Article> {
return try account?.fetchUnreadArticlesBetween(webFeeds: [self], limit: nil, before: before, after: after) ?? Set<Article>()
}
public func fetchUnreadArticlesAsync(_ completion: @escaping ArticleSetResultBlock) {
guard let account = account else {
assertionFailure("Expected feed.account, but got nil.")
@@ -81,6 +86,14 @@ extension Folder: ArticleFetcher {
return try account.fetchArticles(.folder(self, true))
}
public func fetchUnreadArticlesBetween(before: Date? = nil, after: Date? = nil) throws -> Set<Article> {
guard let account = account else {
assertionFailure("Expected folder.account, but got nil.")
return Set<Article>()
}
return try account.fetchUnreadArticlesBetween(folder: self, limit: nil, before: before, after: after)
}
public func fetchUnreadArticlesAsync(_ completion: @escaping ArticleSetResultBlock) {
guard let account = account else {
assertionFailure("Expected folder.account, but got nil.")

View File

@@ -31,6 +31,10 @@ public struct SingleArticleFetcher: ArticleFetcher {
public func fetchUnreadArticles() throws -> Set<Article> {
return try account.fetchArticles(.articleIDs(Set([articleID])))
}
public func fetchUnreadArticlesBetween(before: Date? = nil, after: Date? = nil) throws -> Set<Article> {
return try account.fetchArticlesBetween(articleIDs: Set([articleID]), before: before, after: after)
}
public func fetchUnreadArticlesAsync(_ completion: @escaping ArticleSetResultBlock) {
return account.fetchArticlesAsync(.articleIDs(Set([articleID])), completion)