Save feed.authors.
This commit is contained in:
parent
b5d8233955
commit
e71d763443
|
@ -53,6 +53,12 @@ public extension Feed {
|
||||||
didChangeAtLeastOneSetting = true
|
didChangeAtLeastOneSetting = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let updatedAuthors = Author.authorsWithParsedAuthors(parsedFeed.authors)
|
||||||
|
if authors != updatedAuthors {
|
||||||
|
authors = updatedAuthors
|
||||||
|
didChangeAtLeastOneSetting = true
|
||||||
|
}
|
||||||
|
|
||||||
if didChangeAtLeastOneSetting {
|
if didChangeAtLeastOneSetting {
|
||||||
NotificationCenter.default.post(name: .FeedSettingDidChange, object: self)
|
NotificationCenter.default.post(name: .FeedSettingDidChange, object: self)
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,9 +41,61 @@ public struct Author: Hashable {
|
||||||
self.authorID = databaseIDWithString(s)
|
self.authorID = databaseIDWithString(s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public struct Key {
|
||||||
|
static let authorID = "authorID"
|
||||||
|
static let name = "name"
|
||||||
|
static let url = "url"
|
||||||
|
static let avatarURL = "avatarURL"
|
||||||
|
static let emailAddress = "emailAddress"
|
||||||
|
}
|
||||||
|
|
||||||
|
public init?(dictionary: [String: Any]) {
|
||||||
|
|
||||||
|
self.init(authorID: dictionary[Key.authorID] as? String, name: dictionary[Key.name] as? String, url: dictionary[Key.url] as? String, avatarURL: dictionary[Key.avatarURL] as? String, emailAddress: dictionary[Key.emailAddress] as? String)
|
||||||
|
}
|
||||||
|
|
||||||
|
public var dictionary: [String: Any] {
|
||||||
|
|
||||||
|
var d = [String: Any]()
|
||||||
|
|
||||||
|
d[Key.authorID] = authorID
|
||||||
|
|
||||||
|
if let name = name {
|
||||||
|
d[Key.name] = name
|
||||||
|
}
|
||||||
|
if let url = url {
|
||||||
|
d[Key.url] = url
|
||||||
|
}
|
||||||
|
if let avatarURL = avatarURL {
|
||||||
|
d[Key.avatarURL] = avatarURL
|
||||||
|
}
|
||||||
|
if let emailAddress = emailAddress {
|
||||||
|
d[Key.emailAddress] = emailAddress
|
||||||
|
}
|
||||||
|
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
public static func ==(lhs: Author, rhs: Author) -> Bool {
|
public static func ==(lhs: Author, rhs: Author) -> Bool {
|
||||||
|
|
||||||
return lhs.hashValue == rhs.hashValue && lhs.authorID == rhs.authorID
|
return lhs.hashValue == rhs.hashValue && lhs.authorID == rhs.authorID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static func authorsWithDiskArray(_ diskArray: [[String: Any]]) -> Set<Author>? {
|
||||||
|
|
||||||
|
let authors = diskArray.flatMap { Author(dictionary: $0) }
|
||||||
|
return authors.isEmpty ? nil : Set(authors)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension Set where Element == Author {
|
||||||
|
|
||||||
|
func diskArray() -> [[String: Any]]? {
|
||||||
|
|
||||||
|
if self.isEmpty {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return self.map{ $0.dictionary }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ public final class Feed: DisplayNameProvider, UnreadCountProvider, Hashable {
|
||||||
public var iconURL: String?
|
public var iconURL: String?
|
||||||
public var faviconURL: String?
|
public var faviconURL: String?
|
||||||
public var name: String?
|
public var name: String?
|
||||||
|
public var authors: Set<Author>?
|
||||||
public var editedName: String?
|
public var editedName: String?
|
||||||
public var conditionalGetInfo: HTTPConditionalGetInfo?
|
public var conditionalGetInfo: HTTPConditionalGetInfo?
|
||||||
public var contentHash: String?
|
public var contentHash: String?
|
||||||
|
@ -62,6 +63,7 @@ public final class Feed: DisplayNameProvider, UnreadCountProvider, Hashable {
|
||||||
static let faviconURL = "faviconURL"
|
static let faviconURL = "faviconURL"
|
||||||
static let name = "name"
|
static let name = "name"
|
||||||
static let editedName = "editedName"
|
static let editedName = "editedName"
|
||||||
|
static let authors = "authors"
|
||||||
static let conditionalGetInfo = "conditionalGetInfo"
|
static let conditionalGetInfo = "conditionalGetInfo"
|
||||||
static let contentHash = "contentHash"
|
static let contentHash = "contentHash"
|
||||||
static let unreadCount = "unreadCount"
|
static let unreadCount = "unreadCount"
|
||||||
|
@ -89,6 +91,10 @@ public final class Feed: DisplayNameProvider, UnreadCountProvider, Hashable {
|
||||||
if let savedUnreadCount = dictionary[Key.unreadCount] as? Int {
|
if let savedUnreadCount = dictionary[Key.unreadCount] as? Int {
|
||||||
self.unreadCount = savedUnreadCount
|
self.unreadCount = savedUnreadCount
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let authorsDiskArray = dictionary[Key.authors] as? [[String: Any]] {
|
||||||
|
self.authors = Author.authorsWithDiskArray(authorsDiskArray)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func isFeedDictionary(_ d: [String: Any]) -> Bool {
|
public static func isFeedDictionary(_ d: [String: Any]) -> Bool {
|
||||||
|
@ -122,6 +128,9 @@ public final class Feed: DisplayNameProvider, UnreadCountProvider, Hashable {
|
||||||
if let editedName = editedName {
|
if let editedName = editedName {
|
||||||
d[Key.editedName] = editedName
|
d[Key.editedName] = editedName
|
||||||
}
|
}
|
||||||
|
if let authorsArray = authors?.diskArray() {
|
||||||
|
d[Key.authors] = authorsArray
|
||||||
|
}
|
||||||
if let contentHash = contentHash {
|
if let contentHash = contentHash {
|
||||||
d[Key.contentHash] = contentHash
|
d[Key.contentHash] = contentHash
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ extension Author {
|
||||||
self.init(authorID: nil, name: parsedAuthor.name, url: parsedAuthor.url, avatarURL: parsedAuthor.avatarURL, emailAddress: parsedAuthor.emailAddress)
|
self.init(authorID: nil, name: parsedAuthor.name, url: parsedAuthor.url, avatarURL: parsedAuthor.avatarURL, emailAddress: parsedAuthor.emailAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
static func authorsWithParsedAuthors(_ parsedAuthors: Set<ParsedAuthor>?) -> Set<Author>? {
|
public static func authorsWithParsedAuthors(_ parsedAuthors: Set<ParsedAuthor>?) -> Set<Author>? {
|
||||||
|
|
||||||
guard let parsedAuthors = parsedAuthors else {
|
guard let parsedAuthors = parsedAuthors else {
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue