Support emoji reaction push notifications on pleroma/akkoma

This commit is contained in:
Shadowfacts 2024-04-18 13:17:55 -04:00
parent 6f35fd2676
commit a589bb2863
6 changed files with 42 additions and 7 deletions

View File

@ -109,6 +109,12 @@ class NotificationService: UNNotificationServiceExtension {
kindStr = "📊 Poll finished" kindStr = "📊 Poll finished"
case .update: case .update:
kindStr = "✏️ Edited" kindStr = "✏️ Edited"
case .emojiReaction:
if let emoji = notification.emoji {
kindStr = "\(emoji) Reacted"
} else {
kindStr = nil
}
default: default:
kindStr = nil kindStr = nil
} }

View File

@ -213,6 +213,10 @@ public final class InstanceFeatures: ObservableObject {
hasMastodonVersion(3, 1, 0) hasMastodonVersion(3, 1, 0)
} }
public var emojiReactionNotifications: Bool {
instanceType.isPleroma
}
public init() { public init() {
} }

View File

@ -44,6 +44,7 @@ public struct PushSubscription: Decodable, Sendable {
"data[alerts][favourite]" => alerts.favourite, "data[alerts][favourite]" => alerts.favourite,
"data[alerts][poll]" => alerts.poll, "data[alerts][poll]" => alerts.poll,
"data[alerts][update]" => alerts.update, "data[alerts][update]" => alerts.update,
"data[alerts][pleroma:emoji_reaction]" => alerts.emojiReaction,
"data[policy]" => policy.rawValue, "data[policy]" => policy.rawValue,
])) ]))
} }
@ -58,6 +59,7 @@ public struct PushSubscription: Decodable, Sendable {
"data[alerts][favourite]" => alerts.favourite, "data[alerts][favourite]" => alerts.favourite,
"data[alerts][poll]" => alerts.poll, "data[alerts][poll]" => alerts.poll,
"data[alerts][update]" => alerts.update, "data[alerts][update]" => alerts.update,
"data[alerts][pleroma:emoji_reaction]" => alerts.emojiReaction,
"data[policy]" => policy.rawValue, "data[policy]" => policy.rawValue,
])) ]))
} }
@ -85,8 +87,19 @@ extension PushSubscription {
public let favourite: Bool public let favourite: Bool
public let poll: Bool public let poll: Bool
public let update: Bool public let update: Bool
public let emojiReaction: Bool
public init(mention: Bool, status: Bool, reblog: Bool, follow: Bool, followRequest: Bool, favourite: Bool, poll: Bool, update: 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.mention = mention
self.status = status self.status = status
self.reblog = reblog self.reblog = reblog
@ -95,6 +108,7 @@ extension PushSubscription {
self.favourite = favourite self.favourite = favourite
self.poll = poll self.poll = poll
self.update = update self.update = update
self.emojiReaction = emojiReaction
} }
public init(from decoder: any Decoder) throws { 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) self.poll = try container.decode(Bool.self, forKey: PushSubscription.Alerts.CodingKeys.poll)
// update added in mastodon 3.5.0 // update added in mastodon 3.5.0
self.update = try container.decodeIfPresent(Bool.self, forKey: PushSubscription.Alerts.CodingKeys.update) ?? false 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 { private enum CodingKeys: String, CodingKey {
@ -121,6 +137,7 @@ extension PushSubscription {
case favourite case favourite
case poll case poll
case update case update
case emojiReaction = "pleroma:emoji_reaction"
} }
} }
} }

View File

@ -70,6 +70,7 @@ public struct PushSubscription {
public static let favorite = Alerts(rawValue: 1 << 5) public static let favorite = Alerts(rawValue: 1 << 5)
public static let poll = Alerts(rawValue: 1 << 6) public static let poll = Alerts(rawValue: 1 << 6)
public static let update = Alerts(rawValue: 1 << 7) public static let update = Alerts(rawValue: 1 << 7)
public static let emojiReaction = Alerts(rawValue: 1 << 8)
public let rawValue: Int public let rawValue: Int

View File

@ -58,7 +58,8 @@ private extension Pachyderm.PushSubscription.Alerts {
followRequest: alerts.contains(.followRequest), followRequest: alerts.contains(.followRequest),
favourite: alerts.contains(.favorite), favourite: alerts.contains(.favorite),
poll: alerts.contains(.poll), poll: alerts.contains(.poll),
update: alerts.contains(.update) update: alerts.contains(.update),
emojiReaction: alerts.contains(.emojiReaction)
) )
} }
} }

View File

@ -74,6 +74,9 @@ private struct PushSubscriptionSettingsView: View {
if mastodonController.instanceFeatures.pushNotificationTypeUpdate { if mastodonController.instanceFeatures.pushNotificationTypeUpdate {
toggle("Edits", alert: .update) 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 // 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 { 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 { if mastodonController.instanceFeatures.pushNotificationTypeFollowRequest {
alerts.insert(.followRequest) all.insert(.followRequest)
} }
if mastodonController.instanceFeatures.pushNotificationTypeUpdate { 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 { private func toggle(_ titleKey: LocalizedStringKey, alert: PushSubscription.Alerts) -> some View {