diff --git a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/members/RoomMemberListPresenter.kt b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/members/RoomMemberListPresenter.kt index e69ddb744a..9274c1a8e5 100644 --- a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/members/RoomMemberListPresenter.kt +++ b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/members/RoomMemberListPresenter.kt @@ -179,7 +179,7 @@ class RoomMemberListPresenter( return if (room.info().isEncrypted != true) { RoomMemberWithIdentityState(this, null) } else { - val identityState = identityStates[userId] ?: encryptionService.getUserIdentity(userId).getOrNull() + val identityState = identityStates[userId] ?: encryptionService.getUserIdentity(userId, fallbackToServer = false).getOrNull() RoomMemberWithIdentityState(this, identityState) } } diff --git a/features/userprofile/impl/src/test/kotlin/io/element/android/features/userprofile/impl/UserProfilePresenterTest.kt b/features/userprofile/impl/src/test/kotlin/io/element/android/features/userprofile/impl/UserProfilePresenterTest.kt index 8dcf6aab20..aa984f0066 100644 --- a/features/userprofile/impl/src/test/kotlin/io/element/android/features/userprofile/impl/UserProfilePresenterTest.kt +++ b/features/userprofile/impl/src/test/kotlin/io/element/android/features/userprofile/impl/UserProfilePresenterTest.kt @@ -386,14 +386,12 @@ class UserProfilePresenterTest { } private fun createFakeMatrixClient( - isUserVerified: Boolean = true, userIdentityState: IdentityState? = null, ignoreUserResult: (UserId) -> Result = { Result.success(Unit) }, unIgnoreUserResult: (UserId) -> Result = { Result.success(Unit) }, ignoredUsersFlow: StateFlow> = MutableStateFlow(persistentListOf()) ) = FakeMatrixClient( encryptionService = FakeEncryptionService( - isUserVerifiedResult = { Result.success(isUserVerified) }, getUserIdentityResult = { Result.success(userIdentityState) } ), ignoreUserResult = ignoreUserResult, diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 86d4ef286e..0f55838342 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -178,7 +178,7 @@ test_detekt_test = { module = "io.gitlab.arturbosch.detekt:detekt-test", version # https://github.com/matrix-org/matrix-rust-components-kotlin/commits/main/sdk/sdk-android/src/main/kotlin/org/matrix/rustcomponents/sdk/matrix_sdk_ffi.kt # All new features should not be implemented in the pull request that upgrades the version, developers should # only fix API breaks and may add some TODOs. -matrix_sdk = "org.matrix.rustcomponents:sdk-android:25.11.19" +matrix_sdk = "org.matrix.rustcomponents:sdk-android:25.11.24" # Others coil = { module = "io.coil-kt.coil3:coil", version.ref = "coil" } diff --git a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/encryption/EncryptionService.kt b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/encryption/EncryptionService.kt index 4ae75774c1..aefad517dc 100644 --- a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/encryption/EncryptionService.kt +++ b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/encryption/EncryptionService.kt @@ -64,8 +64,6 @@ interface EncryptionService { */ suspend fun startIdentityReset(): Result - suspend fun isUserVerified(userId: UserId): Result - /** * 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. + * @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 + suspend fun getUserIdentity(userId: UserId, fallbackToServer: Boolean = true): Result } /** diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/encryption/RustEncryptionService.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/encryption/RustEncryptionService.kt index 6ebf80337c..e081d1c9f1 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/encryption/RustEncryptionService.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/encryption/RustEncryptionService.kt @@ -240,10 +240,6 @@ class RustEncryptionService( } } - override suspend fun isUserVerified(userId: UserId): Result = runCatchingExceptions { - getUserIdentityInternal(userId).isVerified() - } - override suspend fun pinUserIdentity(userId: UserId): Result = runCatchingExceptions { getUserIdentityInternal(userId).pin() } @@ -252,8 +248,8 @@ class RustEncryptionService( getUserIdentityInternal(userId).withdrawVerification() } - override suspend fun getUserIdentity(userId: UserId): Result = runCatchingExceptions { - val identity = getUserIdentityInternal(userId) + override suspend fun getUserIdentity(userId: UserId, fallbackToServer: Boolean): Result = runCatchingExceptions { + val identity = getUserIdentityInternal(userId, fallbackToServer) val isVerified = identity.isVerified() when { 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( userId = userId.value, - // requestFromHomeserverIfNeeded = true, + fallbackToServer = fallbackToServer, ) ?: error("User identity not found") } diff --git a/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/encryption/FakeEncryptionService.kt b/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/encryption/FakeEncryptionService.kt index a94de15f1e..04e3779298 100644 --- a/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/encryption/FakeEncryptionService.kt +++ b/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/encryption/FakeEncryptionService.kt @@ -26,7 +26,6 @@ import kotlinx.coroutines.flow.flowOf class FakeEncryptionService( var startIdentityResetLambda: () -> Result = { lambdaError() }, private val pinUserIdentityResult: (UserId) -> Result = { lambdaError() }, - private val isUserVerifiedResult: (UserId) -> Result = { lambdaError() }, private val withdrawVerificationResult: (UserId) -> Result = { lambdaError() }, private val getUserIdentityResult: (UserId) -> Result = { lambdaError() }, private val enableRecoveryLambda: (Boolean) -> Result = { lambdaError() }, @@ -139,11 +138,7 @@ class FakeEncryptionService( return withdrawVerificationResult(userId) } - override suspend fun isUserVerified(userId: UserId): Result = simulateLongTask { - isUserVerifiedResult(userId) - } - - override suspend fun getUserIdentity(userId: UserId): Result = simulateLongTask { + override suspend fun getUserIdentity(userId: UserId, fallbackToServer: Boolean): Result = simulateLongTask { return getUserIdentityResult(userId) }