Keep feedID and feedURL better separated

This commit is contained in:
Maurice Parker 2019-05-08 09:54:55 -05:00
parent f12494cc31
commit 72c92587d2
4 changed files with 32 additions and 17 deletions

View File

@ -386,14 +386,14 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
// For syncing, this may need to be an async method with a callback,
// since it will likely need to call the server.
return createFeed(with: name, editedName: editedName, url: url, feedId: url, homePageURL: nil)
return createFeed(with: name, editedName: editedName, url: url, feedID: url, homePageURL: nil)
}
func createFeed(with name: String?, editedName: String?, url: String, feedId: String, homePageURL: String?) -> Feed {
func createFeed(with name: String?, editedName: String?, url: String, feedID: String, homePageURL: String?) -> Feed {
let metadata = feedMetadata(feedID: feedId)
let feed = Feed(account: self, url: url, feedID: feedId, metadata: metadata)
let metadata = feedMetadata(feedURL: url, feedID: feedID)
let feed = Feed(account: self, url: url, metadata: metadata)
feed.name = name
feed.editedName = editedName
feed.homePageURL = homePageURL
@ -804,6 +804,7 @@ private extension Account {
BatchUpdate.shared.perform {
importOPMLItems(children, parentFolder: nil)
}
}
func saveToDisk() {
@ -831,7 +832,7 @@ private extension Account {
private func metadataForOnlySubscribedToFeeds() -> FeedMetadataDictionary {
let feedIDs = idToFeedDictionary.keys
return feedMetadata.filter { (feedID: String, metadata: FeedMetadata) -> Bool in
return feedIDs.contains(feedID)
return feedIDs.contains(metadata.feedID)
}
}
@ -875,14 +876,14 @@ private extension Account {
private extension Account {
func feedMetadata(feedID: String) -> FeedMetadata {
if let d = feedMetadata[feedID] {
func feedMetadata(feedURL: String, feedID: String) -> FeedMetadata {
if let d = feedMetadata[feedURL] {
assert(d.delegate === self)
return d
}
let d = FeedMetadata(feedID: feedID)
d.delegate = self
feedMetadata[feedID] = d
feedMetadata[feedURL] = d
return d
}
@ -909,9 +910,9 @@ private extension Account {
}
func createFeed(with opmlFeedSpecifier: RSOPMLFeedSpecifier) -> Feed {
let feedID = opmlFeedSpecifier.feedURL
let metadata = feedMetadata(feedID: feedID)
let feed = Feed(account: self, url: opmlFeedSpecifier.feedURL, feedID: feedID, metadata: metadata)
let feedURL = opmlFeedSpecifier.feedURL
let metadata = feedMetadata(feedURL: feedURL, feedID: feedURL)
let feed = Feed(account: self, url: opmlFeedSpecifier.feedURL, metadata: metadata)
if let feedTitle = opmlFeedSpecifier.title {
if feed.name == nil {
feed.name = feedTitle

View File

@ -15,7 +15,15 @@ public final class Feed: DisplayNameProvider, Renamable, UnreadCountProvider, Ha
public weak var account: Account?
public let url: String
public let feedID: String
public var feedID: String {
get {
return metadata.feedID
}
set {
metadata.feedID = newValue
}
}
public var homePageURL: String? {
get {
@ -169,11 +177,10 @@ public final class Feed: DisplayNameProvider, Renamable, UnreadCountProvider, Ha
// MARK: - Init
init(account: Account, url: String, feedID: String, metadata: FeedMetadata) {
init(account: Account, url: String, metadata: FeedMetadata) {
self.account = account
self.accountID = account.accountID
self.url = url
self.feedID = feedID
self.metadata = metadata
}

View File

@ -16,8 +16,6 @@ protocol FeedMetadataDelegate: class {
final class FeedMetadata: Codable {
let feedID: String
enum CodingKeys: String, CodingKey {
case feedID
case homePageURL
@ -31,6 +29,14 @@ final class FeedMetadata: Codable {
case folderRelationship
}
var feedID: String {
didSet {
if feedID != oldValue {
valueDidChange(.feedID)
}
}
}
var homePageURL: String? {
didSet {
if homePageURL != oldValue {
@ -95,6 +101,7 @@ final class FeedMetadata: Codable {
}
}
// Folder Name: Sync Service Relationship ID
var folderRelationship: [String: String]? {
didSet {
if folderRelationship != oldValue {

View File

@ -282,7 +282,7 @@ private extension FeedbinAccountDelegate {
feed.name = subscription.name
feed.homePageURL = subscription.homePageURL
} else {
let feed = account.createFeed(with: subscription.name, editedName: nil, url: subscription.url, feedId: subFeedId, homePageURL: subscription.homePageURL)
let feed = account.createFeed(with: subscription.name, editedName: nil, url: subscription.url, feedID: subFeedId, homePageURL: subscription.homePageURL)
account.addFeed(feed, to: nil)
}
}