diff --git a/features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationPresenter.kt b/features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationPresenter.kt index 90e8a3e598..5ecc500725 100644 --- a/features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationPresenter.kt +++ b/features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationPresenter.kt @@ -93,16 +93,16 @@ class OutgoingVerificationPresenter( observeVerificationService() } - fun handleEvent(event: OutgoingVerificationViewEvents) { + fun handleEvent(event: OutgoingVerificationViewEvent) { Timber.d("Verification user action: ${event::class.simpleName}") when (event) { // Just relay the event to the state machine - OutgoingVerificationViewEvents.RequestVerification -> StateMachineEvent.RequestVerification(verificationRequest) - OutgoingVerificationViewEvents.StartSasVerification -> StateMachineEvent.StartSasVerification - OutgoingVerificationViewEvents.ConfirmVerification -> StateMachineEvent.AcceptChallenge - OutgoingVerificationViewEvents.DeclineVerification -> StateMachineEvent.DeclineChallenge - OutgoingVerificationViewEvents.Cancel -> StateMachineEvent.Cancel - OutgoingVerificationViewEvents.Reset -> StateMachineEvent.Reset + OutgoingVerificationViewEvent.RequestVerification -> StateMachineEvent.RequestVerification(verificationRequest) + OutgoingVerificationViewEvent.StartSasVerification -> StateMachineEvent.StartSasVerification + OutgoingVerificationViewEvent.ConfirmVerification -> StateMachineEvent.AcceptChallenge + OutgoingVerificationViewEvent.DeclineVerification -> StateMachineEvent.DeclineChallenge + OutgoingVerificationViewEvent.Cancel -> StateMachineEvent.Cancel + OutgoingVerificationViewEvent.Reset -> StateMachineEvent.Reset }.let { stateMachineEvent -> stateAndDispatch.dispatchAction(stateMachineEvent) } diff --git a/features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationState.kt b/features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationState.kt index 6ba8a03a7f..5f1d7aa921 100644 --- a/features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationState.kt +++ b/features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationState.kt @@ -16,7 +16,7 @@ import io.element.android.libraries.matrix.api.verification.VerificationRequest data class OutgoingVerificationState( val step: Step, val request: VerificationRequest.Outgoing, - val eventSink: (OutgoingVerificationViewEvents) -> Unit, + val eventSink: (OutgoingVerificationViewEvent) -> Unit, ) { @Stable sealed interface Step { diff --git a/features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationStatePreviewParam.kt b/features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationStatePreviewParam.kt index ee3d5dd7a3..50abe14e9f 100644 --- a/features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationStatePreviewParam.kt +++ b/features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationStatePreviewParam.kt @@ -79,7 +79,7 @@ internal fun anOutgoingSessionVerificationRequest() = VerificationRequest.Outgoi internal fun anOutgoingVerificationState( step: Step = Step.Initial, request: VerificationRequest.Outgoing = anOutgoingSessionVerificationRequest(), - eventSink: (OutgoingVerificationViewEvents) -> Unit = {}, + eventSink: (OutgoingVerificationViewEvent) -> Unit = {}, ) = OutgoingVerificationState( step = step, request = request, diff --git a/features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationView.kt b/features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationView.kt index 978ced6587..c9dc4ef45c 100644 --- a/features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationView.kt +++ b/features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationView.kt @@ -65,13 +65,13 @@ fun OutgoingVerificationView( val step = state.step fun cancelOrResetFlow() { when (step) { - is Step.Canceled -> state.eventSink(OutgoingVerificationViewEvents.Reset) + is Step.Canceled -> state.eventSink(OutgoingVerificationViewEvent.Reset) Step.Initial -> onBack() Step.Completed -> onFinish() - Step.Ready, is Step.AwaitingOtherDeviceResponse -> state.eventSink(OutgoingVerificationViewEvents.Cancel) + Step.Ready, is Step.AwaitingOtherDeviceResponse -> state.eventSink(OutgoingVerificationViewEvent.Cancel) is Step.Verifying -> { if (!step.state.isLoading()) { - state.eventSink(OutgoingVerificationViewEvents.DeclineVerification) + state.eventSink(OutgoingVerificationViewEvent.DeclineVerification) } } else -> Unit @@ -261,7 +261,7 @@ private fun OutgoingVerificationBottomMenu( text = stringResource(CommonStrings.action_start_verification), enabled = !isWaiting, showProgress = isWaiting, - onClick = { eventSink(OutgoingVerificationViewEvents.RequestVerification) }, + onClick = { eventSink(OutgoingVerificationViewEvent.RequestVerification) }, ) InvisibleButton() } @@ -281,7 +281,7 @@ private fun OutgoingVerificationBottomMenu( Button( modifier = Modifier.fillMaxWidth(), text = stringResource(CommonStrings.action_start), - onClick = { eventSink(OutgoingVerificationViewEvents.StartSasVerification) }, + onClick = { eventSink(OutgoingVerificationViewEvent.StartSasVerification) }, ) TextButton( modifier = Modifier.fillMaxWidth(), @@ -299,7 +299,7 @@ private fun OutgoingVerificationBottomMenu( enabled = !isVerifying, showProgress = isVerifying, onClick = { - eventSink(OutgoingVerificationViewEvents.ConfirmVerification) + eventSink(OutgoingVerificationViewEvent.ConfirmVerification) }, ) TextButton( @@ -307,7 +307,7 @@ private fun OutgoingVerificationBottomMenu( text = stringResource(R.string.screen_session_verification_they_dont_match), enabled = !isVerifying, onClick = { - eventSink(OutgoingVerificationViewEvents.DeclineVerification) + eventSink(OutgoingVerificationViewEvent.DeclineVerification) }, ) } diff --git a/features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationViewEvents.kt b/features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationViewEvent.kt similarity index 75% rename from features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationViewEvents.kt rename to features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationViewEvent.kt index 9faab7e790..2edfa21b0c 100644 --- a/features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationViewEvents.kt +++ b/features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationViewEvent.kt @@ -8,11 +8,11 @@ package io.element.android.features.verifysession.impl.outgoing -sealed interface OutgoingVerificationViewEvents { - data object RequestVerification : OutgoingVerificationViewEvents - data object StartSasVerification : OutgoingVerificationViewEvents - data object ConfirmVerification : OutgoingVerificationViewEvents - data object DeclineVerification : OutgoingVerificationViewEvents - data object Cancel : OutgoingVerificationViewEvents - data object Reset : OutgoingVerificationViewEvents +sealed interface OutgoingVerificationViewEvent { + data object RequestVerification : OutgoingVerificationViewEvent + data object StartSasVerification : OutgoingVerificationViewEvent + data object ConfirmVerification : OutgoingVerificationViewEvent + data object DeclineVerification : OutgoingVerificationViewEvent + data object Cancel : OutgoingVerificationViewEvent + data object Reset : OutgoingVerificationViewEvent } diff --git a/features/verifysession/impl/src/test/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationPresenterTest.kt b/features/verifysession/impl/src/test/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationPresenterTest.kt index 577683d12e..e2cb533159 100644 --- a/features/verifysession/impl/src/test/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationPresenterTest.kt +++ b/features/verifysession/impl/src/test/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationPresenterTest.kt @@ -102,7 +102,7 @@ class OutgoingVerificationPresenterTest { val initialState = awaitItem() assertThat(initialState.step).isEqualTo(Step.Initial) val eventSink = initialState.eventSink - eventSink(OutgoingVerificationViewEvents.Cancel) + eventSink(OutgoingVerificationViewEvent.Cancel) assertThat(awaitItem().step).isEqualTo(Step.Exit) } @@ -118,7 +118,7 @@ class OutgoingVerificationPresenterTest { val presenter = createOutgoingVerificationPresenter(service) presenter.test { val state = requestVerificationAndAwaitVerifyingState(service) - state.eventSink(OutgoingVerificationViewEvents.ConfirmVerification) + state.eventSink(OutgoingVerificationViewEvent.ConfirmVerification) // Cancelling assertThat(awaitItem().step).isInstanceOf(Step.Verifying::class.java) service.emitVerificationFlowState(VerificationFlowState.DidFail) @@ -134,7 +134,7 @@ class OutgoingVerificationPresenterTest { ) val presenter = createOutgoingVerificationPresenter(service) presenter.test { - awaitItem().eventSink(OutgoingVerificationViewEvents.RequestVerification) + awaitItem().eventSink(OutgoingVerificationViewEvent.RequestVerification) service.emitVerificationFlowState(VerificationFlowState.DidFail) assertThat(awaitItem().step).isInstanceOf(Step.AwaitingOtherDeviceResponse::class.java) assertThat(awaitItem().step).isEqualTo(Step.Canceled) @@ -151,7 +151,7 @@ class OutgoingVerificationPresenterTest { val presenter = createOutgoingVerificationPresenter(service) presenter.test { val state = requestVerificationAndAwaitVerifyingState(service) - state.eventSink(OutgoingVerificationViewEvents.Cancel) + state.eventSink(OutgoingVerificationViewEvent.Cancel) assertThat(awaitItem().step).isEqualTo(Step.Canceled) } } @@ -181,7 +181,7 @@ class OutgoingVerificationPresenterTest { val state = requestVerificationAndAwaitVerifyingState(service) service.emitVerificationFlowState(VerificationFlowState.DidCancel) assertThat(awaitItem().step).isEqualTo(Step.Canceled) - state.eventSink(OutgoingVerificationViewEvents.Reset) + state.eventSink(OutgoingVerificationViewEvent.Reset) // Went back to initial state assertThat(awaitItem().step).isEqualTo(Step.Initial) cancelAndIgnoreRemainingEvents() @@ -204,7 +204,7 @@ class OutgoingVerificationPresenterTest { service, SessionVerificationData.Emojis(emojis) ) - state.eventSink(OutgoingVerificationViewEvents.ConfirmVerification) + state.eventSink(OutgoingVerificationViewEvent.ConfirmVerification) assertThat(awaitItem().step).isEqualTo( Step.Verifying( SessionVerificationData.Emojis(emojis), @@ -235,7 +235,7 @@ class OutgoingVerificationPresenterTest { ) presenter.test { val state = requestVerificationAndAwaitVerifyingState(service) - state.eventSink(OutgoingVerificationViewEvents.ConfirmVerification) + state.eventSink(OutgoingVerificationViewEvent.ConfirmVerification) assertThat(awaitItem().step).isInstanceOf(Step.Verifying::class.java) service.emitVerificationFlowState(VerificationFlowState.DidFinish) assertThat(awaitItem().step).isEqualTo(Step.Completed) @@ -261,7 +261,7 @@ class OutgoingVerificationPresenterTest { ) presenter.test { val state = requestVerificationAndAwaitVerifyingState(service) - state.eventSink(OutgoingVerificationViewEvents.ConfirmVerification) + state.eventSink(OutgoingVerificationViewEvent.ConfirmVerification) assertThat(awaitItem().step).isInstanceOf(Step.Verifying::class.java) service.emitVerificationFlowState(VerificationFlowState.DidFinish) assertThat(awaitItem().step).isEqualTo(Step.Completed) @@ -286,7 +286,7 @@ class OutgoingVerificationPresenterTest { ) presenter.test { val state = requestVerificationAndAwaitVerifyingState(service) - state.eventSink(OutgoingVerificationViewEvents.ConfirmVerification) + state.eventSink(OutgoingVerificationViewEvent.ConfirmVerification) assertThat(awaitItem().step).isInstanceOf(Step.Verifying::class.java) service.emitVerificationFlowState(VerificationFlowState.DidFinish) // The recovery state never leaves UNKNOWN, so the 10 seconds timeout fires and the flow completes anyway @@ -306,7 +306,7 @@ class OutgoingVerificationPresenterTest { val presenter = createOutgoingVerificationPresenter(service) presenter.test { val state = requestVerificationAndAwaitVerifyingState(service) - state.eventSink(OutgoingVerificationViewEvents.DeclineVerification) + state.eventSink(OutgoingVerificationViewEvent.DeclineVerification) assertThat(awaitItem().step).isEqualTo( Step.Verifying( SessionVerificationData.Emojis(emptyList()), @@ -362,7 +362,7 @@ class OutgoingVerificationPresenterTest { ): OutgoingVerificationState { var state = awaitItem() assertThat(state.step).isEqualTo(Step.Initial) - state.eventSink(OutgoingVerificationViewEvents.RequestVerification) + state.eventSink(OutgoingVerificationViewEvent.RequestVerification) testScope.advanceUntilIdle() // Await for other device response: fakeService.emitVerificationFlowState(VerificationFlowState.DidAcceptVerificationRequest) @@ -371,7 +371,7 @@ class OutgoingVerificationPresenterTest { // Await for the state to be Ready state = awaitItem() assertThat(state.step).isEqualTo(Step.Ready) - state.eventSink(OutgoingVerificationViewEvents.StartSasVerification) + state.eventSink(OutgoingVerificationViewEvent.StartSasVerification) testScope.advanceUntilIdle() // Await for other device response (again): fakeService.emitVerificationFlowState(VerificationFlowState.DidStartSasVerification) diff --git a/features/verifysession/impl/src/test/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationViewTest.kt b/features/verifysession/impl/src/test/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationViewTest.kt index 2b5ec63ced..a186c56f3f 100644 --- a/features/verifysession/impl/src/test/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationViewTest.kt +++ b/features/verifysession/impl/src/test/kotlin/io/element/android/features/verifysession/impl/outgoing/OutgoingVerificationViewTest.kt @@ -29,7 +29,7 @@ import org.junit.Test class OutgoingVerificationViewTest : RobolectricTest() { @Test fun `back key pressed - when canceled resets the flow`() = runAndroidComposeUiTest { - val eventsRecorder = EventsRecorder() + val eventsRecorder = EventsRecorder() setOutgoingVerificationView( anOutgoingVerificationState( step = OutgoingVerificationState.Step.Canceled, @@ -37,12 +37,12 @@ class OutgoingVerificationViewTest : RobolectricTest() { ), ) pressBackKey() - eventsRecorder.assertSingle(OutgoingVerificationViewEvents.Reset) + eventsRecorder.assertSingle(OutgoingVerificationViewEvent.Reset) } @Test fun `back key pressed - when awaiting response cancels the verification`() = runAndroidComposeUiTest { - val eventsRecorder = EventsRecorder() + val eventsRecorder = EventsRecorder() setOutgoingVerificationView( anOutgoingVerificationState( step = OutgoingVerificationState.Step.AwaitingOtherDeviceResponse, @@ -50,12 +50,12 @@ class OutgoingVerificationViewTest : RobolectricTest() { ), ) pressBackKey() - eventsRecorder.assertSingle(OutgoingVerificationViewEvents.Cancel) + eventsRecorder.assertSingle(OutgoingVerificationViewEvent.Cancel) } @Test fun `back key pressed - when ready to verify cancels the verification`() = runAndroidComposeUiTest { - val eventsRecorder = EventsRecorder() + val eventsRecorder = EventsRecorder() setOutgoingVerificationView( anOutgoingVerificationState( step = OutgoingVerificationState.Step.Ready, @@ -63,12 +63,12 @@ class OutgoingVerificationViewTest : RobolectricTest() { ), ) pressBackKey() - eventsRecorder.assertSingle(OutgoingVerificationViewEvents.Cancel) + eventsRecorder.assertSingle(OutgoingVerificationViewEvent.Cancel) } @Test fun `back key pressed - when verifying and not loading declines the verification`() = runAndroidComposeUiTest { - val eventsRecorder = EventsRecorder() + val eventsRecorder = EventsRecorder() setOutgoingVerificationView( anOutgoingVerificationState( step = OutgoingVerificationState.Step.Verifying( @@ -79,12 +79,12 @@ class OutgoingVerificationViewTest : RobolectricTest() { ), ) pressBackKey() - eventsRecorder.assertSingle(OutgoingVerificationViewEvents.DeclineVerification) + eventsRecorder.assertSingle(OutgoingVerificationViewEvent.DeclineVerification) } @Test fun `back key pressed - when verifying and loading does nothing`() = runAndroidComposeUiTest { - val eventsRecorder = EventsRecorder() + val eventsRecorder = EventsRecorder() setOutgoingVerificationView( anOutgoingVerificationState( step = OutgoingVerificationState.Step.Verifying( @@ -113,7 +113,7 @@ class OutgoingVerificationViewTest : RobolectricTest() { @Test fun `when flow is completed and the user clicks on the done button, the expected callback is invoked`() = runAndroidComposeUiTest { - val eventsRecorder = EventsRecorder(expectEvents = false) + val eventsRecorder = EventsRecorder(expectEvents = false) ensureCalledOnce { callback -> setOutgoingVerificationView( anOutgoingVerificationState( @@ -128,7 +128,7 @@ class OutgoingVerificationViewTest : RobolectricTest() { @Test fun `clicking on they match emits the expected event`() = runAndroidComposeUiTest { - val eventsRecorder = EventsRecorder() + val eventsRecorder = EventsRecorder() setOutgoingVerificationView( anOutgoingVerificationState( step = OutgoingVerificationState.Step.Verifying( @@ -139,12 +139,12 @@ class OutgoingVerificationViewTest : RobolectricTest() { ), ) clickOn(R.string.screen_session_verification_they_match) - eventsRecorder.assertSingle(OutgoingVerificationViewEvents.ConfirmVerification) + eventsRecorder.assertSingle(OutgoingVerificationViewEvent.ConfirmVerification) } @Test fun `clicking on they do not match emits the expected event`() = runAndroidComposeUiTest { - val eventsRecorder = EventsRecorder() + val eventsRecorder = EventsRecorder() setOutgoingVerificationView( anOutgoingVerificationState( step = OutgoingVerificationState.Step.Verifying( @@ -155,7 +155,7 @@ class OutgoingVerificationViewTest : RobolectricTest() { ), ) clickOn(R.string.screen_session_verification_they_dont_match) - eventsRecorder.assertSingle(OutgoingVerificationViewEvents.DeclineVerification) + eventsRecorder.assertSingle(OutgoingVerificationViewEvent.DeclineVerification) } private fun AndroidComposeUiTest.setOutgoingVerificationView(