From d422bbca500b3c178b0b7f7cd4a128aa0dd9e5cb Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 8 Dec 2023 17:12:55 +0100 Subject: [PATCH] Add support for SAS verification with numbers. --- .../impl/VerifySelfSessionStateProvider.kt | 22 ++++++++------ .../impl/VerifySelfSessionView.kt | 29 +++++++++++++++++-- .../impl/src/main/res/values/localazy.xml | 2 ++ 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/VerifySelfSessionStateProvider.kt b/features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/VerifySelfSessionStateProvider.kt index 913b43dfd3..9115b8b444 100644 --- a/features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/VerifySelfSessionStateProvider.kt +++ b/features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/VerifySelfSessionStateProvider.kt @@ -29,10 +29,10 @@ open class VerifySelfSessionStateProvider : PreviewParameterProvider = aVerificationEmojiList(), - decimals: List = emptyList(), ): SessionVerificationData { - return if (emojiList.isEmpty()) { - SessionVerificationData.Decimals(decimals) - } else { - SessionVerificationData.Emojis(emojiList) - } + return SessionVerificationData.Emojis(emojiList) +} + +private fun aDecimalsSessionVerificationData( + decimals: List = listOf(123, 456, 789), +): SessionVerificationData { + return SessionVerificationData.Decimals(decimals) } private fun aVerifySelfSessionState() = VerifySelfSessionState( diff --git a/features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/VerifySelfSessionView.kt b/features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/VerifySelfSessionView.kt index a81693b9b0..dd0905dc65 100644 --- a/features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/VerifySelfSessionView.kt +++ b/features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/VerifySelfSessionView.kt @@ -19,6 +19,7 @@ package io.element.android.features.verifysession.impl import androidx.activity.compose.BackHandler import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer @@ -104,14 +105,23 @@ private fun HeaderContent(verificationFlowStep: FlowStep, modifier: Modifier = M FlowStep.Initial -> R.string.screen_session_verification_open_existing_session_title FlowStep.Canceled -> CommonStrings.common_verification_cancelled FlowStep.AwaitingOtherDeviceResponse -> R.string.screen_session_verification_waiting_to_accept_title - FlowStep.Ready, is FlowStep.Verifying, FlowStep.Completed -> R.string.screen_session_verification_compare_emojis_title + FlowStep.Ready, + FlowStep.Completed -> R.string.screen_session_verification_compare_emojis_title + is FlowStep.Verifying -> when (verificationFlowStep.data) { + is SessionVerificationData.Decimals -> R.string.screen_session_verification_compare_numbers_title + is SessionVerificationData.Emojis -> R.string.screen_session_verification_compare_emojis_title + } } val subtitleTextId = when (verificationFlowStep) { FlowStep.Initial -> R.string.screen_session_verification_open_existing_session_subtitle FlowStep.Canceled -> R.string.screen_session_verification_cancelled_subtitle FlowStep.AwaitingOtherDeviceResponse -> R.string.screen_session_verification_waiting_to_accept_subtitle - is FlowStep.Verifying, FlowStep.Completed -> R.string.screen_session_verification_compare_emojis_subtitle FlowStep.Ready -> R.string.screen_session_verification_ready_subtitle + FlowStep.Completed -> R.string.screen_session_verification_compare_emojis_subtitle + is FlowStep.Verifying -> when (verificationFlowStep.data) { + is SessionVerificationData.Decimals -> R.string.screen_session_verification_compare_numbers_subtitle + is SessionVerificationData.Emojis -> R.string.screen_session_verification_compare_emojis_subtitle + } } IconTitleSubtitleMolecule( @@ -143,7 +153,20 @@ private fun ContentWaiting(modifier: Modifier = Modifier) { @Composable private fun ContentVerifying(verificationFlowStep: FlowStep.Verifying, modifier: Modifier = Modifier) { when (verificationFlowStep.data) { - is SessionVerificationData.Decimals -> Unit // TODO Render decimals + is SessionVerificationData.Decimals -> { + val text = verificationFlowStep.data.decimals.joinToString(separator = " - ") { it.toString() } + Box( + modifier = modifier.fillMaxWidth(), + contentAlignment = Alignment.Center, + ) { + Text( + text = text, + style = ElementTheme.typography.fontHeadingLgBold, + color = MaterialTheme.colorScheme.primary, + maxLines = 1, + ) + } + } is SessionVerificationData.Emojis -> { // We want each row to have up to 4 emojis val rows = verificationFlowStep.data.emojis.chunked(4) diff --git a/features/verifysession/impl/src/main/res/values/localazy.xml b/features/verifysession/impl/src/main/res/values/localazy.xml index 24b3a7cf26..9b785044d8 100644 --- a/features/verifysession/impl/src/main/res/values/localazy.xml +++ b/features/verifysession/impl/src/main/res/values/localazy.xml @@ -3,6 +3,8 @@ "Something doesn’t seem right. Either the request timed out or the request was denied." "Confirm that the emojis below match those shown on your other session." "Compare emojis" + "Confirm that the numbers below match those shown on your other session." + "Compare numbers" "Your new session is now verified. It has access to your encrypted messages, and other users will see it as trusted." "Prove it’s you in order to access your encrypted message history." "Open an existing session"