Only offer to verify if a cross-signed device is available (#5433)
* Only offer to verify if a cross-signed device is available * Fix tests * use the right exception mapper * adjust flag name and logic in ChooseSelfVerificationState * add comment * switch order of states to match previous logic
This commit is contained in:
parent
7095b460b3
commit
d2e5b43674
10 changed files with 47 additions and 14 deletions
|
|
@ -21,6 +21,7 @@ import io.element.android.libraries.matrix.api.encryption.IdentityResetHandle
|
|||
import io.element.android.libraries.matrix.api.encryption.RecoveryState
|
||||
import io.element.android.libraries.matrix.api.encryption.identity.IdentityState
|
||||
import io.element.android.libraries.matrix.api.sync.SyncState
|
||||
import io.element.android.libraries.matrix.impl.exception.mapClientException
|
||||
import io.element.android.libraries.matrix.impl.sync.RustSyncService
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.channels.awaitClose
|
||||
|
|
@ -96,6 +97,20 @@ internal class RustEncryptionService(
|
|||
}
|
||||
.stateIn(sessionCoroutineScope, SharingStarted.Eagerly, false)
|
||||
|
||||
/**
|
||||
* Check if the user has any devices available to verify against every 5 seconds.
|
||||
* TODO This is a temporary workaround, when we will have a way to observe
|
||||
* the sessions, this code will have to be updated.
|
||||
*/
|
||||
override val hasDevicesToVerifyAgainst: StateFlow<Boolean> = flow {
|
||||
while (currentCoroutineContext().isActive) {
|
||||
val result = hasDevicesToVerifyAgainst().getOrDefault(false)
|
||||
emit(result)
|
||||
delay(5_000)
|
||||
}
|
||||
}
|
||||
.stateIn(sessionCoroutineScope, SharingStarted.Eagerly, false)
|
||||
|
||||
override suspend fun enableBackups(): Result<Unit> = withContext(dispatchers.io) {
|
||||
runCatchingExceptions {
|
||||
service.enableBackups()
|
||||
|
|
@ -171,6 +186,14 @@ internal class RustEncryptionService(
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun hasDevicesToVerifyAgainst(): Result<Boolean> = withContext(dispatchers.io) {
|
||||
runCatchingExceptions {
|
||||
service.hasDevicesToVerifyAgainst()
|
||||
}.mapFailure {
|
||||
it.mapClientException()
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun resetRecoveryKey(): Result<String> = withContext(dispatchers.io) {
|
||||
runCatchingExceptions {
|
||||
service.resetRecoveryKey()
|
||||
|
|
|
|||
|
|
@ -32,6 +32,10 @@ class FakeFfiEncryption : Encryption(NoPointer) {
|
|||
return false
|
||||
}
|
||||
|
||||
override suspend fun hasDevicesToVerifyAgainst(): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun backupState(): BackupState {
|
||||
return BackupState.ENABLED
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue