Continue changes mandated by DatabaseQueue changes.
This commit is contained in:
parent
e700da9410
commit
67f65545b3
@ -621,32 +621,32 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
}
|
||||
}
|
||||
|
||||
public func fetchArticles(_ fetchType: FetchType) -> Set<Article> {
|
||||
public func fetchArticles(_ fetchType: FetchType) throws -> Set<Article> {
|
||||
switch fetchType {
|
||||
case .starred:
|
||||
return fetchStarredArticles()
|
||||
case .unread:
|
||||
return fetchUnreadArticles()
|
||||
return try fetchUnreadArticles()
|
||||
case .today:
|
||||
return fetchTodayArticles()
|
||||
return try fetchTodayArticles()
|
||||
case .folder(let folder, let readFilter):
|
||||
if readFilter {
|
||||
return fetchUnreadArticles(folder: folder)
|
||||
return try fetchUnreadArticles(folder: folder)
|
||||
} else {
|
||||
return fetchArticles(folder: folder)
|
||||
return try fetchArticles(folder: folder)
|
||||
}
|
||||
case .webFeed(let webFeed):
|
||||
return fetchArticles(webFeed: webFeed)
|
||||
return try fetchArticles(webFeed: webFeed)
|
||||
case .articleIDs(let articleIDs):
|
||||
return fetchArticles(articleIDs: articleIDs)
|
||||
return try fetchArticles(articleIDs: articleIDs)
|
||||
case .search(let searchString):
|
||||
return fetchArticlesMatching(searchString)
|
||||
return try fetchArticlesMatching(searchString)
|
||||
case .searchWithArticleIDs(let searchString, let articleIDs):
|
||||
return fetchArticlesMatchingWithArticleIDs(searchString, articleIDs)
|
||||
return try fetchArticlesMatchingWithArticleIDs(searchString, articleIDs)
|
||||
}
|
||||
}
|
||||
|
||||
public func fetchArticlesAsync(_ fetchType: FetchType, _ completion: @escaping ArticleSetBlock) {
|
||||
public func fetchArticlesAsync(_ fetchType: FetchType, _ completion: @escaping ArticleSetResultBlock) {
|
||||
switch fetchType {
|
||||
case .starred:
|
||||
fetchStarredArticlesAsync(completion)
|
||||
@ -719,7 +719,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
func update(webFeedIDsAndItems: [String: Set<ParsedItem>], defaultRead: Bool, completion: @escaping DatabaseCompletionBlock) {
|
||||
precondition(Thread.isMainThread)
|
||||
guard !webFeedIDsAndItems.isEmpty else {
|
||||
completion()
|
||||
completion(nil)
|
||||
return
|
||||
}
|
||||
database.update(webFeedIDsAndItems: webFeedIDsAndItems, defaultRead: defaultRead) { updateArticlesResult in
|
||||
@ -740,7 +740,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
}
|
||||
userInfo[UserInfoKey.webFeeds] = webFeeds
|
||||
|
||||
completion(.success)
|
||||
completion(nil)
|
||||
|
||||
NotificationCenter.default.post(name: .AccountDidDownloadArticles, object: self, userInfo: userInfo)
|
||||
}
|
||||
@ -749,15 +749,15 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
case .success(let newAndUpdatedArticles):
|
||||
process(newAndUpdatedArticles)
|
||||
case .failure(let databaseError):
|
||||
completion(.failure(databaseError))
|
||||
completion(databaseError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
func update(_ articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) -> Set<Article>? {
|
||||
func update(_ articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) throws -> Set<Article>? {
|
||||
// Returns set of Articles whose statuses did change.
|
||||
guard !articles.isEmpty, let updatedStatuses = database.mark(articles, statusKey: statusKey, flag: flag) else {
|
||||
guard !articles.isEmpty, let updatedStatuses = try database.mark(articles, statusKey: statusKey, flag: flag) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -768,9 +768,9 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
return updatedArticles
|
||||
}
|
||||
|
||||
func ensureStatuses(_ articleIDs: Set<String>, _ defaultRead: Bool, _ statusKey: ArticleStatus.Key, _ flag: Bool, completion: VoidCompletionBlock? = nil) {
|
||||
func ensureStatuses(_ articleIDs: Set<String>, _ defaultRead: Bool, _ statusKey: ArticleStatus.Key, _ flag: Bool, completion: @escaping DatabaseCompletionBlock) {
|
||||
guard !articleIDs.isEmpty else {
|
||||
completion?()
|
||||
completion(nil)
|
||||
return
|
||||
}
|
||||
database.ensureStatuses(articleIDs, defaultRead, statusKey, flag, completion: completion)
|
||||
@ -783,7 +783,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
|
||||
/// Fetch statuses for the specified articleIDs. The completion handler will get nil if the app is suspended.
|
||||
/// To update the properties in the database, call the update method that takes Set<ArticleStatus> as first parameter.
|
||||
func fetchStatuses(articleIDs: Set<String>, createIfNeeded: Bool, completion: @escaping (Set<ArticleStatus>?) -> Void) {
|
||||
func fetchStatuses(articleIDs: Set<String>, createIfNeeded: Bool, completion: @escaping ArticleStatusesResultBlock) {
|
||||
database.fetchStatuses(articleIDs: articleIDs, createIfNeeded: createIfNeeded, completion: completion)
|
||||
}
|
||||
|
||||
@ -937,7 +937,7 @@ private extension Account {
|
||||
return database.fetchStarredArticles(flattenedWebFeeds().webFeedIDs())
|
||||
}
|
||||
|
||||
func fetchStarredArticlesAsync(_ completion: @escaping ArticleSetBlock) {
|
||||
func fetchStarredArticlesAsync(_ completion: @escaping ArticleSetResultBlock) {
|
||||
database.fetchedStarredArticlesAsync(flattenedWebFeeds().webFeedIDs(), completion)
|
||||
}
|
||||
|
||||
@ -945,7 +945,7 @@ private extension Account {
|
||||
return try fetchUnreadArticles(forContainer: self)
|
||||
}
|
||||
|
||||
func fetchUnreadArticlesAsync(_ completion: @escaping ArticleSetBlock) {
|
||||
func fetchUnreadArticlesAsync(_ completion: @escaping ArticleSetResultBlock) {
|
||||
fetchUnreadArticlesAsync(forContainer: self, completion)
|
||||
}
|
||||
|
||||
@ -953,7 +953,7 @@ private extension Account {
|
||||
return try database.fetchTodayArticles(flattenedWebFeeds().webFeedIDs())
|
||||
}
|
||||
|
||||
func fetchTodayArticlesAsync(_ completion: @escaping ArticleSetBlock) {
|
||||
func fetchTodayArticlesAsync(_ completion: @escaping ArticleSetResultBlock) {
|
||||
database.fetchTodayArticlesAsync(flattenedWebFeeds().webFeedIDs(), completion)
|
||||
}
|
||||
|
||||
@ -961,7 +961,7 @@ private extension Account {
|
||||
return try fetchArticles(forContainer: folder)
|
||||
}
|
||||
|
||||
func fetchArticlesAsync(folder: Folder, _ completion: @escaping ArticleSetBlock) {
|
||||
func fetchArticlesAsync(folder: Folder, _ completion: @escaping ArticleSetResultBlock) {
|
||||
fetchArticlesAsync(forContainer: folder, completion)
|
||||
}
|
||||
|
||||
@ -969,7 +969,7 @@ private extension Account {
|
||||
return try fetchUnreadArticles(forContainer: folder)
|
||||
}
|
||||
|
||||
func fetchUnreadArticlesAsync(folder: Folder, _ completion: @escaping ArticleSetBlock) {
|
||||
func fetchUnreadArticlesAsync(folder: Folder, _ completion: @escaping ArticleSetResultBlock) {
|
||||
fetchUnreadArticlesAsync(forContainer: folder, completion)
|
||||
}
|
||||
|
||||
@ -979,7 +979,7 @@ private extension Account {
|
||||
return articles
|
||||
}
|
||||
|
||||
func fetchArticlesAsync(webFeed: WebFeed, _ completion: @escaping ArticleSetBlock) {
|
||||
func fetchArticlesAsync(webFeed: WebFeed, _ completion: @escaping ArticleSetResultBlock) {
|
||||
database.fetchArticlesAsync(webFeed.webFeedID) { [weak self] (articles) in
|
||||
self?.validateUnreadCount(webFeed, articles)
|
||||
completion(articles)
|
||||
@ -994,11 +994,11 @@ private extension Account {
|
||||
return try database.fetchArticlesMatchingWithArticleIDs(searchString, articleIDs)
|
||||
}
|
||||
|
||||
func fetchArticlesMatchingAsync(_ searchString: String, _ completion: @escaping ArticleSetBlock) {
|
||||
func fetchArticlesMatchingAsync(_ searchString: String, _ completion: @escaping ArticleSetResultBlock) {
|
||||
database.fetchArticlesMatchingAsync(searchString, flattenedWebFeeds().webFeedIDs(), completion)
|
||||
}
|
||||
|
||||
func fetchArticlesMatchingWithArticleIDsAsync(_ searchString: String, _ articleIDs: Set<String>, _ completion: @escaping ArticleSetBlock) {
|
||||
func fetchArticlesMatchingWithArticleIDsAsync(_ searchString: String, _ articleIDs: Set<String>, _ completion: @escaping ArticleSetResultBlock) {
|
||||
database.fetchArticlesMatchingWithArticleIDsAsync(searchString, articleIDs, completion)
|
||||
}
|
||||
|
||||
@ -1006,7 +1006,7 @@ private extension Account {
|
||||
return try database.fetchArticles(articleIDs: articleIDs)
|
||||
}
|
||||
|
||||
func fetchArticlesAsync(articleIDs: Set<String>, _ completion: @escaping ArticleSetBlock) {
|
||||
func fetchArticlesAsync(articleIDs: Set<String>, _ completion: @escaping ArticleSetResultBlock) {
|
||||
return database.fetchArticlesAsync(articleIDs: articleIDs, completion)
|
||||
}
|
||||
|
||||
@ -1031,7 +1031,7 @@ private extension Account {
|
||||
return articles
|
||||
}
|
||||
|
||||
func fetchArticlesAsync(forContainer container: Container, _ completion: @escaping ArticleSetBlock) {
|
||||
func fetchArticlesAsync(forContainer container: Container, _ completion: @escaping ArticleSetResultBlock) {
|
||||
let webFeeds = container.flattenedWebFeeds()
|
||||
database.fetchArticlesAsync(webFeeds.webFeedIDs()) { [weak self] (articles) in
|
||||
self?.validateUnreadCountsAfterFetchingUnreadArticles(webFeeds, articles)
|
||||
@ -1046,7 +1046,7 @@ private extension Account {
|
||||
return articles
|
||||
}
|
||||
|
||||
func fetchUnreadArticlesAsync(forContainer container: Container, _ completion: @escaping ArticleSetBlock) {
|
||||
func fetchUnreadArticlesAsync(forContainer container: Container, _ completion: @escaping ArticleSetResultBlock) {
|
||||
let webFeeds = container.flattenedWebFeeds()
|
||||
database.fetchUnreadArticlesAsync(webFeeds.webFeedIDs()) { [weak self] (articles) in
|
||||
self?.validateUnreadCountsAfterFetchingUnreadArticles(webFeeds, articles)
|
||||
|
@ -53,7 +53,7 @@ protocol AccountDelegate {
|
||||
/// Suspend all network activity
|
||||
func suspendNetwork()
|
||||
|
||||
/// Suspend the SQLLite databases
|
||||
/// Suspend the SQLite databases
|
||||
func suspendDatabase()
|
||||
|
||||
/// Make sure no SQLite databases are open and we are ready to issue network requests.
|
||||
|
@ -476,7 +476,7 @@ final class FeedlyAccountDelegate: AccountDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
func markArticles(for account: Account, articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) -> Set<Article>? {
|
||||
func markArticles(for account: Account, articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) throws -> Set<Article>? {
|
||||
|
||||
let syncStatuses = articles.map { article in
|
||||
return SyncStatus(articleID: article.articleID, key: statusKey, flag: flag)
|
||||
@ -491,7 +491,7 @@ final class FeedlyAccountDelegate: AccountDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
return account.update(articles, statusKey: statusKey, flag: flag)
|
||||
return try account.update(articles, statusKey: statusKey, flag: flag)
|
||||
}
|
||||
|
||||
func accountDidInitialize(_ account: Account) {
|
||||
|
@ -32,10 +32,20 @@ final class FeedlySetStarredArticlesOperation: FeedlyOperation {
|
||||
return
|
||||
}
|
||||
|
||||
account.fetchStarredArticleIDs(didFetchStarredArticleIDs(_:))
|
||||
account.fetchStarredArticleIDs { (articleIDsResult) in
|
||||
if let localStarredArticleIDs = try? articleIDsResult.get() {
|
||||
self.didFetchStarredArticleIDs(localStarredArticleIDs)
|
||||
}
|
||||
else {
|
||||
self.didFinish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func didFetchStarredArticleIDs(_ localStarredArticleIDs: Set<String>) {
|
||||
private extension FeedlySetStarredArticlesOperation {
|
||||
|
||||
func didFetchStarredArticleIDs(_ localStarredArticleIDs: Set<String>) {
|
||||
guard !isCancelled else {
|
||||
didFinish()
|
||||
return
|
||||
|
@ -187,7 +187,7 @@ final class LocalAccountDelegate: AccountDelegate {
|
||||
}
|
||||
|
||||
func markArticles(for account: Account, articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) -> Set<Article>? {
|
||||
return account.update(articles, statusKey: statusKey, flag: flag)
|
||||
return try account.update(articles, statusKey: statusKey, flag: flag)
|
||||
}
|
||||
|
||||
func accountDidInitialize(_ account: Account) {
|
||||
|
@ -25,8 +25,8 @@ public typealias SingleUnreadCountResult = Result<Int, DatabaseError>
|
||||
public typealias SingleUnreadCountCompletionBlock = (SingleUnreadCountResult) -> Void
|
||||
|
||||
public struct NewAndUpdatedArticles {
|
||||
let newArticles: Set<Article>?
|
||||
let updatedArticles: Set<Article>?
|
||||
public let newArticles: Set<Article>?
|
||||
public let updatedArticles: Set<Article>?
|
||||
}
|
||||
|
||||
public typealias UpdateArticlesResult = Result<NewAndUpdatedArticles, DatabaseError>
|
||||
|
Loading…
x
Reference in New Issue
Block a user