diff --git a/NotificationExtension/NotificationService.swift b/NotificationExtension/NotificationService.swift index 3b9a4883..be2c6e43 100644 --- a/NotificationExtension/NotificationService.swift +++ b/NotificationExtension/NotificationService.swift @@ -109,6 +109,12 @@ class NotificationService: UNNotificationServiceExtension { kindStr = "📊 Poll finished" case .update: kindStr = "✏️ Edited" + case .emojiReaction: + if let emoji = notification.emoji { + kindStr = "\(emoji) Reacted" + } else { + kindStr = nil + } default: kindStr = nil } diff --git a/Packages/InstanceFeatures/Sources/InstanceFeatures/InstanceFeatures.swift b/Packages/InstanceFeatures/Sources/InstanceFeatures/InstanceFeatures.swift index 1d795a55..5ba74c2e 100644 --- a/Packages/InstanceFeatures/Sources/InstanceFeatures/InstanceFeatures.swift +++ b/Packages/InstanceFeatures/Sources/InstanceFeatures/InstanceFeatures.swift @@ -213,6 +213,10 @@ public final class InstanceFeatures: ObservableObject { hasMastodonVersion(3, 1, 0) } + public var emojiReactionNotifications: Bool { + instanceType.isPleroma + } + public init() { } diff --git a/Packages/Pachyderm/Sources/Pachyderm/Model/PushSubscription.swift b/Packages/Pachyderm/Sources/Pachyderm/Model/PushSubscription.swift index d0405dcb..62608f1b 100644 --- a/Packages/Pachyderm/Sources/Pachyderm/Model/PushSubscription.swift +++ b/Packages/Pachyderm/Sources/Pachyderm/Model/PushSubscription.swift @@ -44,6 +44,7 @@ public struct PushSubscription: Decodable, Sendable { "data[alerts][favourite]" => alerts.favourite, "data[alerts][poll]" => alerts.poll, "data[alerts][update]" => alerts.update, + "data[alerts][pleroma:emoji_reaction]" => alerts.emojiReaction, "data[policy]" => policy.rawValue, ])) } @@ -58,6 +59,7 @@ public struct PushSubscription: Decodable, Sendable { "data[alerts][favourite]" => alerts.favourite, "data[alerts][poll]" => alerts.poll, "data[alerts][update]" => alerts.update, + "data[alerts][pleroma:emoji_reaction]" => alerts.emojiReaction, "data[policy]" => policy.rawValue, ])) } @@ -85,8 +87,19 @@ extension PushSubscription { public let favourite: Bool public let poll: Bool public let update: Bool - - public init(mention: Bool, status: Bool, reblog: Bool, follow: Bool, followRequest: Bool, favourite: Bool, poll: Bool, update: Bool) { + public let emojiReaction: Bool + + public init( + mention: Bool, + status: Bool, + reblog: Bool, + follow: Bool, + followRequest: Bool, + favourite: Bool, + poll: Bool, + update: Bool, + emojiReaction: Bool + ) { self.mention = mention self.status = status self.reblog = reblog @@ -95,6 +108,7 @@ extension PushSubscription { self.favourite = favourite self.poll = poll self.update = update + self.emojiReaction = emojiReaction } public init(from decoder: any Decoder) throws { @@ -110,6 +124,8 @@ extension PushSubscription { self.poll = try container.decode(Bool.self, forKey: PushSubscription.Alerts.CodingKeys.poll) // update added in mastodon 3.5.0 self.update = try container.decodeIfPresent(Bool.self, forKey: PushSubscription.Alerts.CodingKeys.update) ?? false + // pleroma/akkoma only + self.emojiReaction = try container.decodeIfPresent(Bool.self, forKey: .emojiReaction) ?? false } private enum CodingKeys: String, CodingKey { @@ -121,6 +137,7 @@ extension PushSubscription { case favourite case poll case update + case emojiReaction = "pleroma:emoji_reaction" } } } diff --git a/Packages/PushNotifications/Sources/PushNotifications/PushSubscription.swift b/Packages/PushNotifications/Sources/PushNotifications/PushSubscription.swift index d7cf1b0c..8eb41186 100644 --- a/Packages/PushNotifications/Sources/PushNotifications/PushSubscription.swift +++ b/Packages/PushNotifications/Sources/PushNotifications/PushSubscription.swift @@ -70,6 +70,7 @@ public struct PushSubscription { public static let favorite = Alerts(rawValue: 1 << 5) public static let poll = Alerts(rawValue: 1 << 6) public static let update = Alerts(rawValue: 1 << 7) + public static let emojiReaction = Alerts(rawValue: 1 << 8) public let rawValue: Int diff --git a/Tusker/API/MastodonController+Push.swift b/Tusker/API/MastodonController+Push.swift index 0acb5817..892a8fb4 100644 --- a/Tusker/API/MastodonController+Push.swift +++ b/Tusker/API/MastodonController+Push.swift @@ -58,7 +58,8 @@ private extension Pachyderm.PushSubscription.Alerts { followRequest: alerts.contains(.followRequest), favourite: alerts.contains(.favorite), poll: alerts.contains(.poll), - update: alerts.contains(.update) + update: alerts.contains(.update), + emojiReaction: alerts.contains(.emojiReaction) ) } } diff --git a/Tusker/Screens/Preferences/Notifications/PushSubscriptionView.swift b/Tusker/Screens/Preferences/Notifications/PushSubscriptionView.swift index 936cbf32..9a7da2e3 100644 --- a/Tusker/Screens/Preferences/Notifications/PushSubscriptionView.swift +++ b/Tusker/Screens/Preferences/Notifications/PushSubscriptionView.swift @@ -74,6 +74,9 @@ private struct PushSubscriptionSettingsView: View { if mastodonController.instanceFeatures.pushNotificationTypeUpdate { toggle("Edits", alert: .update) } + if mastodonController.instanceFeatures.emojiReactionNotifications { + toggle("Reactions", alert: .emojiReaction) + } // status notifications not supported until we can enable/disable them in the app } } @@ -81,14 +84,17 @@ private struct PushSubscriptionSettingsView: View { } private var allSupportedAlertTypes: PushSubscription.Alerts { - var alerts: PushSubscription.Alerts = [.mention, .favorite, .reblog, .follow, .poll] + var all: PushSubscription.Alerts = [.mention, .favorite, .reblog, .follow, .poll] if mastodonController.instanceFeatures.pushNotificationTypeFollowRequest { - alerts.insert(.followRequest) + all.insert(.followRequest) } if mastodonController.instanceFeatures.pushNotificationTypeUpdate { - alerts.insert(.update) + all.insert(.update) } - return alerts + if mastodonController.instanceFeatures.emojiReactionNotifications { + all.insert(.emojiReaction) + } + return all } private func toggle(_ titleKey: LocalizedStringKey, alert: PushSubscription.Alerts) -> some View {