damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 2c84184dbdcf0bb674c0e56c04c98c55584dc4e6
parent 901a6fc98fc1046b52ab0d99f088b00c0137cc93
Author: Daniel D’Aquino <daniel@daquino.me>
Date:   Mon, 20 May 2024 15:23:58 -0700

Improve UX feedback around notification mode setting

Changing the notification mode setting requires successfully sending or
revoking the device token to the server. As this is an action that might
fail, it is important to have a clear UX feedback in case this fails.

Testing
--------

PASS

Device: iPhone 15 simulator
iOS: 17.4
Damus: This commit
strfry-push-notify: d6c2ff289c80e0a90874a7499ed6408394659fc9
Coverage:
1. Checked that push notification mode setting is invisible when experimental push notifications mode is disabled
2. Checked that push notification mode setting is visible when experimental push notifications mode is enabled
3. Checked that switching between push and local notifications sends requests to the server
4. Checked that switching to push notification mode will cause local notifications to be suppressed and push notifications will be sent to the APNS server
5. Checked that switching back to local notification mode will cause local notifications to be displayed, and push notifications will NOT be sent to APNS
6. Checked that if the API server is off, switching from local to push notification modes is not possible and shows an error to the user.
7. Checked that sending APNS payload to Apple's test APNS page will actually deliver the push notification successfully.

Closes: https://github.com/damus-io/damus/issues/1704
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Reviewed-by: William Casarin <jb55@jb55.com>

Diffstat:
Mdamus/Views/Settings/NotificationSettingsView.swift | 62++++++++++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 46 insertions(+), 16 deletions(-)

diff --git a/damus/Views/Settings/NotificationSettingsView.swift b/damus/Views/Settings/NotificationSettingsView.swift @@ -10,6 +10,7 @@ import SwiftUI struct NotificationSettingsView: View { let damus_state: DamusState @ObservedObject var settings: UserSettingsStore + @State var notification_mode_setting_error: String? = nil @Environment(\.dismiss) var dismiss @@ -25,27 +26,56 @@ struct NotificationSettingsView: View { }) } + func try_to_set_notifications_mode(new_value: UserSettingsStore.NotificationsMode) { + notification_mode_setting_error = nil + if new_value == .push { + Task { + do { + try await damus_state.push_notification_client.send_token() + settings.notifications_mode = new_value + } + catch { + notification_mode_setting_error = String(format: NSLocalizedString("Error configuring push notifications with the server: %@", comment: "Error label shown when user tries to enable push notifications but something fails"), error.localizedDescription) + } + } + } + else { + Task { + do { + try await damus_state.push_notification_client.revoke_token() + settings.notifications_mode = new_value + } + catch { + notification_mode_setting_error = String(format: NSLocalizedString("Error disabling push notifications with the server: %@", comment: "Error label shown when user tries to disable push notifications but something fails"), error.localizedDescription) + } + } + } + } + var body: some 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( - get: { settings.notifications_mode }, - set: { newValue in - settings.notifications_mode = newValue - if newValue == .push { - Task { try await damus_state.push_notification_client.send_token() } - } - else { - Task { try await damus_state.push_notification_client.revoke_token() } - } + Section( + header: Text("General", comment: "Section header for general damus notifications user configuration"), + footer: VStack { + if let notification_mode_setting_error { + Text(notification_mode_setting_error) + .foregroundStyle(.damusDangerPrimary) } - ) + } ) { - ForEach(UserSettingsStore.NotificationsMode.allCases, id: \.self) { notification_mode in - Text(notification_mode.text_description()) - .tag(notification_mode.rawValue) - + 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( + get: { settings.notifications_mode }, + set: { newValue in + self.try_to_set_notifications_mode(new_value: newValue) + } + ) + ) { + ForEach(UserSettingsStore.NotificationsMode.allCases, id: \.self) { notification_mode in + Text(notification_mode.text_description()) + .tag(notification_mode.rawValue) + } } } }