From 9b566dd10d2a5dc7647aba9aef6c4406d000fe35 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Tue, 26 Sep 2017 13:26:28 -0700 Subject: [PATCH] Init feed with a disk dictionary. --- Frameworks/Data/Feed.swift | 44 +++++++++++++++++++++++++++++++++++++- ToDo.opml | 8 +++++-- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/Frameworks/Data/Feed.swift b/Frameworks/Data/Feed.swift index 052ebdb14..24e60b09c 100644 --- a/Frameworks/Data/Feed.swift +++ b/Frameworks/Data/Feed.swift @@ -10,7 +10,7 @@ import Foundation import RSCore import RSWeb -public final class Feed: DisplayNameProvider, UnreadCountProvider, Codable, Hashable { +public final class Feed: DisplayNameProvider, UnreadCountProvider, Hashable { public let accountID: String public let url: String @@ -50,6 +50,48 @@ public final class Feed: DisplayNameProvider, UnreadCountProvider, Codable, Hash self.hashValue = accountID.hashValue ^ url.hashValue ^ feedID.hashValue } + // MARK: - Disk Dictionary + + private struct Key { + static let url = "url" + static let feedID = "feedID" + static let homePageURL = "homePageURL" + static let name = "name" + static let editedName = "editedName" + static let conditionalGetInfo = "conditionalGetInfo" + static let contentHash = "contentHash" + static let unreadCount = "unreadCount" + } + + convenience public init?(accountID: String, dictionary: [String: Any]) { + + guard let url = dictionary[Key.url] as? String, let feedID = dictionary[Key.feedID] as? String else { + return nil + } + + self.init(accountID: accountID, url: url, feedID: feedID) + self.homePageURL = dictionary[Key.homePageURL] as? String + self.name = dictionary[Key.name] as? String + self.editedName = dictionary[Key.editedName] as? String + self.contentHash = dictionary[Key.contentHash] as? String + + if let conditionalGetInfoDictionary = dictionary[Key.conditionalGetInfo] as? [String: String] { + self.conditionalGetInfo = HTTPConditionalGetInfo(dictionary: conditionalGetInfoDictionary) + } + + if let savedUnreadCount = dictionary[Key.unreadCount] as? Int { + self.unreadCount = savedUnreadCount + } + } + + public var dictionary: [String: Any] { + get { + var d = [String: Any]() + + return d + } + } + public class func ==(lhs: Feed, rhs: Feed) -> Bool { return lhs === rhs diff --git a/ToDo.opml b/ToDo.opml index 95ba350a1..45c774798 100644 --- a/ToDo.opml +++ b/ToDo.opml @@ -6,7 +6,7 @@ --> ToDo Tue, 12 Sep 2017 20:15:17 GMT - 23,26,30,35,43,45,51,60 + 23,26,30,35,43,44,48,54,63 0 208 30 @@ -69,7 +69,11 @@ - + + + + +