mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-10-31 16:22:49 +00:00
StartChatEvents -> StartChatEvent
This commit is contained in:
+3
-3
@@ -10,7 +10,7 @@ package io.element.android.features.startchat.impl.root
|
||||
|
||||
import io.element.android.libraries.matrix.api.user.MatrixUser
|
||||
|
||||
sealed interface StartChatEvents {
|
||||
data class StartDM(val matrixUser: MatrixUser) : StartChatEvents
|
||||
data object CancelStartDM : StartChatEvents
|
||||
sealed interface StartChatEvent {
|
||||
data class StartDM(val matrixUser: MatrixUser) : StartChatEvent
|
||||
data object CancelStartDM : StartChatEvent
|
||||
}
|
||||
+3
-3
@@ -49,16 +49,16 @@ class StartChatPresenter(
|
||||
val localCoroutineScope = rememberCoroutineScope()
|
||||
val startDmActionState: MutableState<AsyncAction<RoomId>> = remember { mutableStateOf(AsyncAction.Uninitialized) }
|
||||
|
||||
fun handleEvent(event: StartChatEvents) {
|
||||
fun handleEvent(event: StartChatEvent) {
|
||||
when (event) {
|
||||
is StartChatEvents.StartDM -> localCoroutineScope.launch {
|
||||
is StartChatEvent.StartDM -> localCoroutineScope.launch {
|
||||
startDMAction.execute(
|
||||
matrixUser = event.matrixUser,
|
||||
createIfDmDoesNotExist = startDmActionState.value is AsyncAction.Confirming,
|
||||
actionState = startDmActionState,
|
||||
)
|
||||
}
|
||||
StartChatEvents.CancelStartDM -> startDmActionState.value = AsyncAction.Uninitialized
|
||||
StartChatEvent.CancelStartDM -> startDmActionState.value = AsyncAction.Uninitialized
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -16,5 +16,5 @@ data class StartChatState(
|
||||
val applicationName: String,
|
||||
val userListState: UserListState,
|
||||
val startDmAction: AsyncAction<RoomId>,
|
||||
val eventSink: (StartChatEvents) -> Unit,
|
||||
val eventSink: (StartChatEvent) -> Unit,
|
||||
)
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ fun aCreateRoomRootState(
|
||||
applicationName: String = "Element X Preview",
|
||||
userListState: UserListState = aUserListState(),
|
||||
startDmAction: AsyncAction<RoomId> = AsyncAction.Uninitialized,
|
||||
eventSink: (StartChatEvents) -> Unit = {},
|
||||
eventSink: (StartChatEvent) -> Unit = {},
|
||||
) = StartChatState(
|
||||
applicationName = applicationName,
|
||||
userListState = userListState,
|
||||
|
||||
+6
-6
@@ -94,7 +94,7 @@ fun StartChatView(
|
||||
onSelectUser = {
|
||||
coroutineScope.launch {
|
||||
view.hideKeyboardAndAwaitAnimation()
|
||||
state.eventSink(StartChatEvents.StartDM(it))
|
||||
state.eventSink(StartChatEvent.StartDM(it))
|
||||
}
|
||||
},
|
||||
onDeselectUser = { },
|
||||
@@ -124,21 +124,21 @@ fun StartChatView(
|
||||
errorMessage = { stringResource(R.string.screen_start_chat_error_starting_chat) },
|
||||
onRetry = {
|
||||
state.userListState.selectedUsers.firstOrNull()
|
||||
?.let { state.eventSink(StartChatEvents.StartDM(it)) }
|
||||
?.let { state.eventSink(StartChatEvent.StartDM(it)) }
|
||||
// Cancel start DM if there is no more selected user (should not happen)
|
||||
?: state.eventSink(StartChatEvents.CancelStartDM)
|
||||
?: state.eventSink(StartChatEvent.CancelStartDM)
|
||||
},
|
||||
onErrorDismiss = { state.eventSink(StartChatEvents.CancelStartDM) },
|
||||
onErrorDismiss = { state.eventSink(StartChatEvent.CancelStartDM) },
|
||||
confirmationDialog = { data ->
|
||||
if (data is ConfirmingStartDmWithMatrixUser) {
|
||||
CreateDmConfirmationBottomSheet(
|
||||
matrixUser = data.matrixUser,
|
||||
isUserIdentityUnknown = data.isUserIdentityUnknown,
|
||||
onSendInvite = {
|
||||
state.eventSink(StartChatEvents.StartDM(data.matrixUser))
|
||||
state.eventSink(StartChatEvent.StartDM(data.matrixUser))
|
||||
},
|
||||
onDismiss = {
|
||||
state.eventSink(StartChatEvents.CancelStartDM)
|
||||
state.eventSink(StartChatEvent.CancelStartDM)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
+7
-7
@@ -53,7 +53,7 @@ class StartChatPresenterTest {
|
||||
assertThat(initialState.userListState.isSearchActive).isFalse()
|
||||
assertThat(initialState.userListState.isMultiSelectionEnabled).isFalse()
|
||||
val matrixUser = MatrixUser(UserId("@name:domain"))
|
||||
initialState.eventSink(StartChatEvents.StartDM(matrixUser))
|
||||
initialState.eventSink(StartChatEvent.StartDM(matrixUser))
|
||||
awaitItem().also { state ->
|
||||
assertThat(state.startDmAction).isEqualTo(startDMFailureResult)
|
||||
executeResult.assertions().isCalledOnce().with(
|
||||
@@ -61,7 +61,7 @@ class StartChatPresenterTest {
|
||||
value(false),
|
||||
any(),
|
||||
)
|
||||
state.eventSink(StartChatEvents.CancelStartDM)
|
||||
state.eventSink(StartChatEvent.CancelStartDM)
|
||||
}
|
||||
awaitItem().also { state ->
|
||||
assertThat(state.startDmAction.isUninitialized()).isTrue()
|
||||
@@ -85,7 +85,7 @@ class StartChatPresenterTest {
|
||||
assertThat(initialState.userListState.isSearchActive).isFalse()
|
||||
assertThat(initialState.userListState.isMultiSelectionEnabled).isFalse()
|
||||
val matrixUser = MatrixUser(UserId("@name:domain"))
|
||||
initialState.eventSink(StartChatEvents.StartDM(matrixUser))
|
||||
initialState.eventSink(StartChatEvent.StartDM(matrixUser))
|
||||
awaitItem().also { state ->
|
||||
assertThat(state.startDmAction).isEqualTo(startDMSuccessResult)
|
||||
executeResult.assertions().isCalledOnce().with(
|
||||
@@ -109,7 +109,7 @@ class StartChatPresenterTest {
|
||||
presenter.test {
|
||||
val initialState = awaitItem()
|
||||
assertThat(initialState.startDmAction).isInstanceOf(AsyncAction.Uninitialized::class.java)
|
||||
initialState.eventSink(StartChatEvents.StartDM(matrixUser))
|
||||
initialState.eventSink(StartChatEvent.StartDM(matrixUser))
|
||||
val confirmingState = awaitItem()
|
||||
assertThat(confirmingState.startDmAction).isEqualTo(startDMConfirmationResult)
|
||||
executeResult.assertions().isCalledOnce().with(
|
||||
@@ -118,7 +118,7 @@ class StartChatPresenterTest {
|
||||
any(),
|
||||
)
|
||||
// Cancelling should not create the DM
|
||||
confirmingState.eventSink(StartChatEvents.CancelStartDM)
|
||||
confirmingState.eventSink(StartChatEvent.CancelStartDM)
|
||||
val finalState = awaitItem()
|
||||
assertThat(finalState.startDmAction.isUninitialized()).isTrue()
|
||||
executeResult.assertions().isCalledExactly(1)
|
||||
@@ -137,7 +137,7 @@ class StartChatPresenterTest {
|
||||
presenter.test {
|
||||
val initialState = awaitItem()
|
||||
assertThat(initialState.startDmAction).isInstanceOf(AsyncAction.Uninitialized::class.java)
|
||||
initialState.eventSink(StartChatEvents.StartDM(matrixUser))
|
||||
initialState.eventSink(StartChatEvent.StartDM(matrixUser))
|
||||
val confirmingState = awaitItem()
|
||||
assertThat(confirmingState.startDmAction).isEqualTo(startDMConfirmationResult)
|
||||
executeResult.assertions().isCalledOnce().with(
|
||||
@@ -146,7 +146,7 @@ class StartChatPresenterTest {
|
||||
any(),
|
||||
)
|
||||
// Start DM again should invoke the action with createIfDmDoesNotExist = true
|
||||
confirmingState.eventSink(StartChatEvents.StartDM(matrixUser))
|
||||
confirmingState.eventSink(StartChatEvent.StartDM(matrixUser))
|
||||
executeResult.assertions().isCalledExactly(2).withSequence(
|
||||
listOf(value(matrixUser), value(false), any()),
|
||||
listOf(value(matrixUser), value(true), any()),
|
||||
|
||||
+6
-6
@@ -36,7 +36,7 @@ import org.robolectric.annotation.Config
|
||||
class StartChatViewTest : RobolectricTest() {
|
||||
@Test
|
||||
fun `clicking on back invokes the expected callback`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<StartChatEvents>(expectEvents = false)
|
||||
val eventsRecorder = EventsRecorder<StartChatEvent>(expectEvents = false)
|
||||
ensureCalledOnce {
|
||||
setStartChatView(
|
||||
aCreateRoomRootState(
|
||||
@@ -50,7 +50,7 @@ class StartChatViewTest : RobolectricTest() {
|
||||
|
||||
@Test
|
||||
fun `clicking on New room invokes the expected callback`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<StartChatEvents>(expectEvents = false)
|
||||
val eventsRecorder = EventsRecorder<StartChatEvent>(expectEvents = false)
|
||||
ensureCalledOnce {
|
||||
setStartChatView(
|
||||
aCreateRoomRootState(
|
||||
@@ -65,7 +65,7 @@ class StartChatViewTest : RobolectricTest() {
|
||||
@Config(qualifiers = "h1024dp")
|
||||
@Test
|
||||
fun `clicking on Invite people invokes the expected callback`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<StartChatEvents>(expectEvents = false)
|
||||
val eventsRecorder = EventsRecorder<StartChatEvent>(expectEvents = false)
|
||||
ensureCalledOnce {
|
||||
setStartChatView(
|
||||
aCreateRoomRootState(
|
||||
@@ -84,7 +84,7 @@ class StartChatViewTest : RobolectricTest() {
|
||||
fun `clicking on a user suggestion invokes the expected callback`() = runAndroidComposeUiTest {
|
||||
val recentDirectRoomList = aRecentDirectRoomList()
|
||||
val firstRoom = recentDirectRoomList[0]
|
||||
val eventsRecorder = EventsRecorder<StartChatEvents>(expectEvents = false)
|
||||
val eventsRecorder = EventsRecorder<StartChatEvent>(expectEvents = false)
|
||||
ensureCalledOnceWithParam(firstRoom.roomId) {
|
||||
setStartChatView(
|
||||
aCreateRoomRootState(
|
||||
@@ -102,7 +102,7 @@ class StartChatViewTest : RobolectricTest() {
|
||||
@Config(qualifiers = "h1024dp")
|
||||
@Test
|
||||
fun `clicking on Join room by address invokes the expected callback`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<StartChatEvents>(expectEvents = false)
|
||||
val eventsRecorder = EventsRecorder<StartChatEvent>(expectEvents = false)
|
||||
ensureCalledOnce {
|
||||
setStartChatView(
|
||||
aCreateRoomRootState(
|
||||
@@ -116,7 +116,7 @@ class StartChatViewTest : RobolectricTest() {
|
||||
|
||||
@Test
|
||||
fun `clicking on room directory invokes the expected callback`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<StartChatEvents>(expectEvents = false)
|
||||
val eventsRecorder = EventsRecorder<StartChatEvent>(expectEvents = false)
|
||||
ensureCalledOnce {
|
||||
setStartChatView(
|
||||
aCreateRoomRootState(
|
||||
|
||||
Reference in New Issue
Block a user