Fix unverified account after account creation (#5914)
* Fix unverified account after account creation: When we create an account either using OIDC or by importing a login and password one, we need to wait until the verification state is known (either verified or unverified). The problem is the verification service will return incorrect values until the E2EE tasks are initialized in the SDK, even if we add the state listeners after doing so. So what we can do is initialize the E2EE setup, discard any invalid verification state received while it's not initialized, and take only those received after it's initialized. * Actually restore the `Client` in `RustMatrixAuthenticationService.importCreatedSession` so we don't need to use `clear` and have the navigation restore the client later: This standarizes the way the login/registration flow works, always restoring/reusing the existing client instance
This commit is contained in:
parent
105bab1758
commit
4f1fd33b47
5 changed files with 68 additions and 44 deletions
|
|
@ -19,24 +19,18 @@ import dev.zacsweers.metro.AssistedFactory
|
|||
import dev.zacsweers.metro.AssistedInject
|
||||
import io.element.android.libraries.architecture.AsyncAction
|
||||
import io.element.android.libraries.architecture.Presenter
|
||||
import io.element.android.libraries.core.data.tryOrNull
|
||||
import io.element.android.libraries.core.extensions.flatMap
|
||||
import io.element.android.libraries.core.extensions.runCatchingExceptions
|
||||
import io.element.android.libraries.core.meta.BuildMeta
|
||||
import io.element.android.libraries.matrix.api.MatrixClientProvider
|
||||
import io.element.android.libraries.matrix.api.auth.MatrixAuthenticationService
|
||||
import io.element.android.libraries.matrix.api.core.SessionId
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withTimeout
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
@AssistedInject
|
||||
class CreateAccountPresenter(
|
||||
@Assisted private val url: String,
|
||||
private val authenticationService: MatrixAuthenticationService,
|
||||
private val clientProvider: MatrixClientProvider,
|
||||
private val messageParser: MessageParser,
|
||||
private val buildMeta: BuildMeta,
|
||||
) : Presenter<CreateAccountState> {
|
||||
|
|
@ -80,12 +74,6 @@ class CreateAccountPresenter(
|
|||
}.flatMap { externalSession ->
|
||||
authenticationService.importCreatedSession(externalSession)
|
||||
}.onSuccess { sessionId ->
|
||||
tryOrNull {
|
||||
// Wait until the session is verified
|
||||
val client = clientProvider.getOrRestore(sessionId).getOrThrow()
|
||||
val sessionVerificationService = client.sessionVerificationService
|
||||
withTimeout(10.seconds) { sessionVerificationService.sessionVerifiedStatus.first { it.isVerified() } }
|
||||
}
|
||||
loggedInState.value = AsyncAction.Success(sessionId)
|
||||
}.onFailure { failure ->
|
||||
loggedInState.value = AsyncAction.Failure(failure)
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@ import io.element.android.libraries.matrix.api.auth.external.ExternalSession
|
|||
import io.element.android.libraries.matrix.api.verification.SessionVerifiedStatus
|
||||
import io.element.android.libraries.matrix.test.AN_EXCEPTION
|
||||
import io.element.android.libraries.matrix.test.A_SESSION_ID
|
||||
import io.element.android.libraries.matrix.test.FakeMatrixClient
|
||||
import io.element.android.libraries.matrix.test.FakeMatrixClientProvider
|
||||
import io.element.android.libraries.matrix.test.auth.FakeMatrixAuthenticationService
|
||||
import io.element.android.libraries.matrix.test.core.aBuildMeta
|
||||
import io.element.android.libraries.matrix.test.verification.FakeSessionVerificationService
|
||||
|
|
@ -80,14 +78,11 @@ class CreateAccountPresenterTest {
|
|||
fun `present - receiving a message able to be parsed change the state to success`() = runTest {
|
||||
val lambda = lambdaRecorder<String, ExternalSession> { _ -> anExternalSession() }
|
||||
val sessionVerificationService = FakeSessionVerificationService()
|
||||
val client = FakeMatrixClient(sessionVerificationService = sessionVerificationService)
|
||||
val clientProvider = FakeMatrixClientProvider(getClient = { Result.success(client) })
|
||||
val presenter = createPresenter(
|
||||
authenticationService = FakeMatrixAuthenticationService(
|
||||
importCreatedSessionLambda = { Result.success(A_SESSION_ID) }
|
||||
),
|
||||
messageParser = FakeMessageParser(lambda),
|
||||
clientProvider = clientProvider,
|
||||
)
|
||||
presenter.test {
|
||||
val initialState = awaitItem()
|
||||
|
|
@ -120,12 +115,10 @@ class CreateAccountPresenterTest {
|
|||
authenticationService: MatrixAuthenticationService = FakeMatrixAuthenticationService(),
|
||||
messageParser: MessageParser = FakeMessageParser(),
|
||||
buildMeta: BuildMeta = aBuildMeta(),
|
||||
clientProvider: FakeMatrixClientProvider = FakeMatrixClientProvider(),
|
||||
) = CreateAccountPresenter(
|
||||
url = url,
|
||||
authenticationService = authenticationService,
|
||||
messageParser = messageParser,
|
||||
buildMeta = buildMeta,
|
||||
clientProvider = clientProvider,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue