Sign out: handle no network error.

This commit is contained in:
Benoit Marty 2023-10-31 17:47:27 +01:00 committed by Benoit Marty
parent 4fb825b5cb
commit 2f62779ad4
6 changed files with 98 additions and 11 deletions

View file

@ -37,6 +37,7 @@ import org.matrix.rustcomponents.sdk.BackupState as RustBackupState
import org.matrix.rustcomponents.sdk.BackupUploadState as RustBackupUploadState
import org.matrix.rustcomponents.sdk.EnableRecoveryProgress as RustEnableRecoveryProgress
import org.matrix.rustcomponents.sdk.RecoveryState as RustRecoveryState
import org.matrix.rustcomponents.sdk.SteadyStateException as RustSteadyStateException
internal class RustEncryptionService(
client: Client,
@ -49,6 +50,7 @@ internal class RustEncryptionService(
private val recoveryStateMapper = RecoveryStateMapper()
private val enableRecoveryProgressMapper = EnableRecoveryProgressMapper()
private val backupUploadStateMapper = BackupUploadStateMapper()
private val steadyStateExceptionMapper = SteadyStateExceptionMapper()
override val backupStateStateFlow: MutableStateFlow<BackupState> = MutableStateFlow(service.backupState().let(backupStateMapper::map))
override val recoveryStateStateFlow: MutableStateFlow<RecoveryState> = MutableStateFlow(service.recoveryState().let(recoveryStateMapper::map))
@ -98,16 +100,25 @@ internal class RustEncryptionService(
override fun waitForBackupUploadSteadyState(): Flow<BackupUploadState> {
return callbackFlow {
service.waitForBackupUploadSteadyState(
progressListener = object : BackupSteadyStateListener {
override fun onUpdate(status: RustBackupUploadState) {
trySend(backupUploadStateMapper.map(status))
if (status == RustBackupUploadState.Done) {
close()
runCatching {
service.waitForBackupUploadSteadyState(
progressListener = object : BackupSteadyStateListener {
override fun onUpdate(status: RustBackupUploadState) {
trySend(backupUploadStateMapper.map(status))
if (status == RustBackupUploadState.Done) {
close()
}
}
}
)
}.onFailure {
if (it is RustSteadyStateException) {
trySend(BackupUploadState.SteadyException(steadyStateExceptionMapper.map(it)))
} else {
trySend(BackupUploadState.Error)
}
)
close(it)
}
awaitClose {}
}
}

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2023 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.libraries.matrix.impl.encryption
import io.element.android.libraries.matrix.api.encryption.SteadyStateException
import org.matrix.rustcomponents.sdk.SteadyStateException as RustSteadyStateException
class SteadyStateExceptionMapper {
fun map(data: RustSteadyStateException): SteadyStateException {
return when (data) {
is RustSteadyStateException.BackupDisabled -> SteadyStateException.BackupDisabled(
message = data.message
)
is RustSteadyStateException.Connection -> SteadyStateException.Connection(
message = data.message
)
is RustSteadyStateException.Laged -> SteadyStateException.Lagged(
message = data.message
)
}
}
}