From e2d8db6f26c1e984fb1ab4d6507e4facc16d3fad Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sun, 29 Mar 2020 17:53:11 -0500 Subject: [PATCH] Added feed rename sync to iCloud. --- .../CloudKit/CloudKitAccountDelegate.swift | 12 +++++++++-- .../CloudKit/CloudKitAccountZone.swift | 21 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Frameworks/Account/CloudKit/CloudKitAccountDelegate.swift b/Frameworks/Account/CloudKit/CloudKitAccountDelegate.swift index 1029c2539..45b49173b 100644 --- a/Frameworks/Account/CloudKit/CloudKitAccountDelegate.swift +++ b/Frameworks/Account/CloudKit/CloudKitAccountDelegate.swift @@ -178,8 +178,16 @@ final class CloudKitAccountDelegate: AccountDelegate { } func renameWebFeed(for account: Account, with feed: WebFeed, to name: String, completion: @escaping (Result) -> Void) { - feed.editedName = name - completion(.success(())) + let editedName = name.isEmpty ? nil : name + accountZone.renameWebFeed(feed, editedName: editedName) { result in + switch result { + case .success: + feed.editedName = name + completion(.success(())) + case .failure(let error): + completion(.failure(error)) + } + } } func removeWebFeed(for account: Account, with feed: WebFeed, from container: Container, completion: @escaping (Result) -> Void) { diff --git a/Frameworks/Account/CloudKit/CloudKitAccountZone.swift b/Frameworks/Account/CloudKit/CloudKitAccountZone.swift index 6fbff3139..70b1b9aac 100644 --- a/Frameworks/Account/CloudKit/CloudKitAccountZone.swift +++ b/Frameworks/Account/CloudKit/CloudKitAccountZone.swift @@ -55,6 +55,27 @@ final class CloudKitAccountZone: CloudKitZone { } } + func renameWebFeed(_ webFeed: WebFeed, editedName: String?, completion: @escaping (Result) -> Void) { + guard let externalID = webFeed.externalID else { + completion(.failure(CloudKitZoneError.invalidParameter)) + return + } + + let recordID = CKRecord.ID(recordName: externalID, zoneID: Self.zoneID) + let record = CKRecord(recordType: CloudKitWebFeed.recordType, recordID: recordID) + record[CloudKitWebFeed.Fields.editedName] = editedName + + save(record: record) { result in + switch result { + case .success: + completion(.success(())) + case .failure(let error): + completion(.failure(error)) + } + } + } + + /// Deletes a web feed from iCloud func removeWebFeed(_ webFeed: WebFeed, completion: @escaping (Result) -> Void) { guard let externalID = webFeed.externalID else { completion(.failure(CloudKitZoneError.invalidParameter))