Sync the homePageURL since we don't refigure it for all feeds

This commit is contained in:
Maurice Parker 2020-05-05 18:25:33 -05:00
parent 8c61a7a602
commit 97817cb13c
3 changed files with 29 additions and 15 deletions

View File

@ -254,7 +254,7 @@ final class CloudKitAccountDelegate: AccountDelegate {
func restoreWebFeed(for account: Account, feed: WebFeed, container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
refreshProgress.addToNumberOfTasksAndRemaining(2)
accountZone.createWebFeed(url: feed.url, name: feed.name, editedName: feed.editedName, container: container) { result in
accountZone.createWebFeed(url: feed.url, name: feed.name, editedName: feed.editedName, homePageURL: feed.homePageURL, container: container) { result in
self.refreshProgress.completeTask()
switch result {
case .success(let externalID):
@ -593,7 +593,7 @@ private extension CloudKitAccountDelegate {
return
}
self.accountZone.createWebFeed(url: urlString, name: metaData.name, editedName: editedName, container: container) { result in
self.accountZone.createWebFeed(url: urlString, name: metaData.name, editedName: editedName, homePageURL: metaData.homePageURL, container: container) { result in
self.refreshProgress.completeTask()
switch result {
@ -674,7 +674,11 @@ private extension CloudKitAccountDelegate {
case .success:
BatchUpdate.shared.end()
self.accountZone.createWebFeed(url: bestFeedSpecifier.urlString, name: parsedFeed.title, editedName: editedName, container: container) { result in
self.accountZone.createWebFeed(url: bestFeedSpecifier.urlString,
name: parsedFeed.title,
editedName: editedName,
homePageURL: parsedFeed.homePageURL,
container: container) { result in
self.refreshProgress.completeTask()
switch result {

View File

@ -30,6 +30,7 @@ final class CloudKitAccountZone: CloudKitZone {
static let url = "url"
static let name = "name"
static let editedName = "editedName"
static let homePageURL = "homePageURL"
static let containerExternalIDs = "containerExternalIDs"
}
}
@ -82,7 +83,7 @@ final class CloudKitAccountZone: CloudKitZone {
}
/// Persist a web feed record to iCloud and return the external key
func createWebFeed(url: String, name: String?, editedName: String?, container: Container, completion: @escaping (Result<String, Error>) -> Void) {
func createWebFeed(url: String, name: String?, editedName: String?, homePageURL: String?, container: Container, completion: @escaping (Result<String, Error>) -> Void) {
let recordID = CKRecord.ID(recordName: url.md5String, zoneID: Self.zoneID)
let record = CKRecord(recordType: CloudKitWebFeed.recordType, recordID: recordID)
record[CloudKitWebFeed.Fields.url] = url
@ -90,7 +91,10 @@ final class CloudKitAccountZone: CloudKitZone {
if let editedName = editedName {
record[CloudKitWebFeed.Fields.editedName] = editedName
}
if let homePageURL = homePageURL {
record[CloudKitWebFeed.Fields.homePageURL] = homePageURL
}
guard let containerExternalID = container.externalID else {
completion(.failure(CloudKitZoneError.invalidParameter))
return
@ -293,6 +297,9 @@ private extension CloudKitAccountZone {
if let editedName = feedSpecifier.title {
record[CloudKitWebFeed.Fields.editedName] = editedName
}
if let homePageURL = feedSpecifier.homePageURL {
record[CloudKitWebFeed.Fields.homePageURL] = homePageURL
}
record[CloudKitWebFeed.Fields.containerExternalIDs] = [containerExternalID]
return record
}

View File

@ -15,7 +15,7 @@ import Articles
class CloudKitAcountZoneDelegate: CloudKitZoneDelegate {
private typealias UnclaimedWebFeed = (url: URL, name: String?, editedName: String?, webFeedExternalID: String)
private typealias UnclaimedWebFeed = (url: URL, name: String?, editedName: String?, homePageURL: String?, webFeedExternalID: String)
private var unclaimedWebFeeds = [String: [UnclaimedWebFeed]]()
private var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "CloudKit")
@ -66,15 +66,16 @@ class CloudKitAcountZoneDelegate: CloudKitZoneDelegate {
let name = record[CloudKitAccountZone.CloudKitWebFeed.Fields.name] as? String
let editedName = record[CloudKitAccountZone.CloudKitWebFeed.Fields.editedName] as? String
let homePageURL = record[CloudKitAccountZone.CloudKitWebFeed.Fields.homePageURL] as? String
if let webFeed = account.existingWebFeed(withExternalID: record.externalID) {
updateWebFeed(webFeed, name: name, editedName: editedName, containerExternalIDs: containerExternalIDs)
updateWebFeed(webFeed, name: name, editedName: editedName, homePageURL: homePageURL, containerExternalIDs: containerExternalIDs)
} else {
for containerExternalID in containerExternalIDs {
if let container = account.existingContainer(withExternalID: containerExternalID) {
createWebFeedIfNecessary(url: url, name: name, editedName: editedName, webFeedExternalID: record.externalID, container: container)
createWebFeedIfNecessary(url: url, name: name, editedName: editedName, homePageURL: homePageURL, webFeedExternalID: record.externalID, container: container)
} else {
addUnclaimedWebFeed(url: url, name: name, editedName: editedName, webFeedExternalID: record.externalID, containerExternalID: containerExternalID)
addUnclaimedWebFeed(url: url, name: name, editedName: editedName, homePageURL: homePageURL, webFeedExternalID: record.externalID, containerExternalID: containerExternalID)
}
}
}
@ -107,6 +108,7 @@ class CloudKitAcountZoneDelegate: CloudKitZoneDelegate {
createWebFeedIfNecessary(url: unclaimedWebFeed.url,
name: unclaimedWebFeed.name,
editedName: unclaimedWebFeed.editedName,
homePageURL: unclaimedWebFeed.homePageURL,
webFeedExternalID: unclaimedWebFeed.webFeedExternalID,
container: folder)
}
@ -126,11 +128,12 @@ class CloudKitAcountZoneDelegate: CloudKitZoneDelegate {
private extension CloudKitAcountZoneDelegate {
func updateWebFeed(_ webFeed: WebFeed, name: String?, editedName: String?, containerExternalIDs: [String]) {
func updateWebFeed(_ webFeed: WebFeed, name: String?, editedName: String?, homePageURL: String?, containerExternalIDs: [String]) {
guard let account = account else { return }
webFeed.name = name
webFeed.editedName = editedName
webFeed.homePageURL = homePageURL
let existingContainers = account.existingContainers(withWebFeed: webFeed)
let existingContainerExternalIds = existingContainers.compactMap { $0.externalID }
@ -151,26 +154,26 @@ private extension CloudKitAcountZoneDelegate {
}
}
func createWebFeedIfNecessary(url: URL, name: String?, editedName: String?, webFeedExternalID: String, container: Container) {
func createWebFeedIfNecessary(url: URL, name: String?, editedName: String?, homePageURL: String?, webFeedExternalID: String, container: Container) {
guard let account = account else { return }
if account.existingWebFeed(withExternalID: webFeedExternalID) != nil {
return
}
let webFeed = account.createWebFeed(with: name, url: url.absoluteString, webFeedID: url.absoluteString, homePageURL: nil)
let webFeed = account.createWebFeed(with: name, url: url.absoluteString, webFeedID: url.absoluteString, homePageURL: homePageURL)
webFeed.editedName = editedName
webFeed.externalID = webFeedExternalID
container.addWebFeed(webFeed)
}
func addUnclaimedWebFeed(url: URL, name: String?, editedName: String?, webFeedExternalID: String, containerExternalID: String) {
func addUnclaimedWebFeed(url: URL, name: String?, editedName: String?, homePageURL: String?, webFeedExternalID: String, containerExternalID: String) {
if var unclaimedWebFeeds = self.unclaimedWebFeeds[containerExternalID] {
unclaimedWebFeeds.append(UnclaimedWebFeed(url: url, name: name, editedName: editedName, webFeedExternalID: webFeedExternalID))
unclaimedWebFeeds.append(UnclaimedWebFeed(url: url, name: name, editedName: editedName, homePageURL: homePageURL, webFeedExternalID: webFeedExternalID))
self.unclaimedWebFeeds[containerExternalID] = unclaimedWebFeeds
} else {
var unclaimedWebFeeds = [UnclaimedWebFeed]()
unclaimedWebFeeds.append(UnclaimedWebFeed(url: url, name: name, editedName: editedName, webFeedExternalID: webFeedExternalID))
unclaimedWebFeeds.append(UnclaimedWebFeed(url: url, name: name, editedName: editedName, homePageURL: homePageURL, webFeedExternalID: webFeedExternalID))
self.unclaimedWebFeeds[containerExternalID] = unclaimedWebFeeds
}
}