Added feed rename sync to iCloud.

This commit is contained in:
Maurice Parker 2020-03-29 17:53:11 -05:00
parent 4f425c9c86
commit e2d8db6f26
2 changed files with 31 additions and 2 deletions

View File

@ -178,8 +178,16 @@ final class CloudKitAccountDelegate: AccountDelegate {
} }
func renameWebFeed(for account: Account, with feed: WebFeed, to name: String, completion: @escaping (Result<Void, Error>) -> Void) { func renameWebFeed(for account: Account, with feed: WebFeed, to name: String, completion: @escaping (Result<Void, Error>) -> Void) {
feed.editedName = name let editedName = name.isEmpty ? nil : name
completion(.success(())) 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, Error>) -> Void) { func removeWebFeed(for account: Account, with feed: WebFeed, from container: Container, completion: @escaping (Result<Void, Error>) -> Void) {

View File

@ -55,6 +55,27 @@ final class CloudKitAccountZone: CloudKitZone {
} }
} }
func renameWebFeed(_ webFeed: WebFeed, editedName: String?, completion: @escaping (Result<Void, Error>) -> 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, Error>) -> Void) { func removeWebFeed(_ webFeed: WebFeed, completion: @escaping (Result<Void, Error>) -> Void) {
guard let externalID = webFeed.externalID else { guard let externalID = webFeed.externalID else {
completion(.failure(CloudKitZoneError.invalidParameter)) completion(.failure(CloudKitZoneError.invalidParameter))