Delete all articles when the feed is deleted.
This commit is contained in:
parent
71788d8f69
commit
cf2bed1e69
|
@ -243,8 +243,12 @@ final class CloudKitAccountDelegate: AccountDelegate {
|
|||
}
|
||||
|
||||
func removeWebFeed(for account: Account, with feed: WebFeed, from container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
refreshProgress.addToNumberOfTasksAndRemaining(1)
|
||||
refreshProgress.addToNumberOfTasksAndRemaining(2)
|
||||
accountZone.removeWebFeed(feed, from: container) { result in
|
||||
self.refreshProgress.completeTask()
|
||||
switch result {
|
||||
case .success:
|
||||
self.articlesZone.deleteArticles(feed.url) { result in
|
||||
self.refreshProgress.completeTask()
|
||||
switch result {
|
||||
case .success:
|
||||
|
@ -255,6 +259,11 @@ final class CloudKitAccountDelegate: AccountDelegate {
|
|||
completion(.failure(error))
|
||||
}
|
||||
}
|
||||
case .failure(let error):
|
||||
self.processAccountError(account, error)
|
||||
completion(.failure(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func moveWebFeed(for account: Account, with feed: WebFeed, from fromContainer: Container, to toContainer: Container, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
|
|
|
@ -88,6 +88,21 @@ final class CloudKitArticlesZone: CloudKitZone {
|
|||
saveIfNew(records, completion: completion)
|
||||
}
|
||||
|
||||
func deleteArticles(_ webFeedURL: String, completion: @escaping ((Result<Void, Error>) -> Void)) {
|
||||
let predicate = NSPredicate(format: "webFeedURL = %@", webFeedURL)
|
||||
let ckQuery = CKQuery(recordType: CloudKitArticle.recordType, predicate: predicate)
|
||||
|
||||
query(ckQuery) { result in
|
||||
switch result {
|
||||
case .success(let records):
|
||||
let recordIDs = records.map { $0.recordID }
|
||||
self.delete(recordIDs: recordIDs, completion: completion)
|
||||
case .failure(let error):
|
||||
completion(.failure(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func deleteArticles(_ articles: Set<Article>, completion: @escaping ((Result<Void, Error>) -> Void)) {
|
||||
guard !articles.isEmpty else {
|
||||
completion(.success(()))
|
||||
|
@ -208,5 +223,4 @@ private extension CloudKitArticlesZone {
|
|||
return records
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -122,51 +122,6 @@ extension CloudKitZone {
|
|||
}
|
||||
}
|
||||
|
||||
/// Checks to see if the record described in the query exists by retrieving only the testField parameter field.
|
||||
func exists(_ query: CKQuery, completion: @escaping (Result<Bool, Error>) -> Void) {
|
||||
var recordFound = false
|
||||
let op = CKQueryOperation(query: query)
|
||||
op.desiredKeys = ["creationDate"]
|
||||
|
||||
op.recordFetchedBlock = { record in
|
||||
recordFound = true
|
||||
}
|
||||
|
||||
op.queryCompletionBlock = { [weak self] (_, error) in
|
||||
switch CloudKitZoneResult.resolve(error) {
|
||||
case .success:
|
||||
DispatchQueue.main.async {
|
||||
completion(.success(recordFound))
|
||||
}
|
||||
case .zoneNotFound:
|
||||
self?.createZoneRecord() { result in
|
||||
switch result {
|
||||
case .success:
|
||||
self?.exists(query, completion: completion)
|
||||
case .failure(let error):
|
||||
DispatchQueue.main.async {
|
||||
completion(.failure(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
case .retry(let timeToWait):
|
||||
self?.retryIfPossible(after: timeToWait) {
|
||||
self?.exists(query, completion: completion)
|
||||
}
|
||||
case .userDeletedZone:
|
||||
DispatchQueue.main.async {
|
||||
completion(.failure(CloudKitZoneError.userDeletedZone))
|
||||
}
|
||||
default:
|
||||
DispatchQueue.main.async {
|
||||
completion(.failure(CloudKitError(error!)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
database?.add(op)
|
||||
}
|
||||
|
||||
/// Issue a CKQuery and return the resulting CKRecords.s
|
||||
func query(_ query: CKQuery, completion: @escaping (Result<[CKRecord], Error>) -> Void) {
|
||||
guard let database = database else {
|
||||
|
|
Loading…
Reference in New Issue