Merge pull request #1955 from vector-im/feature/bma/notificationForInvites
Add setting to disable notification for invites
This commit is contained in:
commit
8f5fed48ab
19 changed files with 100 additions and 38 deletions
|
|
@ -17,11 +17,11 @@
|
|||
package io.element.android.features.preferences.impl.notifications
|
||||
|
||||
sealed interface NotificationSettingsEvents {
|
||||
|
||||
data object RefreshSystemNotificationsEnabled : NotificationSettingsEvents
|
||||
data class SetNotificationsEnabled(val enabled: Boolean) : NotificationSettingsEvents
|
||||
data class SetAtRoomNotificationsEnabled(val enabled: Boolean) : NotificationSettingsEvents
|
||||
data class SetCallNotificationsEnabled(val enabled: Boolean) : NotificationSettingsEvents
|
||||
data class SetInviteForMeNotificationsEnabled(val enabled: Boolean) : NotificationSettingsEvents
|
||||
data object FixConfigurationMismatch : NotificationSettingsEvents
|
||||
data object ClearConfigurationMismatchError : NotificationSettingsEvents
|
||||
data object ClearNotificationChangeError : NotificationSettingsEvents
|
||||
|
|
|
|||
|
|
@ -76,6 +76,9 @@ class NotificationSettingsPresenter @Inject constructor(
|
|||
is NotificationSettingsEvents.SetCallNotificationsEnabled -> {
|
||||
localCoroutineScope.setCallNotificationsEnabled(event.enabled, changeNotificationSettingAction)
|
||||
}
|
||||
is NotificationSettingsEvents.SetInviteForMeNotificationsEnabled -> {
|
||||
localCoroutineScope.setInviteForMeNotificationsEnabled(event.enabled, changeNotificationSettingAction)
|
||||
}
|
||||
is NotificationSettingsEvents.SetNotificationsEnabled -> localCoroutineScope.setNotificationsEnabled(userPushStore, event.enabled)
|
||||
NotificationSettingsEvents.ClearConfigurationMismatchError -> {
|
||||
matrixSettings.value = NotificationSettingsState.MatrixSettings.Invalid(fixFailed = false)
|
||||
|
|
@ -123,10 +126,12 @@ class NotificationSettingsPresenter @Inject constructor(
|
|||
|
||||
val callNotificationsEnabled = notificationSettingsService.isCallEnabled().getOrThrow()
|
||||
val atRoomNotificationsEnabled = notificationSettingsService.isRoomMentionEnabled().getOrThrow()
|
||||
val inviteForMeNotificationsEnabled = notificationSettingsService.isInviteForMeEnabled().getOrThrow()
|
||||
|
||||
target.value = NotificationSettingsState.MatrixSettings.Valid(
|
||||
atRoomNotificationsEnabled = atRoomNotificationsEnabled,
|
||||
callNotificationsEnabled = callNotificationsEnabled,
|
||||
inviteForMeNotificationsEnabled = inviteForMeNotificationsEnabled,
|
||||
defaultGroupNotificationMode = encryptedGroupDefaultMode,
|
||||
defaultOneToOneNotificationMode = encryptedOneToOneDefaultMode,
|
||||
)
|
||||
|
|
@ -175,6 +180,12 @@ class NotificationSettingsPresenter @Inject constructor(
|
|||
}.runCatchingUpdatingState(action)
|
||||
}
|
||||
|
||||
private fun CoroutineScope.setInviteForMeNotificationsEnabled(enabled: Boolean, action: MutableState<Async<Unit>>) = launch {
|
||||
suspend {
|
||||
notificationSettingsService.setInviteForMeEnabled(enabled).getOrThrow()
|
||||
}.runCatchingUpdatingState(action)
|
||||
}
|
||||
|
||||
private fun CoroutineScope.setNotificationsEnabled(userPushStore: UserPushStore, enabled: Boolean) = launch {
|
||||
userPushStore.setNotificationEnabledForDevice(enabled)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ data class NotificationSettingsState(
|
|||
data class Valid(
|
||||
val atRoomNotificationsEnabled: Boolean,
|
||||
val callNotificationsEnabled: Boolean,
|
||||
val inviteForMeNotificationsEnabled: Boolean,
|
||||
val defaultGroupNotificationMode: RoomNotificationMode?,
|
||||
val defaultOneToOneNotificationMode: RoomNotificationMode?,
|
||||
) : MatrixSettings
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ fun aNotificationSettingsState(
|
|||
matrixSettings = NotificationSettingsState.MatrixSettings.Valid(
|
||||
atRoomNotificationsEnabled = true,
|
||||
callNotificationsEnabled = true,
|
||||
inviteForMeNotificationsEnabled = true,
|
||||
defaultGroupNotificationMode = RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY,
|
||||
defaultOneToOneNotificationMode = RoomNotificationMode.ALL_MESSAGES,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ fun NotificationSettingsView(
|
|||
onMentionNotificationsChanged = { state.eventSink(NotificationSettingsEvents.SetAtRoomNotificationsEnabled(it)) },
|
||||
// TODO We are removing the call notification toggle until support for call notifications has been added
|
||||
// onCallsNotificationsChanged = { state.eventSink(NotificationSettingsEvents.SetCallNotificationsEnabled(it)) },
|
||||
onInviteForMeNotificationsChanged = { state.eventSink(NotificationSettingsEvents.SetInviteForMeNotificationsEnabled(it)) },
|
||||
)
|
||||
}
|
||||
AsyncView(
|
||||
|
|
@ -98,6 +99,7 @@ private fun NotificationSettingsContentView(
|
|||
onMentionNotificationsChanged: (Boolean) -> Unit,
|
||||
// TODO We are removing the call notification toggle until support for call notifications has been added
|
||||
// onCallsNotificationsChanged: (Boolean) -> Unit,
|
||||
onInviteForMeNotificationsChanged: (Boolean) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
|
|
@ -147,8 +149,8 @@ private fun NotificationSettingsContentView(
|
|||
onCheckedChange = onMentionNotificationsChanged
|
||||
)
|
||||
}
|
||||
// TODO We are removing the call notification toggle until support for call notifications has been added
|
||||
// PreferenceCategory(title = stringResource(id = CommonStrings.screen_notification_settings_additional_settings_section_title)) {
|
||||
PreferenceCategory(title = stringResource(id = R.string.screen_notification_settings_additional_settings_section_title)) {
|
||||
// TODO We are removing the call notification toggle until support for call notifications has been added
|
||||
// PreferenceSwitch(
|
||||
// modifier = Modifier,
|
||||
// title = stringResource(id = CommonStrings.screen_notification_settings_calls_label),
|
||||
|
|
@ -156,7 +158,14 @@ private fun NotificationSettingsContentView(
|
|||
// switchAlignment = Alignment.Top,
|
||||
// onCheckedChange = onCallsNotificationsChanged
|
||||
// )
|
||||
// }
|
||||
PreferenceSwitch(
|
||||
modifier = Modifier,
|
||||
title = stringResource(id = R.string.screen_notification_settings_invite_for_me_label),
|
||||
isChecked = matrixSettings.inviteForMeNotificationsEnabled,
|
||||
switchAlignment = Alignment.Top,
|
||||
onCheckedChange = onInviteForMeNotificationsChanged
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue