RoomNotificationSettingsEvents -> RoomNotificationSettingsEvent

This commit is contained in:
Benoit Marty 2026-01-27 14:57:53 +01:00
parent 1d7f238f11
commit b6736233ce
6 changed files with 30 additions and 30 deletions

View file

@ -10,10 +10,10 @@ package io.element.android.features.roomdetails.impl.notificationsettings
import io.element.android.libraries.matrix.api.room.RoomNotificationMode import io.element.android.libraries.matrix.api.room.RoomNotificationMode
sealed interface RoomNotificationSettingsEvents { sealed interface RoomNotificationSettingsEvent {
data class ChangeRoomNotificationMode(val mode: RoomNotificationMode) : RoomNotificationSettingsEvents data class ChangeRoomNotificationMode(val mode: RoomNotificationMode) : RoomNotificationSettingsEvent
data class SetNotificationMode(val isDefault: Boolean) : RoomNotificationSettingsEvents data class SetNotificationMode(val isDefault: Boolean) : RoomNotificationSettingsEvent
data object DeleteCustomNotification : RoomNotificationSettingsEvents data object DeleteCustomNotification : RoomNotificationSettingsEvent
data object ClearSetNotificationError : RoomNotificationSettingsEvents data object ClearSetNotificationError : RoomNotificationSettingsEvent
data object ClearRestoreDefaultError : RoomNotificationSettingsEvents data object ClearRestoreDefaultError : RoomNotificationSettingsEvent
} }

View file

@ -100,12 +100,12 @@ class RoomNotificationSettingsPresenter(
!notificationSettingsService.canHomeServerPushEncryptedEventsToDevice().getOrDefault(true) !notificationSettingsService.canHomeServerPushEncryptedEventsToDevice().getOrDefault(true)
} }
fun handleEvent(event: RoomNotificationSettingsEvents) { fun handleEvent(event: RoomNotificationSettingsEvent) {
when (event) { when (event) {
is RoomNotificationSettingsEvents.ChangeRoomNotificationMode -> { is RoomNotificationSettingsEvent.ChangeRoomNotificationMode -> {
localCoroutineScope.setRoomNotificationMode(event.mode, pendingRoomNotificationMode, pendingSetDefault, setNotificationSettingAction) localCoroutineScope.setRoomNotificationMode(event.mode, pendingRoomNotificationMode, pendingSetDefault, setNotificationSettingAction)
} }
is RoomNotificationSettingsEvents.SetNotificationMode -> { is RoomNotificationSettingsEvent.SetNotificationMode -> {
if (event.isDefault) { if (event.isDefault) {
localCoroutineScope.restoreDefaultRoomNotificationMode(restoreDefaultAction, pendingSetDefault) localCoroutineScope.restoreDefaultRoomNotificationMode(restoreDefaultAction, pendingSetDefault)
} else { } else {
@ -114,13 +114,13 @@ class RoomNotificationSettingsPresenter(
} }
} }
} }
is RoomNotificationSettingsEvents.DeleteCustomNotification -> { is RoomNotificationSettingsEvent.DeleteCustomNotification -> {
localCoroutineScope.restoreDefaultRoomNotificationMode(restoreDefaultAction, pendingSetDefault) localCoroutineScope.restoreDefaultRoomNotificationMode(restoreDefaultAction, pendingSetDefault)
} }
RoomNotificationSettingsEvents.ClearSetNotificationError -> { RoomNotificationSettingsEvent.ClearSetNotificationError -> {
setNotificationSettingAction.value = AsyncAction.Uninitialized setNotificationSettingAction.value = AsyncAction.Uninitialized
} }
RoomNotificationSettingsEvents.ClearRestoreDefaultError -> { RoomNotificationSettingsEvent.ClearRestoreDefaultError -> {
restoreDefaultAction.value = AsyncAction.Uninitialized restoreDefaultAction.value = AsyncAction.Uninitialized
} }
} }

View file

@ -23,7 +23,7 @@ data class RoomNotificationSettingsState(
val setNotificationSettingAction: AsyncAction<Unit>, val setNotificationSettingAction: AsyncAction<Unit>,
val restoreDefaultAction: AsyncAction<Unit>, val restoreDefaultAction: AsyncAction<Unit>,
val displayMentionsOnlyDisclaimer: Boolean, val displayMentionsOnlyDisclaimer: Boolean,
val eventSink: (RoomNotificationSettingsEvents) -> Unit val eventSink: (RoomNotificationSettingsEvent) -> Unit
) )
val RoomNotificationSettingsState.displayNotificationMode: RoomNotificationMode? get() { val RoomNotificationSettingsState.displayNotificationMode: RoomNotificationMode? get() {

View file

@ -85,7 +85,7 @@ private fun RoomSpecificNotificationSettingsView(
PreferenceSwitch( PreferenceSwitch(
isChecked = !state.displayIsDefault.orTrue(), isChecked = !state.displayIsDefault.orTrue(),
onCheckedChange = { onCheckedChange = {
state.eventSink(RoomNotificationSettingsEvents.SetNotificationMode(!it)) state.eventSink(RoomNotificationSettingsEvent.SetNotificationMode(!it))
}, },
title = stringResource(id = R.string.screen_room_notification_settings_allow_custom), title = stringResource(id = R.string.screen_room_notification_settings_allow_custom),
subtitle = stringResource(id = R.string.screen_room_notification_settings_allow_custom_footnote), subtitle = stringResource(id = R.string.screen_room_notification_settings_allow_custom_footnote),
@ -138,7 +138,7 @@ private fun RoomSpecificNotificationSettingsView(
enabled = !state.displayIsDefault.orTrue(), enabled = !state.displayIsDefault.orTrue(),
displayMentionsOnlyDisclaimer = state.displayMentionsOnlyDisclaimer, displayMentionsOnlyDisclaimer = state.displayMentionsOnlyDisclaimer,
onSelectOption = { onSelectOption = {
state.eventSink(RoomNotificationSettingsEvents.ChangeRoomNotificationMode(it.mode)) state.eventSink(RoomNotificationSettingsEvent.ChangeRoomNotificationMode(it.mode))
}, },
) )
} }
@ -148,14 +148,14 @@ private fun RoomSpecificNotificationSettingsView(
async = state.setNotificationSettingAction, async = state.setNotificationSettingAction,
onSuccess = {}, onSuccess = {},
errorMessage = { stringResource(R.string.screen_notification_settings_edit_failed_updating_default_mode) }, errorMessage = { stringResource(R.string.screen_notification_settings_edit_failed_updating_default_mode) },
onErrorDismiss = { state.eventSink(RoomNotificationSettingsEvents.ClearSetNotificationError) }, onErrorDismiss = { state.eventSink(RoomNotificationSettingsEvent.ClearSetNotificationError) },
) )
AsyncActionView( AsyncActionView(
async = state.restoreDefaultAction, async = state.restoreDefaultAction,
onSuccess = {}, onSuccess = {},
errorMessage = { stringResource(R.string.screen_notification_settings_edit_failed_updating_default_mode) }, errorMessage = { stringResource(R.string.screen_notification_settings_edit_failed_updating_default_mode) },
onErrorDismiss = { state.eventSink(RoomNotificationSettingsEvents.ClearRestoreDefaultError) }, onErrorDismiss = { state.eventSink(RoomNotificationSettingsEvent.ClearRestoreDefaultError) },
) )
} }
} }

View file

@ -60,7 +60,7 @@ fun UserDefinedRoomNotificationSettingsView(
enabled = !state.displayIsDefault.orTrue(), enabled = !state.displayIsDefault.orTrue(),
displayMentionsOnlyDisclaimer = state.displayMentionsOnlyDisclaimer, displayMentionsOnlyDisclaimer = state.displayMentionsOnlyDisclaimer,
onSelectOption = { onSelectOption = {
state.eventSink(RoomNotificationSettingsEvents.ChangeRoomNotificationMode(it.mode)) state.eventSink(RoomNotificationSettingsEvent.ChangeRoomNotificationMode(it.mode))
}, },
) )
} }
@ -69,7 +69,7 @@ fun UserDefinedRoomNotificationSettingsView(
headlineContent = { Text(stringResource(R.string.screen_room_notification_settings_edit_remove_setting)) }, headlineContent = { Text(stringResource(R.string.screen_room_notification_settings_edit_remove_setting)) },
style = ListItemStyle.Destructive, style = ListItemStyle.Destructive,
onClick = { onClick = {
state.eventSink(RoomNotificationSettingsEvents.DeleteCustomNotification) state.eventSink(RoomNotificationSettingsEvent.DeleteCustomNotification)
} }
) )
@ -77,14 +77,14 @@ fun UserDefinedRoomNotificationSettingsView(
async = state.setNotificationSettingAction, async = state.setNotificationSettingAction,
onSuccess = {}, onSuccess = {},
errorMessage = { stringResource(R.string.screen_notification_settings_edit_failed_updating_default_mode) }, errorMessage = { stringResource(R.string.screen_notification_settings_edit_failed_updating_default_mode) },
onErrorDismiss = { state.eventSink(RoomNotificationSettingsEvents.ClearSetNotificationError) }, onErrorDismiss = { state.eventSink(RoomNotificationSettingsEvent.ClearSetNotificationError) },
) )
AsyncActionView( AsyncActionView(
async = state.restoreDefaultAction, async = state.restoreDefaultAction,
onSuccess = { onBackClick() }, onSuccess = { onBackClick() },
errorMessage = { stringResource(R.string.screen_notification_settings_edit_failed_updating_default_mode) }, errorMessage = { stringResource(R.string.screen_notification_settings_edit_failed_updating_default_mode) },
onErrorDismiss = { state.eventSink(RoomNotificationSettingsEvents.ClearRestoreDefaultError) }, onErrorDismiss = { state.eventSink(RoomNotificationSettingsEvent.ClearRestoreDefaultError) },
) )
} }
} }

View file

@ -45,7 +45,7 @@ class RoomNotificationSettingsPresenterTest {
moleculeFlow(RecompositionMode.Immediate) { moleculeFlow(RecompositionMode.Immediate) {
presenter.present() presenter.present()
}.test { }.test {
awaitItem().eventSink(RoomNotificationSettingsEvents.ChangeRoomNotificationMode(RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY)) awaitItem().eventSink(RoomNotificationSettingsEvent.ChangeRoomNotificationMode(RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY))
val updatedState = consumeItemsUntilPredicate { val updatedState = consumeItemsUntilPredicate {
it.roomNotificationSettings.dataOrNull()?.mode == RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY it.roomNotificationSettings.dataOrNull()?.mode == RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY
}.last() }.last()
@ -78,7 +78,7 @@ class RoomNotificationSettingsPresenterTest {
presenter.present() presenter.present()
}.test { }.test {
val initialState = awaitItem() val initialState = awaitItem()
initialState.eventSink(RoomNotificationSettingsEvents.SetNotificationMode(false)) initialState.eventSink(RoomNotificationSettingsEvent.SetNotificationMode(false))
val failedState = consumeItemsUntilPredicate { val failedState = consumeItemsUntilPredicate {
it.setNotificationSettingAction.isFailure() it.setNotificationSettingAction.isFailure()
}.last() }.last()
@ -87,7 +87,7 @@ class RoomNotificationSettingsPresenterTest {
assertThat(failedState.pendingSetDefault).isNull() assertThat(failedState.pendingSetDefault).isNull()
assertThat(failedState.setNotificationSettingAction.isFailure()).isTrue() assertThat(failedState.setNotificationSettingAction.isFailure()).isTrue()
failedState.eventSink(RoomNotificationSettingsEvents.ClearSetNotificationError) failedState.eventSink(RoomNotificationSettingsEvent.ClearSetNotificationError)
val errorClearedState = consumeItemsUntilPredicate { val errorClearedState = consumeItemsUntilPredicate {
it.setNotificationSettingAction.isUninitialized() it.setNotificationSettingAction.isUninitialized()
@ -104,7 +104,7 @@ class RoomNotificationSettingsPresenterTest {
presenter.present() presenter.present()
}.test { }.test {
val initialState = awaitItem() val initialState = awaitItem()
initialState.eventSink(RoomNotificationSettingsEvents.SetNotificationMode(false)) initialState.eventSink(RoomNotificationSettingsEvent.SetNotificationMode(false))
skipItems(3) skipItems(3)
val defaultState = awaitItem() val defaultState = awaitItem()
assertThat(defaultState.roomNotificationSettings.dataOrNull()?.isDefault).isFalse() assertThat(defaultState.roomNotificationSettings.dataOrNull()?.isDefault).isFalse()
@ -119,8 +119,8 @@ class RoomNotificationSettingsPresenterTest {
presenter.present() presenter.present()
}.test { }.test {
val initialState = awaitItem() val initialState = awaitItem()
initialState.eventSink(RoomNotificationSettingsEvents.ChangeRoomNotificationMode(RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY)) initialState.eventSink(RoomNotificationSettingsEvent.ChangeRoomNotificationMode(RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY))
initialState.eventSink(RoomNotificationSettingsEvents.SetNotificationMode(true)) initialState.eventSink(RoomNotificationSettingsEvent.SetNotificationMode(true))
val defaultState = consumeItemsUntilPredicate { val defaultState = consumeItemsUntilPredicate {
it.roomNotificationSettings.dataOrNull()?.mode == RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY it.roomNotificationSettings.dataOrNull()?.mode == RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY
}.last() }.last()
@ -138,13 +138,13 @@ class RoomNotificationSettingsPresenterTest {
presenter.present() presenter.present()
}.test { }.test {
val initialState = awaitItem() val initialState = awaitItem()
initialState.eventSink(RoomNotificationSettingsEvents.ChangeRoomNotificationMode(RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY)) initialState.eventSink(RoomNotificationSettingsEvent.ChangeRoomNotificationMode(RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY))
initialState.eventSink(RoomNotificationSettingsEvents.SetNotificationMode(true)) initialState.eventSink(RoomNotificationSettingsEvent.SetNotificationMode(true))
val failedState = consumeItemsUntilPredicate { val failedState = consumeItemsUntilPredicate {
it.restoreDefaultAction.isFailure() it.restoreDefaultAction.isFailure()
}.last() }.last()
assertThat(failedState.restoreDefaultAction.isFailure()).isTrue() assertThat(failedState.restoreDefaultAction.isFailure()).isTrue()
failedState.eventSink(RoomNotificationSettingsEvents.ClearRestoreDefaultError) failedState.eventSink(RoomNotificationSettingsEvent.ClearRestoreDefaultError)
val errorClearedState = consumeItemsUntilPredicate { val errorClearedState = consumeItemsUntilPredicate {
it.restoreDefaultAction.isUninitialized() it.restoreDefaultAction.isUninitialized()