mirror of
git://jb55.com/damus
synced 2024-09-28 16:00:43 +00:00
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>
This commit is contained in:
parent
901a6fc98f
commit
2c84184dbd
@ -10,6 +10,7 @@ import SwiftUI
|
|||||||
struct NotificationSettingsView: View {
|
struct NotificationSettingsView: View {
|
||||||
let damus_state: DamusState
|
let damus_state: DamusState
|
||||||
@ObservedObject var settings: UserSettingsStore
|
@ObservedObject var settings: UserSettingsStore
|
||||||
|
@State var notification_mode_setting_error: String? = nil
|
||||||
|
|
||||||
@Environment(\.dismiss) var dismiss
|
@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 {
|
var body: some View {
|
||||||
Form {
|
Form {
|
||||||
if settings.enable_experimental_push_notifications {
|
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)."),
|
Section(
|
||||||
selection: Binding(
|
header: Text("General", comment: "Section header for general damus notifications user configuration"),
|
||||||
get: { settings.notifications_mode },
|
footer: VStack {
|
||||||
set: { newValue in
|
if let notification_mode_setting_error {
|
||||||
settings.notifications_mode = newValue
|
Text(notification_mode_setting_error)
|
||||||
if newValue == .push {
|
.foregroundStyle(.damusDangerPrimary)
|
||||||
Task { try await damus_state.push_notification_client.send_token() }
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Task { try await damus_state.push_notification_client.revoke_token() }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
}
|
||||||
) {
|
) {
|
||||||
ForEach(UserSettingsStore.NotificationsMode.allCases, id: \.self) { notification_mode in
|
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)."),
|
||||||
Text(notification_mode.text_description())
|
selection: Binding(
|
||||||
.tag(notification_mode.rawValue)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user