Retain existing feeds for folders that haven't been created yet. Fixes #3047
This commit is contained in:
parent
7e820c58e5
commit
a03430a790
|
@ -16,8 +16,9 @@ import Articles
|
||||||
class CloudKitAcountZoneDelegate: CloudKitZoneDelegate {
|
class CloudKitAcountZoneDelegate: CloudKitZoneDelegate {
|
||||||
|
|
||||||
private typealias UnclaimedWebFeed = (url: URL, name: String?, editedName: String?, homePageURL: String?, webFeedExternalID: String)
|
private typealias UnclaimedWebFeed = (url: URL, name: String?, editedName: String?, homePageURL: String?, webFeedExternalID: String)
|
||||||
private var unclaimedWebFeeds = [String: [UnclaimedWebFeed]]()
|
private var newUnclaimedWebFeeds = [String: [UnclaimedWebFeed]]()
|
||||||
|
private var existingUnclaimedWebFeeds = [String: [WebFeed]]()
|
||||||
|
|
||||||
private var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "CloudKit")
|
private var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "CloudKit")
|
||||||
|
|
||||||
weak var account: Account?
|
weak var account: Account?
|
||||||
|
@ -75,7 +76,7 @@ class CloudKitAcountZoneDelegate: CloudKitZoneDelegate {
|
||||||
if let container = account.existingContainer(withExternalID: containerExternalID) {
|
if let container = account.existingContainer(withExternalID: containerExternalID) {
|
||||||
createWebFeedIfNecessary(url: url, name: name, editedName: editedName, homePageURL: homePageURL, 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, homePageURL: homePageURL, webFeedExternalID: record.externalID, containerExternalID: containerExternalID)
|
addNewUnclaimedWebFeed(url: url, name: name, editedName: editedName, homePageURL: homePageURL, webFeedExternalID: record.externalID, containerExternalID: containerExternalID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,19 +107,27 @@ class CloudKitAcountZoneDelegate: CloudKitZoneDelegate {
|
||||||
folder?.externalID = record.externalID
|
folder?.externalID = record.externalID
|
||||||
}
|
}
|
||||||
|
|
||||||
if let folder = folder, let containerExternalID = folder.externalID, let unclaimedWebFeeds = unclaimedWebFeeds[containerExternalID] {
|
guard let folder = folder, let containerExternalID = folder.externalID else { return }
|
||||||
for unclaimedWebFeed in unclaimedWebFeeds {
|
|
||||||
createWebFeedIfNecessary(url: unclaimedWebFeed.url,
|
if let newUnclaimedWebFeeds = newUnclaimedWebFeeds[containerExternalID] {
|
||||||
name: unclaimedWebFeed.name,
|
for newUnclaimedWebFeed in newUnclaimedWebFeeds {
|
||||||
editedName: unclaimedWebFeed.editedName,
|
createWebFeedIfNecessary(url: newUnclaimedWebFeed.url,
|
||||||
homePageURL: unclaimedWebFeed.homePageURL,
|
name: newUnclaimedWebFeed.name,
|
||||||
webFeedExternalID: unclaimedWebFeed.webFeedExternalID,
|
editedName: newUnclaimedWebFeed.editedName,
|
||||||
|
homePageURL: newUnclaimedWebFeed.homePageURL,
|
||||||
|
webFeedExternalID: newUnclaimedWebFeed.webFeedExternalID,
|
||||||
container: folder)
|
container: folder)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.unclaimedWebFeeds.removeValue(forKey: containerExternalID)
|
self.newUnclaimedWebFeeds.removeValue(forKey: containerExternalID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let existingUnclaimedWebFeeds = existingUnclaimedWebFeeds[containerExternalID] {
|
||||||
|
for existingUnclaimedWebFeed in existingUnclaimedWebFeeds {
|
||||||
|
folder.addWebFeed(existingUnclaimedWebFeed)
|
||||||
|
}
|
||||||
|
self.existingUnclaimedWebFeeds.removeValue(forKey: containerExternalID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeContainer(_ externalID: String) {
|
func removeContainer(_ externalID: String) {
|
||||||
|
@ -152,6 +161,8 @@ private extension CloudKitAcountZoneDelegate {
|
||||||
case .insert(_, let externalID, _):
|
case .insert(_, let externalID, _):
|
||||||
if let container = account.existingContainer(withExternalID: externalID) {
|
if let container = account.existingContainer(withExternalID: externalID) {
|
||||||
container.addWebFeed(webFeed)
|
container.addWebFeed(webFeed)
|
||||||
|
} else {
|
||||||
|
addExistingUnclaimedWebFeed(webFeed, containerExternalID: externalID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,14 +181,25 @@ private extension CloudKitAcountZoneDelegate {
|
||||||
container.addWebFeed(webFeed)
|
container.addWebFeed(webFeed)
|
||||||
}
|
}
|
||||||
|
|
||||||
func addUnclaimedWebFeed(url: URL, name: String?, editedName: String?, homePageURL: String?, webFeedExternalID: String, containerExternalID: String) {
|
func addNewUnclaimedWebFeed(url: URL, name: String?, editedName: String?, homePageURL: String?, webFeedExternalID: String, containerExternalID: String) {
|
||||||
if var unclaimedWebFeeds = self.unclaimedWebFeeds[containerExternalID] {
|
if var unclaimedWebFeeds = self.newUnclaimedWebFeeds[containerExternalID] {
|
||||||
unclaimedWebFeeds.append(UnclaimedWebFeed(url: url, name: name, editedName: editedName, homePageURL: homePageURL, webFeedExternalID: webFeedExternalID))
|
unclaimedWebFeeds.append(UnclaimedWebFeed(url: url, name: name, editedName: editedName, homePageURL: homePageURL, webFeedExternalID: webFeedExternalID))
|
||||||
self.unclaimedWebFeeds[containerExternalID] = unclaimedWebFeeds
|
self.newUnclaimedWebFeeds[containerExternalID] = unclaimedWebFeeds
|
||||||
} else {
|
} else {
|
||||||
var unclaimedWebFeeds = [UnclaimedWebFeed]()
|
var unclaimedWebFeeds = [UnclaimedWebFeed]()
|
||||||
unclaimedWebFeeds.append(UnclaimedWebFeed(url: url, name: name, editedName: editedName, homePageURL: homePageURL, webFeedExternalID: webFeedExternalID))
|
unclaimedWebFeeds.append(UnclaimedWebFeed(url: url, name: name, editedName: editedName, homePageURL: homePageURL, webFeedExternalID: webFeedExternalID))
|
||||||
self.unclaimedWebFeeds[containerExternalID] = unclaimedWebFeeds
|
self.newUnclaimedWebFeeds[containerExternalID] = unclaimedWebFeeds
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func addExistingUnclaimedWebFeed(_ webFeed: WebFeed, containerExternalID: String) {
|
||||||
|
if var unclaimedWebFeeds = self.existingUnclaimedWebFeeds[containerExternalID] {
|
||||||
|
unclaimedWebFeeds.append(webFeed)
|
||||||
|
self.existingUnclaimedWebFeeds[containerExternalID] = unclaimedWebFeeds
|
||||||
|
} else {
|
||||||
|
var unclaimedWebFeeds = [WebFeed]()
|
||||||
|
unclaimedWebFeeds.append(webFeed)
|
||||||
|
self.existingUnclaimedWebFeeds[containerExternalID] = unclaimedWebFeeds
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue