From 199dd0e247c225a9087b280ef29ab041aa43a150 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Thu, 5 Oct 2017 21:08:27 -0700 Subject: [PATCH] Fix bug loading feeds from disk. --- Frameworks/Data/Article.swift | 2 +- Frameworks/Data/Feed.swift | 14 ++++++++++---- Frameworks/RSParser/Feeds/ParsedHub.swift | 2 +- Frameworks/RSParser/Feeds/ParsedItem.swift | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Frameworks/Data/Article.swift b/Frameworks/Data/Article.swift index 106c86a5c..fcef1345a 100644 --- a/Frameworks/Data/Article.swift +++ b/Frameworks/Data/Article.swift @@ -57,7 +57,7 @@ public struct Article: Hashable { self.articleID = Article.calculatedArticleID(feedID: feedID, uniqueID: uniqueID) } - self.hashValue = accountID.hashValue ^ self.articleID.hashValue + self.hashValue = (accountID + self.articleID).hashValue } public static func calculatedArticleID(feedID: String, uniqueID: String) -> String { diff --git a/Frameworks/Data/Feed.swift b/Frameworks/Data/Feed.swift index 4d800beff..df39c0e58 100644 --- a/Frameworks/Data/Feed.swift +++ b/Frameworks/Data/Feed.swift @@ -47,7 +47,7 @@ public final class Feed: DisplayNameProvider, UnreadCountProvider, Hashable { self.accountID = accountID self.url = url self.feedID = feedID - self.hashValue = accountID.hashValue ^ url.hashValue ^ feedID.hashValue + self.hashValue = feedID.hashValue } // MARK: - Disk Dictionary @@ -65,10 +65,11 @@ public final class Feed: DisplayNameProvider, UnreadCountProvider, Hashable { convenience public init?(accountID: String, dictionary: [String: Any]) { - guard let url = dictionary[Key.url] as? String, let feedID = dictionary[Key.feedID] as? String else { + guard let url = dictionary[Key.url] as? String else { return nil } - + let feedID = dictionary[Key.feedID] as? String ?? url + self.init(accountID: accountID, url: url, feedID: feedID) self.homePageURL = dictionary[Key.homePageURL] as? String self.name = dictionary[Key.name] as? String @@ -94,7 +95,12 @@ public final class Feed: DisplayNameProvider, UnreadCountProvider, Hashable { var d = [String: Any]() d[Key.url] = url - d[Key.feedID] = feedID + + // feedID is not repeated when it’s the same as url + if (feedID != url) { + d[Key.feedID] = feedID + } + if let homePageURL = homePageURL { d[Key.homePageURL] = homePageURL } diff --git a/Frameworks/RSParser/Feeds/ParsedHub.swift b/Frameworks/RSParser/Feeds/ParsedHub.swift index e328c5cdd..585cc5654 100644 --- a/Frameworks/RSParser/Feeds/ParsedHub.swift +++ b/Frameworks/RSParser/Feeds/ParsedHub.swift @@ -18,7 +18,7 @@ public struct ParsedHub: Hashable { self.type = type self.url = url - self.hashValue = type.hashValue ^ url.hashValue + self.hashValue = url.hashValue } public static func ==(lhs: ParsedHub, rhs: ParsedHub) -> Bool { diff --git a/Frameworks/RSParser/Feeds/ParsedItem.swift b/Frameworks/RSParser/Feeds/ParsedItem.swift index ee37ddbe3..216dd5e24 100644 --- a/Frameworks/RSParser/Feeds/ParsedItem.swift +++ b/Frameworks/RSParser/Feeds/ParsedItem.swift @@ -46,7 +46,7 @@ public struct ParsedItem: Hashable { self.authors = authors self.tags = tags self.attachments = attachments - self.hashValue = feedURL.hashValue ^ uniqueID.hashValue + self.hashValue = (feedURL + uniqueID).hashValue } public static func ==(lhs: ParsedItem, rhs: ParsedItem) -> Bool {