diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index d787bfa51..8f52a0d13 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -732,7 +732,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, return updatedArticles } - func ensureStatuses(_ articleIDs: Set, _ defaultRead: Bool, _ statusKey: ArticleStatus.Key, _ flag: Bool, completionHandler: (() -> ())? = nil) { + func ensureStatuses(_ articleIDs: Set, _ defaultRead: Bool, _ statusKey: ArticleStatus.Key, _ flag: Bool, completionHandler: VoidCompletionBlock? = nil) { guard !articleIDs.isEmpty else { completionHandler?() return diff --git a/Frameworks/ArticlesDatabase/ArticlesDatabase.swift b/Frameworks/ArticlesDatabase/ArticlesDatabase.swift index 948deefa2..12fbffcba 100644 --- a/Frameworks/ArticlesDatabase/ArticlesDatabase.swift +++ b/Frameworks/ArticlesDatabase/ArticlesDatabase.swift @@ -7,6 +7,7 @@ // import Foundation +import RSCore import RSDatabase import RSParser import Articles @@ -147,7 +148,7 @@ public final class ArticlesDatabase { articlesTable.update(webFeedIDsAndItems, defaultRead, completion) } - public func ensureStatuses(_ articleIDs: Set, _ defaultRead: Bool, _ statusKey: ArticleStatus.Key, _ flag: Bool, completionHandler: (() -> ())? = nil) { + public func ensureStatuses(_ articleIDs: Set, _ defaultRead: Bool, _ statusKey: ArticleStatus.Key, _ flag: Bool, completionHandler: VoidCompletionBlock? = nil) { articlesTable.ensureStatuses(articleIDs, defaultRead, statusKey, flag, completionHandler: completionHandler) } diff --git a/Frameworks/ArticlesDatabase/ArticlesTable.swift b/Frameworks/ArticlesDatabase/ArticlesTable.swift index 59e65f4ad..6c505ace3 100644 --- a/Frameworks/ArticlesDatabase/ArticlesTable.swift +++ b/Frameworks/ArticlesDatabase/ArticlesTable.swift @@ -298,13 +298,13 @@ final class ArticlesTable: DatabaseTable { } } - func ensureStatuses(_ articleIDs: Set, _ defaultRead: Bool, _ statusKey: ArticleStatus.Key, _ flag: Bool, completionHandler: (() -> ())? = nil) { + func ensureStatuses(_ articleIDs: Set, _ defaultRead: Bool, _ statusKey: ArticleStatus.Key, _ flag: Bool, completionHandler: VoidCompletionBlock? = nil) { queue.runInTransaction { (database) in let statusesDictionary = self.statusesTable.ensureStatusesForArticleIDs(articleIDs, defaultRead, database) let statuses = Set(statusesDictionary.values) self.statusesTable.mark(statuses, statusKey, flag, database) if let handler = completionHandler { - DispatchQueue.main.async(execute: handler) + callVoidCompletionBlock(handler) } } } diff --git a/Frameworks/SyncDatabase/SyncDatabase.swift b/Frameworks/SyncDatabase/SyncDatabase.swift index 568da3353..8ffad570b 100644 --- a/Frameworks/SyncDatabase/SyncDatabase.swift +++ b/Frameworks/SyncDatabase/SyncDatabase.swift @@ -7,6 +7,7 @@ // import Foundation +import RSCore import RSDatabase public struct SyncDatabase { @@ -30,7 +31,7 @@ public struct SyncDatabase { // MARK: - API - public func insertStatuses(_ statuses: [SyncStatus], completionHandler: (() -> ())? = nil) { + public func insertStatuses(_ statuses: [SyncStatus], completionHandler: VoidCompletionBlock? = nil) { syncStatusTable.insertStatuses(statuses, completionHandler: completionHandler) } @@ -42,11 +43,11 @@ public struct SyncDatabase { return syncStatusTable.selectPendingCount() } - public func resetSelectedForProcessing(_ articleIDs: [String], completionHandler: (() -> ())? = nil) { + public func resetSelectedForProcessing(_ articleIDs: [String], completionHandler: VoidCompletionBlock? = nil) { syncStatusTable.resetSelectedForProcessing(articleIDs, completionHandler: completionHandler) } - public func deleteSelectedForProcessing(_ articleIDs: [String], completionHandler: (() -> ())? = nil) { + public func deleteSelectedForProcessing(_ articleIDs: [String], completionHandler: VoidCompletionBlock? = nil) { syncStatusTable.deleteSelectedForProcessing(articleIDs, completionHandler: completionHandler) } diff --git a/Frameworks/SyncDatabase/SyncStatusTable.swift b/Frameworks/SyncDatabase/SyncStatusTable.swift index 23b55c2d5..55361205f 100644 --- a/Frameworks/SyncDatabase/SyncStatusTable.swift +++ b/Frameworks/SyncDatabase/SyncStatusTable.swift @@ -7,6 +7,7 @@ // import Foundation +import RSCore import Articles import RSDatabase @@ -48,36 +49,36 @@ struct SyncStatusTable: DatabaseTable { return count } - func resetSelectedForProcessing(_ articleIDs: [String], completionHandler: (() -> ())? = nil) { + func resetSelectedForProcessing(_ articleIDs: [String], completionHandler: VoidCompletionBlock? = nil) { queue.runInTransaction { database in let parameters = articleIDs.map { $0 as AnyObject } let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(articleIDs.count))! let updateSQL = "update syncStatus set selected = false where articleID in \(placeholders)" database.executeUpdate(updateSQL, withArgumentsIn: parameters) if let handler = completionHandler { - DispatchQueue.main.async(execute: handler) + callVoidCompletionBlock(handler) } } } - func deleteSelectedForProcessing(_ articleIDs: [String], completionHandler: (() -> ())? = nil) { + func deleteSelectedForProcessing(_ articleIDs: [String], completionHandler: VoidCompletionBlock? = nil) { queue.runInTransaction { database in let parameters = articleIDs.map { $0 as AnyObject } let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(articleIDs.count))! let deleteSQL = "delete from syncStatus where articleID in \(placeholders)" database.executeUpdate(deleteSQL, withArgumentsIn: parameters) if let handler = completionHandler { - DispatchQueue.main.async(execute: handler) + callVoidCompletionBlock(handler) } } } - func insertStatuses(_ statuses: [SyncStatus], completionHandler: (() -> ())? = nil) { + func insertStatuses(_ statuses: [SyncStatus], completionHandler: VoidCompletionBlock? = nil) { queue.runInTransaction { database in let statusArray = statuses.map { $0.databaseDictionary() } self.insertRows(statusArray, insertType: .orReplace, in: database) if let handler = completionHandler { - DispatchQueue.main.async(execute: handler) + callVoidCompletionBlock(handler) } } }