Sync the homePageURL since we don't refigure it for all feeds
This commit is contained in:
parent
8c61a7a602
commit
97817cb13c
@ -254,7 +254,7 @@ final class CloudKitAccountDelegate: AccountDelegate {
|
|||||||
|
|
||||||
func restoreWebFeed(for account: Account, feed: WebFeed, container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
|
func restoreWebFeed(for account: Account, feed: WebFeed, container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||||
refreshProgress.addToNumberOfTasksAndRemaining(2)
|
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()
|
self.refreshProgress.completeTask()
|
||||||
switch result {
|
switch result {
|
||||||
case .success(let externalID):
|
case .success(let externalID):
|
||||||
@ -593,7 +593,7 @@ private extension CloudKitAccountDelegate {
|
|||||||
return
|
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()
|
self.refreshProgress.completeTask()
|
||||||
switch result {
|
switch result {
|
||||||
@ -674,7 +674,11 @@ private extension CloudKitAccountDelegate {
|
|||||||
case .success:
|
case .success:
|
||||||
BatchUpdate.shared.end()
|
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()
|
self.refreshProgress.completeTask()
|
||||||
switch result {
|
switch result {
|
||||||
|
@ -30,6 +30,7 @@ final class CloudKitAccountZone: CloudKitZone {
|
|||||||
static let url = "url"
|
static let url = "url"
|
||||||
static let name = "name"
|
static let name = "name"
|
||||||
static let editedName = "editedName"
|
static let editedName = "editedName"
|
||||||
|
static let homePageURL = "homePageURL"
|
||||||
static let containerExternalIDs = "containerExternalIDs"
|
static let containerExternalIDs = "containerExternalIDs"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,7 +83,7 @@ final class CloudKitAccountZone: CloudKitZone {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Persist a web feed record to iCloud and return the external key
|
/// 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 recordID = CKRecord.ID(recordName: url.md5String, zoneID: Self.zoneID)
|
||||||
let record = CKRecord(recordType: CloudKitWebFeed.recordType, recordID: recordID)
|
let record = CKRecord(recordType: CloudKitWebFeed.recordType, recordID: recordID)
|
||||||
record[CloudKitWebFeed.Fields.url] = url
|
record[CloudKitWebFeed.Fields.url] = url
|
||||||
@ -90,6 +91,9 @@ final class CloudKitAccountZone: CloudKitZone {
|
|||||||
if let editedName = editedName {
|
if let editedName = editedName {
|
||||||
record[CloudKitWebFeed.Fields.editedName] = editedName
|
record[CloudKitWebFeed.Fields.editedName] = editedName
|
||||||
}
|
}
|
||||||
|
if let homePageURL = homePageURL {
|
||||||
|
record[CloudKitWebFeed.Fields.homePageURL] = homePageURL
|
||||||
|
}
|
||||||
|
|
||||||
guard let containerExternalID = container.externalID else {
|
guard let containerExternalID = container.externalID else {
|
||||||
completion(.failure(CloudKitZoneError.invalidParameter))
|
completion(.failure(CloudKitZoneError.invalidParameter))
|
||||||
@ -293,6 +297,9 @@ private extension CloudKitAccountZone {
|
|||||||
if let editedName = feedSpecifier.title {
|
if let editedName = feedSpecifier.title {
|
||||||
record[CloudKitWebFeed.Fields.editedName] = editedName
|
record[CloudKitWebFeed.Fields.editedName] = editedName
|
||||||
}
|
}
|
||||||
|
if let homePageURL = feedSpecifier.homePageURL {
|
||||||
|
record[CloudKitWebFeed.Fields.homePageURL] = homePageURL
|
||||||
|
}
|
||||||
record[CloudKitWebFeed.Fields.containerExternalIDs] = [containerExternalID]
|
record[CloudKitWebFeed.Fields.containerExternalIDs] = [containerExternalID]
|
||||||
return record
|
return record
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ import Articles
|
|||||||
|
|
||||||
class CloudKitAcountZoneDelegate: CloudKitZoneDelegate {
|
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 unclaimedWebFeeds = [String: [UnclaimedWebFeed]]()
|
||||||
|
|
||||||
private var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "CloudKit")
|
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 name = record[CloudKitAccountZone.CloudKitWebFeed.Fields.name] as? String
|
||||||
let editedName = record[CloudKitAccountZone.CloudKitWebFeed.Fields.editedName] 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) {
|
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 {
|
} else {
|
||||||
for containerExternalID in containerExternalIDs {
|
for containerExternalID in containerExternalIDs {
|
||||||
if let container = account.existingContainer(withExternalID: containerExternalID) {
|
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 {
|
} 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,
|
createWebFeedIfNecessary(url: unclaimedWebFeed.url,
|
||||||
name: unclaimedWebFeed.name,
|
name: unclaimedWebFeed.name,
|
||||||
editedName: unclaimedWebFeed.editedName,
|
editedName: unclaimedWebFeed.editedName,
|
||||||
|
homePageURL: unclaimedWebFeed.homePageURL,
|
||||||
webFeedExternalID: unclaimedWebFeed.webFeedExternalID,
|
webFeedExternalID: unclaimedWebFeed.webFeedExternalID,
|
||||||
container: folder)
|
container: folder)
|
||||||
}
|
}
|
||||||
@ -126,11 +128,12 @@ class CloudKitAcountZoneDelegate: CloudKitZoneDelegate {
|
|||||||
|
|
||||||
private extension CloudKitAcountZoneDelegate {
|
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 }
|
guard let account = account else { return }
|
||||||
|
|
||||||
webFeed.name = name
|
webFeed.name = name
|
||||||
webFeed.editedName = editedName
|
webFeed.editedName = editedName
|
||||||
|
webFeed.homePageURL = homePageURL
|
||||||
|
|
||||||
let existingContainers = account.existingContainers(withWebFeed: webFeed)
|
let existingContainers = account.existingContainers(withWebFeed: webFeed)
|
||||||
let existingContainerExternalIds = existingContainers.compactMap { $0.externalID }
|
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 }
|
guard let account = account else { return }
|
||||||
|
|
||||||
if account.existingWebFeed(withExternalID: webFeedExternalID) != nil {
|
if account.existingWebFeed(withExternalID: webFeedExternalID) != nil {
|
||||||
return
|
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.editedName = editedName
|
||||||
webFeed.externalID = webFeedExternalID
|
webFeed.externalID = webFeedExternalID
|
||||||
container.addWebFeed(webFeed)
|
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] {
|
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
|
self.unclaimedWebFeeds[containerExternalID] = unclaimedWebFeeds
|
||||||
} else {
|
} else {
|
||||||
var unclaimedWebFeeds = [UnclaimedWebFeed]()
|
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
|
self.unclaimedWebFeeds[containerExternalID] = unclaimedWebFeeds
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user