From 0e46a811b79db3aaed4cb7578666777ab09ead2f Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Mon, 19 Feb 2024 10:18:12 +0100 Subject: [PATCH] Use constant foe UserInfo-key instead of string (IOS-192) --- Mastodon/Protocol/Provider/DataSourceFacade+Block.swift | 2 +- Mastodon/Protocol/Provider/DataSourceFacade+Follow.swift | 6 +++--- Mastodon/Protocol/Provider/DataSourceFacade+Mute.swift | 2 +- Mastodon/Scene/Profile/ProfileViewController.swift | 4 ++-- .../Service/API/APIService+HomeTimeline.swift | 3 +-- .../Service/API/APIService+Relationship.swift | 8 ++++++++ 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Mastodon/Protocol/Provider/DataSourceFacade+Block.swift b/Mastodon/Protocol/Provider/DataSourceFacade+Block.swift index 02bf7893b..139de62dc 100644 --- a/Mastodon/Protocol/Provider/DataSourceFacade+Block.swift +++ b/Mastodon/Protocol/Provider/DataSourceFacade+Block.swift @@ -27,7 +27,7 @@ extension DataSourceFacade { ) let userInfo = [ - "relationship": response.value, + .relationship: response.value, ] NotificationCenter.default.post(name: .relationshipChanged, object: self, userInfo: userInfo) diff --git a/Mastodon/Protocol/Provider/DataSourceFacade+Follow.swift b/Mastodon/Protocol/Provider/DataSourceFacade+Follow.swift index 2c16c8241..b47aa9e76 100644 --- a/Mastodon/Protocol/Provider/DataSourceFacade+Follow.swift +++ b/Mastodon/Protocol/Provider/DataSourceFacade+Follow.swift @@ -27,7 +27,7 @@ extension DataSourceFacade { dependency.context.authenticationService.fetchFollowingAndBlockedAsync() NotificationCenter.default.post(name: .relationshipChanged, object: nil, userInfo: [ - "relationship": response + .relationship: response ]) return response @@ -75,7 +75,7 @@ extension DataSourceFacade { } NotificationCenter.default.post(name: .relationshipChanged, object: nil, userInfo: [ - "relationship": newRelationship + .relationship: newRelationship ]) await notificationView.configure(notification: notification, authenticationBox: dependency.authContext.mastodonAuthenticationBox) @@ -115,7 +115,7 @@ extension DataSourceFacade { ) let userInfo = [ - "relationship": newRelationship, + .relationship: newRelationship, ] NotificationCenter.default.post(name: .relationshipChanged, object: self, userInfo: userInfo) diff --git a/Mastodon/Protocol/Provider/DataSourceFacade+Mute.swift b/Mastodon/Protocol/Provider/DataSourceFacade+Mute.swift index 3e70d7b09..b072e8e27 100644 --- a/Mastodon/Protocol/Provider/DataSourceFacade+Mute.swift +++ b/Mastodon/Protocol/Provider/DataSourceFacade+Mute.swift @@ -23,7 +23,7 @@ extension DataSourceFacade { ) let userInfo = [ - "relationship": response.value, + .relationship: response.value, ] NotificationCenter.default.post(name: .relationshipChanged, object: self, userInfo: userInfo) diff --git a/Mastodon/Scene/Profile/ProfileViewController.swift b/Mastodon/Scene/Profile/ProfileViewController.swift index 47c93d3c1..09ee2235d 100644 --- a/Mastodon/Scene/Profile/ProfileViewController.swift +++ b/Mastodon/Scene/Profile/ProfileViewController.swift @@ -833,7 +833,7 @@ extension ProfileViewController: ProfileHeaderViewControllerDelegate { // we need to trigger this here as domain block doesn't return a relationship let userInfo = [ - "relationship": newRelationship, + .relationship: newRelationship, ] NotificationCenter.default.post(name: .relationshipChanged, object: self, userInfo: userInfo) @@ -1002,7 +1002,7 @@ extension ProfileViewController { @objc func relationshipChanged(_ notification: Notification) { - guard let userInfo = notification.userInfo, let relationship = userInfo["relationship"] as? Mastodon.Entity.Relationship else { + guard let userInfo = notification.userInfo, let relationship = userInfo[.relationship] as? Mastodon.Entity.Relationship else { return } diff --git a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+HomeTimeline.swift b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+HomeTimeline.swift index 976ccfb73..17544b4fe 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+HomeTimeline.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+HomeTimeline.swift @@ -11,9 +11,8 @@ import CoreData import CoreDataStack import MastodonSDK -public extension Foundation.Notification.Name { +public extension Notification.Name { static let userFetched = Notification.Name(rawValue: "org.joinmastodon.app.user-fetched") - static let relationshipChanged = Notification.Name(rawValue: "org.joinmastodon.app.relationship-changed") } extension APIService { diff --git a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Relationship.swift b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Relationship.swift index ce366ad7e..69b378cb2 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Relationship.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Relationship.swift @@ -11,6 +11,14 @@ import CoreData import CoreDataStack import MastodonSDK +extension Notification.Name { + public static let relationshipChanged = Notification.Name(rawValue: "org.joinmastodon.app.relationship-changed") +} + +extension AnyHashable { + public static let relationship = "relationship" +} + extension APIService { public func relationship( forAccounts accounts: [Mastodon.Entity.Account],