Give the .FeedSettingsDidChange notification a userInfo with the key of the setting that changed. This way observers can ignore changes they don’t care about.
This commit is contained in:
parent
80bee5b487
commit
5f1bdb29ec
|
@ -571,6 +571,10 @@ extension Account: FeedMetadataDelegate {
|
|||
|
||||
func valueDidChange(_ feedMetadata: FeedMetadata, key: FeedMetadata.CodingKeys) {
|
||||
feedMetadataDirty = true
|
||||
guard let feed = existingFeed(with: feedMetadata.feedID) else {
|
||||
return
|
||||
}
|
||||
feed.postFeedSettingDidChangeNotification(key)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,42 +11,38 @@ import Articles
|
|||
import RSParser
|
||||
|
||||
public extension Notification.Name {
|
||||
|
||||
static let FeedSettingDidChange = Notification.Name(rawValue: "FeedSettingDidChangeNotification")
|
||||
}
|
||||
|
||||
public extension Feed {
|
||||
|
||||
public static let FeedSettingUserInfoKey = "feedSetting"
|
||||
|
||||
public struct FeedSettingKey {
|
||||
static let homePageURL = "homePageURL"
|
||||
static let iconURL = "iconURL"
|
||||
static let faviconURL = "faviconURL"
|
||||
static let name = "name"
|
||||
static let editedName = "editedName"
|
||||
static let authors = "authors"
|
||||
static let contentHash = "contentHash"
|
||||
static let conditionalGetInfo = "conditionalGetInfo"
|
||||
}
|
||||
}
|
||||
|
||||
extension Feed {
|
||||
|
||||
func takeSettings(from parsedFeed: ParsedFeed) {
|
||||
|
||||
var didChangeAtLeastOneSetting = false
|
||||
|
||||
if iconURL != parsedFeed.iconURL {
|
||||
iconURL = parsedFeed.iconURL
|
||||
didChangeAtLeastOneSetting = true
|
||||
}
|
||||
if faviconURL != parsedFeed.faviconURL {
|
||||
faviconURL = parsedFeed.faviconURL
|
||||
didChangeAtLeastOneSetting = true
|
||||
}
|
||||
if homePageURL != parsedFeed.homePageURL {
|
||||
homePageURL = parsedFeed.homePageURL
|
||||
didChangeAtLeastOneSetting = true
|
||||
}
|
||||
if name != parsedFeed.title {
|
||||
name = parsedFeed.title
|
||||
didChangeAtLeastOneSetting = true
|
||||
authors = Author.authorsWithParsedAuthors(parsedFeed.authors)
|
||||
}
|
||||
|
||||
let updatedAuthors = Author.authorsWithParsedAuthors(parsedFeed.authors)
|
||||
if authors != updatedAuthors {
|
||||
authors = updatedAuthors
|
||||
didChangeAtLeastOneSetting = true
|
||||
}
|
||||
|
||||
if didChangeAtLeastOneSetting {
|
||||
NotificationCenter.default.post(name: .FeedSettingDidChange, object: self)
|
||||
}
|
||||
func postFeedSettingDidChangeNotification(_ codingKey: FeedMetadata.CodingKeys) {
|
||||
let userInfo = [Feed.FeedSettingUserInfoKey: codingKey.stringValue]
|
||||
NotificationCenter.default.post(name: .FeedSettingDidChange, object: self, userInfo: userInfo)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue