Init feed with a disk dictionary.

This commit is contained in:
Brent Simmons 2017-09-26 13:26:28 -07:00
parent 8d9c9217dc
commit 9b566dd10d
2 changed files with 49 additions and 3 deletions

View File

@ -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

View File

@ -6,7 +6,7 @@
</editor> -->
<title>ToDo</title>
<dateCreated>Tue, 12 Sep 2017 20:15:17 GMT</dateCreated>
<expansionState>23,26,30,35,43,45,51,60</expansionState>
<expansionState>23,26,30,35,43,44,48,54,63</expansionState>
<vertScrollState>0</vertScrollState>
<windowTop>208</windowTop>
<windowLeft>30</windowLeft>
@ -69,7 +69,11 @@
</outline>
</outline>
<outline text="Frameworks">
<outline text="Account"/>
<outline text="Account">
<outline text="Save account settings and feeds to disk"/>
<outline text="Read account settings and feeds from disk"/>
<outline text="Update feed unread counts at startup"/>
</outline>
<outline text="Database">
<outline text="Update cutoff date periodically"/>
<outline text="Cleanup">