Skip to content

Commit a7ab8ee

Browse files
committed
Self verification : makes sure cancellation works properly
1 parent fbce600 commit a7ab8ee

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

features/verifysession/impl/src/main/kotlin/io/element/android/features/verifysession/impl/VerifySelfSessionView.kt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,9 @@ fun VerifySelfSessionView(
7070
onSuccessLogout: (String?) -> Unit,
7171
modifier: Modifier = Modifier,
7272
) {
73-
fun resetFlow() {
74-
state.eventSink(VerifySelfSessionViewEvents.Reset)
75-
}
76-
77-
val latestOnFinish by rememberUpdatedState(newValue = onFinish)
78-
LaunchedEffect(state.verificationFlowStep, latestOnFinish) {
79-
if (state.verificationFlowStep is FlowStep.Skipped) {
80-
latestOnFinish()
81-
}
82-
}
83-
BackHandler {
73+
fun cancelOrResetFlow() {
8474
when (state.verificationFlowStep) {
85-
is FlowStep.Canceled -> resetFlow()
75+
is FlowStep.Canceled -> state.eventSink(VerifySelfSessionViewEvents.Reset)
8676
is FlowStep.AwaitingOtherDeviceResponse, FlowStep.Ready -> state.eventSink(VerifySelfSessionViewEvents.Cancel)
8777
is FlowStep.Verifying -> {
8878
if (!state.verificationFlowStep.state.isLoading()) {
@@ -92,6 +82,16 @@ fun VerifySelfSessionView(
9282
else -> Unit
9383
}
9484
}
85+
86+
val latestOnFinish by rememberUpdatedState(newValue = onFinish)
87+
LaunchedEffect(state.verificationFlowStep, latestOnFinish) {
88+
if (state.verificationFlowStep is FlowStep.Skipped) {
89+
latestOnFinish()
90+
}
91+
}
92+
BackHandler {
93+
cancelOrResetFlow()
94+
}
9595
val verificationFlowStep = state.verificationFlowStep
9696

9797
if (state.verificationFlowStep is FlowStep.Loading ||
@@ -133,9 +133,9 @@ fun VerifySelfSessionView(
133133
footer = {
134134
BottomMenu(
135135
screenState = state,
136-
goBack = ::resetFlow,
136+
onCancelClick = ::cancelOrResetFlow,
137137
onEnterRecoveryKey = onEnterRecoveryKey,
138-
onFinish = onFinish,
138+
onContinueClick = onFinish,
139139
onResetKey = onResetKey,
140140
)
141141
}
@@ -268,8 +268,8 @@ private fun BottomMenu(
268268
screenState: VerifySelfSessionState,
269269
onEnterRecoveryKey: () -> Unit,
270270
onResetKey: () -> Unit,
271-
goBack: () -> Unit,
272-
onFinish: () -> Unit,
271+
onCancelClick: () -> Unit,
272+
onContinueClick: () -> Unit,
273273
) {
274274
val verificationViewState = screenState.verificationFlowStep
275275
val eventSink = screenState.eventSink
@@ -316,7 +316,7 @@ private fun BottomMenu(
316316
TextButton(
317317
modifier = Modifier.fillMaxWidth(),
318318
text = stringResource(CommonStrings.action_cancel),
319-
onClick = goBack,
319+
onClick = onCancelClick,
320320
)
321321
}
322322
}
@@ -330,7 +330,7 @@ private fun BottomMenu(
330330
TextButton(
331331
modifier = Modifier.fillMaxWidth(),
332332
text = stringResource(CommonStrings.action_cancel),
333-
onClick = goBack,
333+
onClick = onCancelClick,
334334
)
335335
}
336336
}
@@ -375,7 +375,7 @@ private fun BottomMenu(
375375
Button(
376376
modifier = Modifier.fillMaxWidth(),
377377
text = stringResource(CommonStrings.action_continue),
378-
onClick = onFinish,
378+
onClick = onContinueClick,
379379
)
380380
// Placeholder so the 1st button keeps its vertical position
381381
Spacer(modifier = Modifier.height(48.dp))

libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/verification/RustSessionVerificationService.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,19 @@ class RustSessionVerificationService(
9797
updateVerificationStatus()
9898
}
9999
}
100-
.launchIn(sessionCoroutineScope)
100+
.launchIn(sessionCoroutineScope)
101101
}
102102

103103
override suspend fun requestVerification() = tryOrFail {
104104
initVerificationControllerIfNeeded()
105105
verificationController.requestVerification()
106106
}
107107

108-
override suspend fun cancelVerification() = tryOrFail { verificationController.cancelVerification() }
108+
override suspend fun cancelVerification() = tryOrFail {
109+
verificationController.cancelVerification()
110+
// We need to manually set the state to canceled, as the Rust SDK doesn't always call `didCancel` when it should
111+
didCancel()
112+
}
109113

110114
override suspend fun approveVerification() = tryOrFail { verificationController.approveVerification() }
111115

0 commit comments

Comments
 (0)