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