commit a0f6bdd8d9362ba95396cb8943af4683803835b8
parent 8feb228ea038abc84835b2bd7e45cdaff365d982
Author: Daniel D’Aquino <daniel@daquino.me>
Date: Mon, 20 May 2024 14:35:03 -0700
Send device token when switching to push notifications mode
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Reviewed-by: William Casarin <jb55@jb55.com>
Diffstat:
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/damus/Util/Router.swift b/damus/Util/Router.swift
@@ -79,7 +79,7 @@ enum Route: Hashable {
case .AppearanceSettings(let settings):
AppearanceSettingsView(damus_state: damusState, settings: settings)
case .NotificationSettings(let settings):
- NotificationSettingsView(settings: settings)
+ NotificationSettingsView(damus_state: damusState, settings: settings)
case .ZapSettings(let settings):
ZapSettingsView(settings: settings)
case .TranslationSettings(let settings):
diff --git a/damus/Views/Settings/NotificationSettingsView.swift b/damus/Views/Settings/NotificationSettingsView.swift
@@ -8,6 +8,7 @@
import SwiftUI
struct NotificationSettingsView: View {
+ let damus_state: DamusState
@ObservedObject var settings: UserSettingsStore
@Environment(\.dismiss) var dismiss
@@ -28,7 +29,15 @@ struct NotificationSettingsView: View {
Form {
if settings.enable_experimental_push_notifications {
Picker(NSLocalizedString("Notifications mode", comment: "Prompt selection of the notification mode (Feature to switch between local notifications (generated from user's own phone) or push notifications (generated by Damus server)."),
- selection: Binding($settings.notifications_mode)
+ selection: Binding(
+ get: { settings.notifications_mode },
+ set: { newValue in
+ settings.notifications_mode = newValue
+ if newValue == .push {
+ Task { try await damus_state.push_notification_client.send_token() }
+ }
+ }
+ )
) {
ForEach(UserSettingsStore.NotificationsMode.allCases, id: \.self) { notification_mode in
Text(notification_mode.text_description())
@@ -76,6 +85,6 @@ struct NotificationSettingsView: View {
struct NotificationSettings_Previews: PreviewProvider {
static var previews: some View {
- NotificationSettingsView(settings: UserSettingsStore())
+ NotificationSettingsView(damus_state: test_damus_state, settings: UserSettingsStore())
}
}