From 8ff0f23a550e898361da5935376d4884ff8fbea5 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Tue, 14 Apr 2020 08:05:16 -0500 Subject: [PATCH 1/3] Fix bug triggered by having no authors associated with a starred article. --- Frameworks/Account/CloudKit/CloudKitArticlesZone.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Frameworks/Account/CloudKit/CloudKitArticlesZone.swift b/Frameworks/Account/CloudKit/CloudKitArticlesZone.swift index f78d1218d..ae1ecab1d 100644 --- a/Frameworks/Account/CloudKit/CloudKitArticlesZone.swift +++ b/Frameworks/Account/CloudKit/CloudKitArticlesZone.swift @@ -233,7 +233,7 @@ private extension CloudKitArticlesZone { let encoder = JSONEncoder() var parsedAuthors = [String]() - if let authors = article.authors { + if let authors = article.authors, !authors.isEmpty { for author in authors { let parsedAuthor = ParsedAuthor(name: author.name, url: author.url, @@ -243,10 +243,9 @@ private extension CloudKitArticlesZone { parsedAuthors.append(encodedParsedAuthor) } } + articleRecord[CloudKitArticle.Fields.parsedAuthors] = parsedAuthors } - articleRecord[CloudKitArticle.Fields.parsedAuthors] = parsedAuthors - records.append(articleRecord) return records } From 8bb249b1addb00e8b776c77976c1732d538a49ec Mon Sep 17 00:00:00 2001 From: Nate Weaver Date: Wed, 15 Apr 2020 16:39:58 -0500 Subject: [PATCH 2/3] Fix typo --- Shared/Article Rendering/ArticleRenderer.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Shared/Article Rendering/ArticleRenderer.swift b/Shared/Article Rendering/ArticleRenderer.swift index 0be3508d3..09c73889d 100644 --- a/Shared/Article Rendering/ArticleRenderer.swift +++ b/Shared/Article Rendering/ArticleRenderer.swift @@ -230,7 +230,7 @@ private extension ArticleRenderer { byline += name.htmlByAddingLink(url) } else if let name = author.name, let emailAddress = author.emailAddress { - byline += "\(name) <\(emailAddress)≶" + byline += "\(name) <\(emailAddress)>" } else if let name = author.name { byline += name From b66d0ef25015bf063806b341fcf4a8051df78e0d Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Wed, 15 Apr 2020 18:30:39 -0500 Subject: [PATCH 3/3] Change how we save the CloudKit token so that is won't save if the app is quit before processing its records --- .../Account/CloudKit/CloudKitZone.swift | 37 ++++++++----------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/Frameworks/Account/CloudKit/CloudKitZone.swift b/Frameworks/Account/CloudKit/CloudKitZone.swift index c87a676ac..3bd02c1ee 100644 --- a/Frameworks/Account/CloudKit/CloudKitZone.swift +++ b/Frameworks/Account/CloudKit/CloudKitZone.swift @@ -474,6 +474,8 @@ extension CloudKitZone { /// Fetch all the changes in the CKZone since the last time we checked func fetchChangesInZone(completion: @escaping (Result) -> Void) { + var savedChangeToken = changeToken + var changedRecords = [CKRecord]() var deletedRecordKeys = [CloudKitRecordKey]() @@ -482,12 +484,8 @@ extension CloudKitZone { let op = CKFetchRecordZoneChangesOperation(recordZoneIDs: [Self.zoneID], configurationsByRecordZoneID: [Self.zoneID: zoneConfig]) op.fetchAllChanges = true - op.recordZoneChangeTokensUpdatedBlock = { [weak self] zoneID, token, _ in - guard let self = self else { return } - - DispatchQueue.main.async { - self.changeToken = token - } + op.recordZoneChangeTokensUpdatedBlock = { zoneID, token, _ in + savedChangeToken = token } op.recordChangedBlock = { record in @@ -499,20 +497,9 @@ extension CloudKitZone { deletedRecordKeys.append(recordKey) } - op.recordZoneFetchCompletionBlock = { [weak self] zoneID ,token, _, _, error in - guard let self = self else { return } - - 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") + op.recordZoneFetchCompletionBlock = { zoneID ,token, _, _, error in + if case .success = CloudKitZoneResult.resolve(error) { + savedChangeToken = token } } @@ -522,7 +509,15 @@ extension CloudKitZone { switch CloudKitZoneResult.resolve(error) { case .success: 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: self.createZoneRecord() { result in