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
sealed interface RoomNotificationSettingsEvents {
data class ChangeRoomNotificationMode(val mode: RoomNotificationMode) : RoomNotificationSettingsEvents
data class SetNotificationMode(val isDefault: Boolean) : RoomNotificationSettingsEvents
data object DeleteCustomNotification : RoomNotificationSettingsEvents
data object ClearSetNotificationError : RoomNotificationSettingsEvents
data object ClearRestoreDefaultError : RoomNotificationSettingsEvents
sealed interface RoomNotificationSettingsEvent {
data class ChangeRoomNotificationMode(val mode: RoomNotificationMode) : RoomNotificationSettingsEvent
data class SetNotificationMode(val isDefault: Boolean) : RoomNotificationSettingsEvent
data object DeleteCustomNotification : RoomNotificationSettingsEvent
data object ClearSetNotificationError : RoomNotificationSettingsEvent
data object ClearRestoreDefaultError : RoomNotificationSettingsEvent
}

View File

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

View File

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

View File

@@ -85,7 +85,7 @@ private fun RoomSpecificNotificationSettingsView(
PreferenceSwitch(
isChecked = !state.displayIsDefault.orTrue(),
onCheckedChange = {
state.eventSink(RoomNotificationSettingsEvents.SetNotificationMode(!it))
state.eventSink(RoomNotificationSettingsEvent.SetNotificationMode(!it))
},
title = stringResource(id = R.string.screen_room_notification_settings_allow_custom),
subtitle = stringResource(id = R.string.screen_room_notification_settings_allow_custom_footnote),
@@ -138,7 +138,7 @@ private fun RoomSpecificNotificationSettingsView(
enabled = !state.displayIsDefault.orTrue(),
displayMentionsOnlyDisclaimer = state.displayMentionsOnlyDisclaimer,
onSelectOption = {
state.eventSink(RoomNotificationSettingsEvents.ChangeRoomNotificationMode(it.mode))
state.eventSink(RoomNotificationSettingsEvent.ChangeRoomNotificationMode(it.mode))
},
)
}
@@ -148,14 +148,14 @@ private fun RoomSpecificNotificationSettingsView(
async = state.setNotificationSettingAction,
onSuccess = {},
errorMessage = { stringResource(R.string.screen_notification_settings_edit_failed_updating_default_mode) },
onErrorDismiss = { state.eventSink(RoomNotificationSettingsEvents.ClearSetNotificationError) },
onErrorDismiss = { state.eventSink(RoomNotificationSettingsEvent.ClearSetNotificationError) },
)
AsyncActionView(
async = state.restoreDefaultAction,
onSuccess = {},
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(),
displayMentionsOnlyDisclaimer = state.displayMentionsOnlyDisclaimer,
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)) },
style = ListItemStyle.Destructive,
onClick = {
state.eventSink(RoomNotificationSettingsEvents.DeleteCustomNotification)
state.eventSink(RoomNotificationSettingsEvent.DeleteCustomNotification)
}
)
@@ -77,14 +77,14 @@ fun UserDefinedRoomNotificationSettingsView(
async = state.setNotificationSettingAction,
onSuccess = {},
errorMessage = { stringResource(R.string.screen_notification_settings_edit_failed_updating_default_mode) },
onErrorDismiss = { state.eventSink(RoomNotificationSettingsEvents.ClearSetNotificationError) },
onErrorDismiss = { state.eventSink(RoomNotificationSettingsEvent.ClearSetNotificationError) },
)
AsyncActionView(
async = state.restoreDefaultAction,
onSuccess = { onBackClick() },
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) {
presenter.present()
}.test {
awaitItem().eventSink(RoomNotificationSettingsEvents.ChangeRoomNotificationMode(RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY))
awaitItem().eventSink(RoomNotificationSettingsEvent.ChangeRoomNotificationMode(RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY))
val updatedState = consumeItemsUntilPredicate {
it.roomNotificationSettings.dataOrNull()?.mode == RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY
}.last()
@@ -78,7 +78,7 @@ class RoomNotificationSettingsPresenterTest {
presenter.present()
}.test {
val initialState = awaitItem()
initialState.eventSink(RoomNotificationSettingsEvents.SetNotificationMode(false))
initialState.eventSink(RoomNotificationSettingsEvent.SetNotificationMode(false))
val failedState = consumeItemsUntilPredicate {
it.setNotificationSettingAction.isFailure()
}.last()
@@ -87,7 +87,7 @@ class RoomNotificationSettingsPresenterTest {
assertThat(failedState.pendingSetDefault).isNull()
assertThat(failedState.setNotificationSettingAction.isFailure()).isTrue()
failedState.eventSink(RoomNotificationSettingsEvents.ClearSetNotificationError)
failedState.eventSink(RoomNotificationSettingsEvent.ClearSetNotificationError)
val errorClearedState = consumeItemsUntilPredicate {
it.setNotificationSettingAction.isUninitialized()
@@ -104,7 +104,7 @@ class RoomNotificationSettingsPresenterTest {
presenter.present()
}.test {
val initialState = awaitItem()
initialState.eventSink(RoomNotificationSettingsEvents.SetNotificationMode(false))
initialState.eventSink(RoomNotificationSettingsEvent.SetNotificationMode(false))
skipItems(3)
val defaultState = awaitItem()
assertThat(defaultState.roomNotificationSettings.dataOrNull()?.isDefault).isFalse()
@@ -119,8 +119,8 @@ class RoomNotificationSettingsPresenterTest {
presenter.present()
}.test {
val initialState = awaitItem()
initialState.eventSink(RoomNotificationSettingsEvents.ChangeRoomNotificationMode(RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY))
initialState.eventSink(RoomNotificationSettingsEvents.SetNotificationMode(true))
initialState.eventSink(RoomNotificationSettingsEvent.ChangeRoomNotificationMode(RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY))
initialState.eventSink(RoomNotificationSettingsEvent.SetNotificationMode(true))
val defaultState = consumeItemsUntilPredicate {
it.roomNotificationSettings.dataOrNull()?.mode == RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY
}.last()
@@ -138,13 +138,13 @@ class RoomNotificationSettingsPresenterTest {
presenter.present()
}.test {
val initialState = awaitItem()
initialState.eventSink(RoomNotificationSettingsEvents.ChangeRoomNotificationMode(RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY))
initialState.eventSink(RoomNotificationSettingsEvents.SetNotificationMode(true))
initialState.eventSink(RoomNotificationSettingsEvent.ChangeRoomNotificationMode(RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY))
initialState.eventSink(RoomNotificationSettingsEvent.SetNotificationMode(true))
val failedState = consumeItemsUntilPredicate {
it.restoreDefaultAction.isFailure()
}.last()
assertThat(failedState.restoreDefaultAction.isFailure()).isTrue()
failedState.eventSink(RoomNotificationSettingsEvents.ClearRestoreDefaultError)
failedState.eventSink(RoomNotificationSettingsEvent.ClearRestoreDefaultError)
val errorClearedState = consumeItemsUntilPredicate {
it.restoreDefaultAction.isUninitialized()