deps(sdk) : add fallbackToServer on userIdentity api.

This commit is contained in:
ganfra 2025-11-24 20:22:11 +01:00
parent 9f24048e96
commit 8a599a1e51
3 changed files with 8 additions and 17 deletions

View file

@ -64,8 +64,6 @@ interface EncryptionService {
*/ */
suspend fun startIdentityReset(): Result<IdentityResetHandle?> suspend fun startIdentityReset(): Result<IdentityResetHandle?>
suspend fun isUserVerified(userId: UserId): Result<Boolean>
/** /**
* Remember this identity, ensuring it does not result in a pin violation. * Remember this identity, ensuring it does not result in a pin violation.
*/ */
@ -82,8 +80,10 @@ interface EncryptionService {
/** /**
* Get the identity state of a user, if known. * Get the identity state of a user, if known.
* @param userId the user id to get the identity for.
* @param fallbackToServer whether to fallback to fetching the identity from the server if not known locally. Defaults to true.
*/ */
suspend fun getUserIdentity(userId: UserId): Result<IdentityState?> suspend fun getUserIdentity(userId: UserId, fallbackToServer: Boolean = true): Result<IdentityState?>
} }
/** /**

View file

@ -240,10 +240,6 @@ class RustEncryptionService(
} }
} }
override suspend fun isUserVerified(userId: UserId): Result<Boolean> = runCatchingExceptions {
getUserIdentityInternal(userId).isVerified()
}
override suspend fun pinUserIdentity(userId: UserId): Result<Unit> = runCatchingExceptions { override suspend fun pinUserIdentity(userId: UserId): Result<Unit> = runCatchingExceptions {
getUserIdentityInternal(userId).pin() getUserIdentityInternal(userId).pin()
} }
@ -252,8 +248,8 @@ class RustEncryptionService(
getUserIdentityInternal(userId).withdrawVerification() getUserIdentityInternal(userId).withdrawVerification()
} }
override suspend fun getUserIdentity(userId: UserId): Result<IdentityState?> = runCatchingExceptions { override suspend fun getUserIdentity(userId: UserId, fallbackToServer: Boolean): Result<IdentityState?> = runCatchingExceptions {
val identity = getUserIdentityInternal(userId) val identity = getUserIdentityInternal(userId, fallbackToServer)
val isVerified = identity.isVerified() val isVerified = identity.isVerified()
when { when {
identity.hasVerificationViolation() -> IdentityState.VerificationViolation identity.hasVerificationViolation() -> IdentityState.VerificationViolation
@ -263,10 +259,10 @@ class RustEncryptionService(
} }
} }
suspend fun getUserIdentityInternal(userId: UserId): UserIdentity { private suspend fun getUserIdentityInternal(userId: UserId, fallbackToServer: Boolean = true): UserIdentity {
return service.userIdentity( return service.userIdentity(
userId = userId.value, userId = userId.value,
// requestFromHomeserverIfNeeded = true, fallbackToServer = fallbackToServer,
) ?: error("User identity not found") ) ?: error("User identity not found")
} }

View file

@ -26,7 +26,6 @@ import kotlinx.coroutines.flow.flowOf
class FakeEncryptionService( class FakeEncryptionService(
var startIdentityResetLambda: () -> Result<IdentityResetHandle?> = { lambdaError() }, var startIdentityResetLambda: () -> Result<IdentityResetHandle?> = { lambdaError() },
private val pinUserIdentityResult: (UserId) -> Result<Unit> = { lambdaError() }, private val pinUserIdentityResult: (UserId) -> Result<Unit> = { lambdaError() },
private val isUserVerifiedResult: (UserId) -> Result<Boolean> = { lambdaError() },
private val withdrawVerificationResult: (UserId) -> Result<Unit> = { lambdaError() }, private val withdrawVerificationResult: (UserId) -> Result<Unit> = { lambdaError() },
private val getUserIdentityResult: (UserId) -> Result<IdentityState?> = { lambdaError() }, private val getUserIdentityResult: (UserId) -> Result<IdentityState?> = { lambdaError() },
private val enableRecoveryLambda: (Boolean) -> Result<Unit> = { lambdaError() }, private val enableRecoveryLambda: (Boolean) -> Result<Unit> = { lambdaError() },
@ -139,11 +138,7 @@ class FakeEncryptionService(
return withdrawVerificationResult(userId) return withdrawVerificationResult(userId)
} }
override suspend fun isUserVerified(userId: UserId): Result<Boolean> = simulateLongTask { override suspend fun getUserIdentity(userId: UserId, fallbackToServer: Boolean): Result<IdentityState?> = simulateLongTask {
isUserVerifiedResult(userId)
}
override suspend fun getUserIdentity(userId: UserId): Result<IdentityState?> = simulateLongTask {
return getUserIdentityResult(userId) return getUserIdentityResult(userId)
} }