Make feed.metadata no longer an optional.
This commit is contained in:
parent
47935717c5
commit
3e52bb9c24
|
@ -166,14 +166,14 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||||
delegate.refreshAll(for: self)
|
delegate.refreshAll(for: self)
|
||||||
}
|
}
|
||||||
|
|
||||||
func metadata(for feed: Feed) -> FeedMetadata {
|
func metadata(feedID: String) -> FeedMetadata {
|
||||||
if let d = feedMetadata[feed.feedID] {
|
if let d = feedMetadata[feedID] {
|
||||||
assert(d.delegate === self)
|
assert(d.delegate === self)
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
let d = FeedMetadata(feedID: feed.feedID)
|
let d = FeedMetadata(feedID: feedID)
|
||||||
d.delegate = self
|
d.delegate = self
|
||||||
feedMetadata[feed.feedID] = d
|
feedMetadata[feedID] = d
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,7 +279,8 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||||
// For syncing, this may need to be an async method with a callback,
|
// For syncing, this may need to be an async method with a callback,
|
||||||
// since it will likely need to call the server.
|
// since it will likely need to call the server.
|
||||||
|
|
||||||
let feed = Feed(account: self, url: url, feedID: url)
|
let feedMetadata = metadata(feedID: url)
|
||||||
|
let feed = Feed(account: self, url: url, feedID: url, metadata: feedMetadata)
|
||||||
if let name = name, feed.name == nil {
|
if let name = name, feed.name == nil {
|
||||||
feed.name = name
|
feed.name = name
|
||||||
}
|
}
|
||||||
|
@ -732,8 +733,9 @@ private extension Account {
|
||||||
}
|
}
|
||||||
|
|
||||||
func createFeed(with opmlFeedSpecifier: RSOPMLFeedSpecifier) -> Feed {
|
func createFeed(with opmlFeedSpecifier: RSOPMLFeedSpecifier) -> Feed {
|
||||||
|
let feedID = opmlFeedSpecifier.feedURL
|
||||||
let feed = Feed(account: self, url: opmlFeedSpecifier.feedURL, feedID: opmlFeedSpecifier.feedURL)
|
let feedMetadata = metadata(feedID: feedID)
|
||||||
|
let feed = Feed(account: self, url: opmlFeedSpecifier.feedURL, feedID: feedID, metadata: feedMetadata)
|
||||||
if let feedTitle = opmlFeedSpecifier.title {
|
if let feedTitle = opmlFeedSpecifier.title {
|
||||||
if feed.name == nil {
|
if feed.name == nil {
|
||||||
feed.name = feedTitle
|
feed.name = feedTitle
|
||||||
|
|
|
@ -19,43 +19,43 @@ public final class Feed: DisplayNameProvider, Renamable, UnreadCountProvider, Ha
|
||||||
|
|
||||||
public var homePageURL: String? {
|
public var homePageURL: String? {
|
||||||
get {
|
get {
|
||||||
return metadata?.homePageURL
|
return metadata.homePageURL
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
if let url = newValue {
|
if let url = newValue {
|
||||||
metadata?.homePageURL = url.rs_normalizedURL()
|
metadata.homePageURL = url.rs_normalizedURL()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
metadata?.homePageURL = nil
|
metadata.homePageURL = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public var iconURL: String? {
|
public var iconURL: String? {
|
||||||
get {
|
get {
|
||||||
return metadata?.iconURL
|
return metadata.iconURL
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
metadata?.iconURL = newValue
|
metadata.iconURL = newValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public var faviconURL: String? {
|
public var faviconURL: String? {
|
||||||
get {
|
get {
|
||||||
return metadata?.faviconURL
|
return metadata.faviconURL
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
metadata?.faviconURL = newValue
|
metadata.faviconURL = newValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public var name: String? {
|
public var name: String? {
|
||||||
get {
|
get {
|
||||||
return metadata?.name
|
return metadata.name
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
let oldNameForDisplay = nameForDisplay
|
let oldNameForDisplay = nameForDisplay
|
||||||
metadata?.name = newValue
|
metadata.name = newValue
|
||||||
if oldNameForDisplay != nameForDisplay {
|
if oldNameForDisplay != nameForDisplay {
|
||||||
postDisplayNameDidChangeNotification()
|
postDisplayNameDidChangeNotification()
|
||||||
}
|
}
|
||||||
|
@ -64,17 +64,17 @@ public final class Feed: DisplayNameProvider, Renamable, UnreadCountProvider, Ha
|
||||||
|
|
||||||
public var authors: Set<Author>? {
|
public var authors: Set<Author>? {
|
||||||
get {
|
get {
|
||||||
if let authorsArray = metadata?.authors {
|
if let authorsArray = metadata.authors {
|
||||||
return Set(authorsArray)
|
return Set(authorsArray)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
if let authorsSet = newValue {
|
if let authorsSet = newValue {
|
||||||
metadata?.authors = Array(authorsSet)
|
metadata.authors = Array(authorsSet)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
metadata?.authors = nil
|
metadata.authors = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ public final class Feed: DisplayNameProvider, Renamable, UnreadCountProvider, Ha
|
||||||
public var editedName: String? {
|
public var editedName: String? {
|
||||||
// Don’t let editedName == ""
|
// Don’t let editedName == ""
|
||||||
get {
|
get {
|
||||||
guard let s = metadata?.editedName, !s.isEmpty else {
|
guard let s = metadata.editedName, !s.isEmpty else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
|
@ -90,10 +90,10 @@ public final class Feed: DisplayNameProvider, Renamable, UnreadCountProvider, Ha
|
||||||
set {
|
set {
|
||||||
if newValue != editedName {
|
if newValue != editedName {
|
||||||
if let valueToSet = newValue, !valueToSet.isEmpty {
|
if let valueToSet = newValue, !valueToSet.isEmpty {
|
||||||
metadata?.editedName = valueToSet
|
metadata.editedName = valueToSet
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
metadata?.editedName = nil
|
metadata.editedName = nil
|
||||||
}
|
}
|
||||||
postDisplayNameDidChangeNotification()
|
postDisplayNameDidChangeNotification()
|
||||||
}
|
}
|
||||||
|
@ -102,19 +102,19 @@ public final class Feed: DisplayNameProvider, Renamable, UnreadCountProvider, Ha
|
||||||
|
|
||||||
public var conditionalGetInfo: HTTPConditionalGetInfo? {
|
public var conditionalGetInfo: HTTPConditionalGetInfo? {
|
||||||
get {
|
get {
|
||||||
return metadata?.conditionalGetInfo
|
return metadata.conditionalGetInfo
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
metadata?.conditionalGetInfo = newValue
|
metadata.conditionalGetInfo = newValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public var contentHash: String? {
|
public var contentHash: String? {
|
||||||
get {
|
get {
|
||||||
return metadata?.contentHash
|
return metadata.contentHash
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
metadata?.contentHash = newValue
|
metadata.contentHash = newValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,23 +152,16 @@ public final class Feed: DisplayNameProvider, Renamable, UnreadCountProvider, Ha
|
||||||
}
|
}
|
||||||
|
|
||||||
private let accountID: String // Used for hashing and equality; account may turn nil
|
private let accountID: String // Used for hashing and equality; account may turn nil
|
||||||
|
private let metadata: FeedMetadata
|
||||||
private var _metadata: FeedMetadata?
|
|
||||||
private var metadata: FeedMetadata? {
|
|
||||||
if let cachedMetadata = _metadata {
|
|
||||||
return cachedMetadata
|
|
||||||
}
|
|
||||||
_metadata = account?.metadata(for: self)
|
|
||||||
return _metadata
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Init
|
// MARK: - Init
|
||||||
|
|
||||||
public init(account: Account, url: String, feedID: String) {
|
public init(account: Account, url: String, feedID: String, metadata: FeedMetadata) {
|
||||||
self.account = account
|
self.account = account
|
||||||
self.accountID = account.accountID
|
self.accountID = account.accountID
|
||||||
self.url = url
|
self.url = url
|
||||||
self.feedID = feedID
|
self.feedID = feedID
|
||||||
|
self.metadata = metadata
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Debug
|
// MARK: - Debug
|
||||||
|
|
|
@ -14,7 +14,7 @@ protocol FeedMetadataDelegate: class {
|
||||||
func valueDidChange(_ feedMetadata: FeedMetadata, key: FeedMetadata.CodingKeys)
|
func valueDidChange(_ feedMetadata: FeedMetadata, key: FeedMetadata.CodingKeys)
|
||||||
}
|
}
|
||||||
|
|
||||||
final class FeedMetadata: Codable {
|
public final class FeedMetadata: Codable {
|
||||||
|
|
||||||
let feedID: String
|
let feedID: String
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue