From 5f1bdb29ec59437aa5ddbf62cf905f2ddfa46bb6 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 17 Mar 2019 12:47:04 -0700 Subject: [PATCH] =?UTF-8?q?Give=20the=20.FeedSettingsDidChange=20notificat?= =?UTF-8?q?ion=20a=20userInfo=20with=20the=20key=20of=20the=20setting=20th?= =?UTF-8?q?at=20changed.=20This=20way=20observers=20can=20ignore=20changes?= =?UTF-8?q?=20they=20don=E2=80=99t=20care=20about.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frameworks/Account/Account.swift | 4 ++ Frameworks/Account/DataExtensions.swift | 54 ++++++++++++------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index 0eab0690d..d5652a013 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -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) } } diff --git a/Frameworks/Account/DataExtensions.swift b/Frameworks/Account/DataExtensions.swift index 304a1866b..f9a7f9a96 100644 --- a/Frameworks/Account/DataExtensions.swift +++ b/Frameworks/Account/DataExtensions.swift @@ -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) { + iconURL = parsedFeed.iconURL + faviconURL = parsedFeed.faviconURL + homePageURL = parsedFeed.homePageURL + name = parsedFeed.title + authors = Author.authorsWithParsedAuthors(parsedFeed.authors) + } - 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 - } - - 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) } }