Stub out subscription delete

This commit is contained in:
Maurice Parker 2020-04-04 05:02:33 -05:00
parent cceec096a9
commit adefcc7c3f
3 changed files with 42 additions and 16 deletions

View File

@ -30,9 +30,10 @@ final class CloudKitAccountDelegate: AccountDelegate {
return CKContainer(identifier: "iCloud.\(orgID).NetNewsWire")
}()
private lazy var zones: [CloudKitZone] = [accountZone, articlesZone]
private lazy var zones: [CloudKitZone] = [accountZone, articlesZone, publicZone]
private let accountZone: CloudKitAccountZone
private let articlesZone: CloudKitArticlesZone
private let publicZone: CloudKitPublicZone
private let refresher = LocalAccountRefresher()
@ -48,6 +49,7 @@ final class CloudKitAccountDelegate: AccountDelegate {
init(dataFolder: String) {
accountZone = CloudKitAccountZone(container: container)
articlesZone = CloudKitArticlesZone(container: container)
publicZone = CloudKitPublicZone(container: container)
let databaseFilePath = (dataFolder as NSString).appendingPathComponent("Sync.sqlite3")
database = SyncDatabase(databaseFilePath: databaseFilePath)
@ -259,9 +261,13 @@ final class CloudKitAccountDelegate: AccountDelegate {
accountZone.removeWebFeed(feed, from: container) { result in
self.refreshProgress.completeTask()
switch result {
case .success:
case .success(let deleted):
container.removeWebFeed(feed)
if deleted {
self.publicZone.removeSubscription(feed, completion: completion)
} else {
completion(.success(()))
}
case .failure(let error):
completion(.failure(error))
}

View File

@ -125,8 +125,8 @@ final class CloudKitAccountZone: CloudKitZone {
}
}
/// Deletes a web feed from iCloud
func removeWebFeed(_ webFeed: WebFeed, from: Container, completion: @escaping (Result<Void, Error>) -> Void) {
/// Removes a web feed from a container and optionally deletes it, calling the completion with true if deleted
func removeWebFeed(_ webFeed: WebFeed, from: Container, completion: @escaping (Result<Bool, Error>) -> Void) {
guard let fromContainerExternalID = from.externalID else {
completion(.failure(CloudKitZoneError.invalidParameter))
return
@ -135,16 +135,36 @@ final class CloudKitAccountZone: CloudKitZone {
fetch(externalID: webFeed.externalID) { result in
switch result {
case .success(let record):
if let containerExternalIDs = record[CloudKitWebFeed.Fields.containerExternalIDs] as? [String] {
var containerExternalIDSet = Set(containerExternalIDs)
containerExternalIDSet.remove(fromContainerExternalID)
if containerExternalIDSet.isEmpty {
self.delete(externalID: webFeed.externalID , completion: completion)
self.delete(externalID: webFeed.externalID) { result in
switch result {
case .success:
completion(.success(true))
case .failure(let error):
completion(.failure(error))
}
}
} else {
record[CloudKitWebFeed.Fields.containerExternalIDs] = Array(containerExternalIDSet)
self.save(record, completion: completion)
self.save(record) { result in
switch result {
case .success:
completion(.success(false))
case .failure(let error):
completion(.failure(error))
}
}
}
}
case .failure(let error):
completion(.failure(error))
}

View File

@ -31,14 +31,6 @@ final class CloudKitPublicZone: CloudKitZone {
}
}
struct CloudKitWebFeedCheck {
static let recordType = "UserSubscription"
struct Fields {
static let webFeed = "webFeed"
static let subscriptionID = "oldestPossibleCheckTime"
}
}
struct CloudKitUserSubscription {
static let recordType = "UserSubscription"
struct Fields {
@ -48,11 +40,19 @@ final class CloudKitPublicZone: CloudKitZone {
}
}
init(container: CKContainer) {
self.container = container
self.database = container.publicCloudDatabase
}
func subscribe() {}
func receiveRemoteNotification(userInfo: [AnyHashable : Any], completion: @escaping () -> Void) {
}
func removeSubscription(_ webFeed: WebFeed, completion: @escaping (Result<Void, Error>) -> Void) {
}
}