Fix bug loading feeds from disk.

This commit is contained in:
Brent Simmons 2017-10-05 21:08:27 -07:00
parent 0f19fda54d
commit 199dd0e247
4 changed files with 13 additions and 7 deletions

View File

@ -57,7 +57,7 @@ public struct Article: Hashable {
self.articleID = Article.calculatedArticleID(feedID: feedID, uniqueID: uniqueID) 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 { public static func calculatedArticleID(feedID: String, uniqueID: String) -> String {

View File

@ -47,7 +47,7 @@ public final class Feed: DisplayNameProvider, UnreadCountProvider, Hashable {
self.accountID = accountID self.accountID = accountID
self.url = url self.url = url
self.feedID = feedID self.feedID = feedID
self.hashValue = accountID.hashValue ^ url.hashValue ^ feedID.hashValue self.hashValue = feedID.hashValue
} }
// MARK: - Disk Dictionary // MARK: - Disk Dictionary
@ -65,10 +65,11 @@ public final class Feed: DisplayNameProvider, UnreadCountProvider, Hashable {
convenience public init?(accountID: String, dictionary: [String: Any]) { 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 return nil
} }
let feedID = dictionary[Key.feedID] as? String ?? url
self.init(accountID: accountID, url: url, feedID: feedID) self.init(accountID: accountID, url: url, feedID: feedID)
self.homePageURL = dictionary[Key.homePageURL] as? String self.homePageURL = dictionary[Key.homePageURL] as? String
self.name = dictionary[Key.name] as? String self.name = dictionary[Key.name] as? String
@ -94,7 +95,12 @@ public final class Feed: DisplayNameProvider, UnreadCountProvider, Hashable {
var d = [String: Any]() var d = [String: Any]()
d[Key.url] = url d[Key.url] = url
d[Key.feedID] = feedID
// feedID is not repeated when its the same as url
if (feedID != url) {
d[Key.feedID] = feedID
}
if let homePageURL = homePageURL { if let homePageURL = homePageURL {
d[Key.homePageURL] = homePageURL d[Key.homePageURL] = homePageURL
} }

View File

@ -18,7 +18,7 @@ public struct ParsedHub: Hashable {
self.type = type self.type = type
self.url = url self.url = url
self.hashValue = type.hashValue ^ url.hashValue self.hashValue = url.hashValue
} }
public static func ==(lhs: ParsedHub, rhs: ParsedHub) -> Bool { public static func ==(lhs: ParsedHub, rhs: ParsedHub) -> Bool {

View File

@ -46,7 +46,7 @@ public struct ParsedItem: Hashable {
self.authors = authors self.authors = authors
self.tags = tags self.tags = tags
self.attachments = attachments self.attachments = attachments
self.hashValue = feedURL.hashValue ^ uniqueID.hashValue self.hashValue = (feedURL + uniqueID).hashValue
} }
public static func ==(lhs: ParsedItem, rhs: ParsedItem) -> Bool { public static func ==(lhs: ParsedItem, rhs: ParsedItem) -> Bool {