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)
|
||||
}
|
||||
|
||||
func metadata(for feed: Feed) -> FeedMetadata {
|
||||
if let d = feedMetadata[feed.feedID] {
|
||||
func metadata(feedID: String) -> FeedMetadata {
|
||||
if let d = feedMetadata[feedID] {
|
||||
assert(d.delegate === self)
|
||||
return d
|
||||
}
|
||||
let d = FeedMetadata(feedID: feed.feedID)
|
||||
let d = FeedMetadata(feedID: feedID)
|
||||
d.delegate = self
|
||||
feedMetadata[feed.feedID] = d
|
||||
feedMetadata[feedID] = 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,
|
||||
// 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 {
|
||||
feed.name = name
|
||||
}
|
||||
|
@ -732,8 +733,9 @@ private extension Account {
|
|||
}
|
||||
|
||||
func createFeed(with opmlFeedSpecifier: RSOPMLFeedSpecifier) -> Feed {
|
||||
|
||||
let feed = Feed(account: self, url: opmlFeedSpecifier.feedURL, feedID: opmlFeedSpecifier.feedURL)
|
||||
let 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 feed.name == nil {
|
||||
feed.name = feedTitle
|
||||
|
|
|
@ -19,43 +19,43 @@ public final class Feed: DisplayNameProvider, Renamable, UnreadCountProvider, Ha
|
|||
|
||||
public var homePageURL: String? {
|
||||
get {
|
||||
return metadata?.homePageURL
|
||||
return metadata.homePageURL
|
||||
}
|
||||
set {
|
||||
if let url = newValue {
|
||||
metadata?.homePageURL = url.rs_normalizedURL()
|
||||
metadata.homePageURL = url.rs_normalizedURL()
|
||||
}
|
||||
else {
|
||||
metadata?.homePageURL = nil
|
||||
metadata.homePageURL = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public var iconURL: String? {
|
||||
get {
|
||||
return metadata?.iconURL
|
||||
return metadata.iconURL
|
||||
}
|
||||
set {
|
||||
metadata?.iconURL = newValue
|
||||
metadata.iconURL = newValue
|
||||
}
|
||||
}
|
||||
|
||||
public var faviconURL: String? {
|
||||
get {
|
||||
return metadata?.faviconURL
|
||||
return metadata.faviconURL
|
||||
}
|
||||
set {
|
||||
metadata?.faviconURL = newValue
|
||||
metadata.faviconURL = newValue
|
||||
}
|
||||
}
|
||||
|
||||
public var name: String? {
|
||||
get {
|
||||
return metadata?.name
|
||||
return metadata.name
|
||||
}
|
||||
set {
|
||||
let oldNameForDisplay = nameForDisplay
|
||||
metadata?.name = newValue
|
||||
metadata.name = newValue
|
||||
if oldNameForDisplay != nameForDisplay {
|
||||
postDisplayNameDidChangeNotification()
|
||||
}
|
||||
|
@ -64,17 +64,17 @@ public final class Feed: DisplayNameProvider, Renamable, UnreadCountProvider, Ha
|
|||
|
||||
public var authors: Set<Author>? {
|
||||
get {
|
||||
if let authorsArray = metadata?.authors {
|
||||
if let authorsArray = metadata.authors {
|
||||
return Set(authorsArray)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
set {
|
||||
if let authorsSet = newValue {
|
||||
metadata?.authors = Array(authorsSet)
|
||||
metadata.authors = Array(authorsSet)
|
||||
}
|
||||
else {
|
||||
metadata?.authors = nil
|
||||
metadata.authors = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ public final class Feed: DisplayNameProvider, Renamable, UnreadCountProvider, Ha
|
|||
public var editedName: String? {
|
||||
// Don’t let editedName == ""
|
||||
get {
|
||||
guard let s = metadata?.editedName, !s.isEmpty else {
|
||||
guard let s = metadata.editedName, !s.isEmpty else {
|
||||
return nil
|
||||
}
|
||||
return s
|
||||
|
@ -90,10 +90,10 @@ public final class Feed: DisplayNameProvider, Renamable, UnreadCountProvider, Ha
|
|||
set {
|
||||
if newValue != editedName {
|
||||
if let valueToSet = newValue, !valueToSet.isEmpty {
|
||||
metadata?.editedName = valueToSet
|
||||
metadata.editedName = valueToSet
|
||||
}
|
||||
else {
|
||||
metadata?.editedName = nil
|
||||
metadata.editedName = nil
|
||||
}
|
||||
postDisplayNameDidChangeNotification()
|
||||
}
|
||||
|
@ -102,19 +102,19 @@ public final class Feed: DisplayNameProvider, Renamable, UnreadCountProvider, Ha
|
|||
|
||||
public var conditionalGetInfo: HTTPConditionalGetInfo? {
|
||||
get {
|
||||
return metadata?.conditionalGetInfo
|
||||
return metadata.conditionalGetInfo
|
||||
}
|
||||
set {
|
||||
metadata?.conditionalGetInfo = newValue
|
||||
metadata.conditionalGetInfo = newValue
|
||||
}
|
||||
}
|
||||
|
||||
public var contentHash: String? {
|
||||
get {
|
||||
return metadata?.contentHash
|
||||
return metadata.contentHash
|
||||
}
|
||||
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 var _metadata: FeedMetadata?
|
||||
private var metadata: FeedMetadata? {
|
||||
if let cachedMetadata = _metadata {
|
||||
return cachedMetadata
|
||||
}
|
||||
_metadata = account?.metadata(for: self)
|
||||
return _metadata
|
||||
}
|
||||
private let metadata: FeedMetadata
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
public init(account: Account, url: String, feedID: String) {
|
||||
public init(account: Account, url: String, feedID: String, metadata: FeedMetadata) {
|
||||
self.account = account
|
||||
self.accountID = account.accountID
|
||||
self.url = url
|
||||
self.feedID = feedID
|
||||
self.metadata = metadata
|
||||
}
|
||||
|
||||
// MARK: - Debug
|
||||
|
|
|
@ -14,7 +14,7 @@ protocol FeedMetadataDelegate: class {
|
|||
func valueDidChange(_ feedMetadata: FeedMetadata, key: FeedMetadata.CodingKeys)
|
||||
}
|
||||
|
||||
final class FeedMetadata: Codable {
|
||||
public final class FeedMetadata: Codable {
|
||||
|
||||
let feedID: String
|
||||
|
||||
|
|
Loading…
Reference in New Issue