Fix missing callback that was hanging new accounts.

This commit is contained in:
Maurice Parker 2020-04-13 04:26:28 -05:00
parent 6bd2c0dc06
commit 6f255e63b3
1 changed files with 22 additions and 14 deletions

View File

@ -27,6 +27,17 @@ class CloudKitAcountZoneDelegate: CloudKitZoneDelegate {
}
func cloudKitDidModify(changed: [CKRecord], deleted: [CloudKitRecordKey], completion: @escaping (Result<Void, Error>) -> Void) {
for deletedRecordKey in deleted {
switch deletedRecordKey.recordType {
case CloudKitAccountZone.CloudKitWebFeed.recordType:
removeWebFeed(deletedRecordKey.recordID.externalID)
case CloudKitAccountZone.CloudKitContainer.recordType:
removeContainer(deletedRecordKey.recordID.externalID)
default:
assertionFailure("Unknown record type: \(deletedRecordKey.recordType)")
}
}
let group = DispatchGroup()
for changedRecord in changed {
@ -46,17 +57,6 @@ class CloudKitAcountZoneDelegate: CloudKitZoneDelegate {
}
}
for deletedRecordKey in deleted {
switch deletedRecordKey.recordType {
case CloudKitAccountZone.CloudKitWebFeed.recordType:
removeWebFeed(deletedRecordKey.recordID.externalID)
case CloudKitAccountZone.CloudKitContainer.recordType:
removeContainer(deletedRecordKey.recordID.externalID)
default:
assertionFailure("Unknown record type: \(deletedRecordKey.recordType)")
}
}
group.notify(queue: DispatchQueue.main) {
completion(.success(()))
}
@ -66,7 +66,10 @@ class CloudKitAcountZoneDelegate: CloudKitZoneDelegate {
guard let account = account,
let urlString = record[CloudKitAccountZone.CloudKitWebFeed.Fields.url] as? String,
let containerExternalIDs = record[CloudKitAccountZone.CloudKitWebFeed.Fields.containerExternalIDs] as? [String],
let url = URL(string: urlString) else { return }
let url = URL(string: urlString) else {
completion()
return
}
let editedName = record[CloudKitAccountZone.CloudKitWebFeed.Fields.editedName] as? String
@ -108,7 +111,10 @@ class CloudKitAcountZoneDelegate: CloudKitZoneDelegate {
guard let account = account,
let name = record[CloudKitAccountZone.CloudKitContainer.Fields.name] as? String,
let isAccount = record[CloudKitAccountZone.CloudKitContainer.Fields.isAccount] as? String,
isAccount != "1" else { return }
isAccount != "1" else {
completion()
return
}
var folder = account.existingFolder(withExternalID: record.externalID)
folder?.name = name
@ -194,6 +200,8 @@ private extension CloudKitAcountZoneDelegate {
account.update(webFeed, with: parsedFeed, { _ in
completion(webFeed)
})
} else {
completion(webFeed)
}
}