Merge branch 'master' into extension-point

This commit is contained in:
Maurice Parker 2020-04-15 19:02:20 -05:00
commit c414d22666
3 changed files with 19 additions and 25 deletions

View File

@ -233,7 +233,7 @@ private extension CloudKitArticlesZone {
let encoder = JSONEncoder() let encoder = JSONEncoder()
var parsedAuthors = [String]() var parsedAuthors = [String]()
if let authors = article.authors { if let authors = article.authors, !authors.isEmpty {
for author in authors { for author in authors {
let parsedAuthor = ParsedAuthor(name: author.name, let parsedAuthor = ParsedAuthor(name: author.name,
url: author.url, url: author.url,
@ -243,9 +243,8 @@ private extension CloudKitArticlesZone {
parsedAuthors.append(encodedParsedAuthor) parsedAuthors.append(encodedParsedAuthor)
} }
} }
}
articleRecord[CloudKitArticle.Fields.parsedAuthors] = parsedAuthors articleRecord[CloudKitArticle.Fields.parsedAuthors] = parsedAuthors
}
records.append(articleRecord) records.append(articleRecord)
return records return records

View File

@ -474,6 +474,8 @@ extension CloudKitZone {
/// Fetch all the changes in the CKZone since the last time we checked /// Fetch all the changes in the CKZone since the last time we checked
func fetchChangesInZone(completion: @escaping (Result<Void, Error>) -> Void) { func fetchChangesInZone(completion: @escaping (Result<Void, Error>) -> Void) {
var savedChangeToken = changeToken
var changedRecords = [CKRecord]() var changedRecords = [CKRecord]()
var deletedRecordKeys = [CloudKitRecordKey]() var deletedRecordKeys = [CloudKitRecordKey]()
@ -482,12 +484,8 @@ extension CloudKitZone {
let op = CKFetchRecordZoneChangesOperation(recordZoneIDs: [Self.zoneID], configurationsByRecordZoneID: [Self.zoneID: zoneConfig]) let op = CKFetchRecordZoneChangesOperation(recordZoneIDs: [Self.zoneID], configurationsByRecordZoneID: [Self.zoneID: zoneConfig])
op.fetchAllChanges = true op.fetchAllChanges = true
op.recordZoneChangeTokensUpdatedBlock = { [weak self] zoneID, token, _ in op.recordZoneChangeTokensUpdatedBlock = { zoneID, token, _ in
guard let self = self else { return } savedChangeToken = token
DispatchQueue.main.async {
self.changeToken = token
}
} }
op.recordChangedBlock = { record in op.recordChangedBlock = { record in
@ -499,20 +497,9 @@ extension CloudKitZone {
deletedRecordKeys.append(recordKey) deletedRecordKeys.append(recordKey)
} }
op.recordZoneFetchCompletionBlock = { [weak self] zoneID ,token, _, _, error in op.recordZoneFetchCompletionBlock = { zoneID ,token, _, _, error in
guard let self = self else { return } if case .success = CloudKitZoneResult.resolve(error) {
savedChangeToken = token
switch CloudKitZoneResult.resolve(error) {
case .success:
DispatchQueue.main.async {
self.changeToken = token
}
case .retry(let timeToWait):
self.retryIfPossible(after: timeToWait) {
self.fetchChangesInZone(completion: completion)
}
default:
os_log(.error, log: self.log, "%@ zone fetch changes error: %@", zoneID.zoneName, error?.localizedDescription ?? "Unknown")
} }
} }
@ -522,7 +509,15 @@ extension CloudKitZone {
switch CloudKitZoneResult.resolve(error) { switch CloudKitZoneResult.resolve(error) {
case .success: case .success:
DispatchQueue.main.async { DispatchQueue.main.async {
self.delegate?.cloudKitDidModify(changed: changedRecords, deleted: deletedRecordKeys, completion: completion) self.delegate?.cloudKitDidModify(changed: changedRecords, deleted: deletedRecordKeys) { result in
switch result {
case .success:
self.changeToken = savedChangeToken
completion(.success(()))
case .failure(let error):
completion(.failure(error))
}
}
} }
case .zoneNotFound: case .zoneNotFound:
self.createZoneRecord() { result in self.createZoneRecord() { result in

View File

@ -230,7 +230,7 @@ private extension ArticleRenderer {
byline += name.htmlByAddingLink(url) byline += name.htmlByAddingLink(url)
} }
else if let name = author.name, let emailAddress = author.emailAddress { else if let name = author.name, let emailAddress = author.emailAddress {
byline += "\(name) &lt;\(emailAddress)&lg;" byline += "\(name) &lt;\(emailAddress)&gt;"
} }
else if let name = author.name { else if let name = author.name {
byline += name byline += name