Use the new VoidCompletionBlock instead of (() -> ()).
This commit is contained in:
parent
cd019d6d89
commit
45804a3d1a
|
@ -732,7 +732,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||||
return updatedArticles
|
return updatedArticles
|
||||||
}
|
}
|
||||||
|
|
||||||
func ensureStatuses(_ articleIDs: Set<String>, _ defaultRead: Bool, _ statusKey: ArticleStatus.Key, _ flag: Bool, completionHandler: (() -> ())? = nil) {
|
func ensureStatuses(_ articleIDs: Set<String>, _ defaultRead: Bool, _ statusKey: ArticleStatus.Key, _ flag: Bool, completionHandler: VoidCompletionBlock? = nil) {
|
||||||
guard !articleIDs.isEmpty else {
|
guard !articleIDs.isEmpty else {
|
||||||
completionHandler?()
|
completionHandler?()
|
||||||
return
|
return
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import RSCore
|
||||||
import RSDatabase
|
import RSDatabase
|
||||||
import RSParser
|
import RSParser
|
||||||
import Articles
|
import Articles
|
||||||
|
@ -147,7 +148,7 @@ public final class ArticlesDatabase {
|
||||||
articlesTable.update(webFeedIDsAndItems, defaultRead, completion)
|
articlesTable.update(webFeedIDsAndItems, defaultRead, completion)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func ensureStatuses(_ articleIDs: Set<String>, _ defaultRead: Bool, _ statusKey: ArticleStatus.Key, _ flag: Bool, completionHandler: (() -> ())? = nil) {
|
public func ensureStatuses(_ articleIDs: Set<String>, _ defaultRead: Bool, _ statusKey: ArticleStatus.Key, _ flag: Bool, completionHandler: VoidCompletionBlock? = nil) {
|
||||||
articlesTable.ensureStatuses(articleIDs, defaultRead, statusKey, flag, completionHandler: completionHandler)
|
articlesTable.ensureStatuses(articleIDs, defaultRead, statusKey, flag, completionHandler: completionHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -298,13 +298,13 @@ final class ArticlesTable: DatabaseTable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ensureStatuses(_ articleIDs: Set<String>, _ defaultRead: Bool, _ statusKey: ArticleStatus.Key, _ flag: Bool, completionHandler: (() -> ())? = nil) {
|
func ensureStatuses(_ articleIDs: Set<String>, _ defaultRead: Bool, _ statusKey: ArticleStatus.Key, _ flag: Bool, completionHandler: VoidCompletionBlock? = nil) {
|
||||||
queue.runInTransaction { (database) in
|
queue.runInTransaction { (database) in
|
||||||
let statusesDictionary = self.statusesTable.ensureStatusesForArticleIDs(articleIDs, defaultRead, database)
|
let statusesDictionary = self.statusesTable.ensureStatusesForArticleIDs(articleIDs, defaultRead, database)
|
||||||
let statuses = Set(statusesDictionary.values)
|
let statuses = Set(statusesDictionary.values)
|
||||||
self.statusesTable.mark(statuses, statusKey, flag, database)
|
self.statusesTable.mark(statuses, statusKey, flag, database)
|
||||||
if let handler = completionHandler {
|
if let handler = completionHandler {
|
||||||
DispatchQueue.main.async(execute: handler)
|
callVoidCompletionBlock(handler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import RSCore
|
||||||
import RSDatabase
|
import RSDatabase
|
||||||
|
|
||||||
public struct SyncDatabase {
|
public struct SyncDatabase {
|
||||||
|
@ -30,7 +31,7 @@ public struct SyncDatabase {
|
||||||
|
|
||||||
// MARK: - API
|
// MARK: - API
|
||||||
|
|
||||||
public func insertStatuses(_ statuses: [SyncStatus], completionHandler: (() -> ())? = nil) {
|
public func insertStatuses(_ statuses: [SyncStatus], completionHandler: VoidCompletionBlock? = nil) {
|
||||||
syncStatusTable.insertStatuses(statuses, completionHandler: completionHandler)
|
syncStatusTable.insertStatuses(statuses, completionHandler: completionHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,11 +43,11 @@ public struct SyncDatabase {
|
||||||
return syncStatusTable.selectPendingCount()
|
return syncStatusTable.selectPendingCount()
|
||||||
}
|
}
|
||||||
|
|
||||||
public func resetSelectedForProcessing(_ articleIDs: [String], completionHandler: (() -> ())? = nil) {
|
public func resetSelectedForProcessing(_ articleIDs: [String], completionHandler: VoidCompletionBlock? = nil) {
|
||||||
syncStatusTable.resetSelectedForProcessing(articleIDs, completionHandler: completionHandler)
|
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)
|
syncStatusTable.deleteSelectedForProcessing(articleIDs, completionHandler: completionHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import RSCore
|
||||||
import Articles
|
import Articles
|
||||||
import RSDatabase
|
import RSDatabase
|
||||||
|
|
||||||
|
@ -48,36 +49,36 @@ struct SyncStatusTable: DatabaseTable {
|
||||||
return count
|
return count
|
||||||
}
|
}
|
||||||
|
|
||||||
func resetSelectedForProcessing(_ articleIDs: [String], completionHandler: (() -> ())? = nil) {
|
func resetSelectedForProcessing(_ articleIDs: [String], completionHandler: VoidCompletionBlock? = nil) {
|
||||||
queue.runInTransaction { database in
|
queue.runInTransaction { database in
|
||||||
let parameters = articleIDs.map { $0 as AnyObject }
|
let parameters = articleIDs.map { $0 as AnyObject }
|
||||||
let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(articleIDs.count))!
|
let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(articleIDs.count))!
|
||||||
let updateSQL = "update syncStatus set selected = false where articleID in \(placeholders)"
|
let updateSQL = "update syncStatus set selected = false where articleID in \(placeholders)"
|
||||||
database.executeUpdate(updateSQL, withArgumentsIn: parameters)
|
database.executeUpdate(updateSQL, withArgumentsIn: parameters)
|
||||||
if let handler = completionHandler {
|
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
|
queue.runInTransaction { database in
|
||||||
let parameters = articleIDs.map { $0 as AnyObject }
|
let parameters = articleIDs.map { $0 as AnyObject }
|
||||||
let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(articleIDs.count))!
|
let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(articleIDs.count))!
|
||||||
let deleteSQL = "delete from syncStatus where articleID in \(placeholders)"
|
let deleteSQL = "delete from syncStatus where articleID in \(placeholders)"
|
||||||
database.executeUpdate(deleteSQL, withArgumentsIn: parameters)
|
database.executeUpdate(deleteSQL, withArgumentsIn: parameters)
|
||||||
if let handler = completionHandler {
|
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
|
queue.runInTransaction { database in
|
||||||
let statusArray = statuses.map { $0.databaseDictionary() }
|
let statusArray = statuses.map { $0.databaseDictionary() }
|
||||||
self.insertRows(statusArray, insertType: .orReplace, in: database)
|
self.insertRows(statusArray, insertType: .orReplace, in: database)
|
||||||
if let handler = completionHandler {
|
if let handler = completionHandler {
|
||||||
DispatchQueue.main.async(execute: handler)
|
callVoidCompletionBlock(handler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue