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) {
|
func valueDidChange(_ feedMetadata: FeedMetadata, key: FeedMetadata.CodingKeys) {
|
||||||
feedMetadataDirty = true
|
feedMetadataDirty = true
|
||||||
|
guard let feed = existingFeed(with: feedMetadata.feedID) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
feed.postFeedSettingDidChangeNotification(key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,42 +11,38 @@ import Articles
|
||||||
import RSParser
|
import RSParser
|
||||||
|
|
||||||
public extension Notification.Name {
|
public extension Notification.Name {
|
||||||
|
|
||||||
static let FeedSettingDidChange = Notification.Name(rawValue: "FeedSettingDidChangeNotification")
|
static let FeedSettingDidChange = Notification.Name(rawValue: "FeedSettingDidChangeNotification")
|
||||||
}
|
}
|
||||||
|
|
||||||
public extension Feed {
|
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) {
|
func takeSettings(from parsedFeed: ParsedFeed) {
|
||||||
|
|
||||||
var didChangeAtLeastOneSetting = false
|
|
||||||
|
|
||||||
if iconURL != parsedFeed.iconURL {
|
|
||||||
iconURL = parsedFeed.iconURL
|
iconURL = parsedFeed.iconURL
|
||||||
didChangeAtLeastOneSetting = true
|
|
||||||
}
|
|
||||||
if faviconURL != parsedFeed.faviconURL {
|
|
||||||
faviconURL = parsedFeed.faviconURL
|
faviconURL = parsedFeed.faviconURL
|
||||||
didChangeAtLeastOneSetting = true
|
|
||||||
}
|
|
||||||
if homePageURL != parsedFeed.homePageURL {
|
|
||||||
homePageURL = parsedFeed.homePageURL
|
homePageURL = parsedFeed.homePageURL
|
||||||
didChangeAtLeastOneSetting = true
|
|
||||||
}
|
|
||||||
if name != parsedFeed.title {
|
|
||||||
name = parsedFeed.title
|
name = parsedFeed.title
|
||||||
didChangeAtLeastOneSetting = true
|
authors = Author.authorsWithParsedAuthors(parsedFeed.authors)
|
||||||
}
|
}
|
||||||
|
|
||||||
let updatedAuthors = Author.authorsWithParsedAuthors(parsedFeed.authors)
|
func postFeedSettingDidChangeNotification(_ codingKey: FeedMetadata.CodingKeys) {
|
||||||
if authors != updatedAuthors {
|
let userInfo = [Feed.FeedSettingUserInfoKey: codingKey.stringValue]
|
||||||
authors = updatedAuthors
|
NotificationCenter.default.post(name: .FeedSettingDidChange, object: self, userInfo: userInfo)
|
||||||
didChangeAtLeastOneSetting = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if didChangeAtLeastOneSetting {
|
|
||||||
NotificationCenter.default.post(name: .FeedSettingDidChange, object: self)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue