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))