From 261bd1625d5153d26dea90bc47118e17eaaa536c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Fri, 14 Nov 2025 13:49:04 +0100 Subject: [PATCH] feat(bindings): Allow user identities to only be fetched from storage --- bindings/matrix-sdk-ffi/CHANGELOG.md | 4 ++++ bindings/matrix-sdk-ffi/src/encryption.rs | 13 ++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/bindings/matrix-sdk-ffi/CHANGELOG.md b/bindings/matrix-sdk-ffi/CHANGELOG.md index 19ec85c0d95..2a860e9bc9b 100644 --- a/bindings/matrix-sdk-ffi/CHANGELOG.md +++ b/bindings/matrix-sdk-ffi/CHANGELOG.md @@ -8,6 +8,10 @@ All notable changes to this project will be documented in this file. ### Breaking changes +- The `Encryption::user_identity()` method has received a new argument. The + `fallback_to_server` argument controls if we should attempt to fetch the user + identity from the homeserver if it wasn't found in the local storage. + ([#5870](https://github.com/matrix-org/matrix-rust-sdk/pull/5870)) - Expose the power level required to modify `m.space.child` on `room::power_levels::RoomPowerLevelsValues`. - Rename `Client::login_with_qr_code` to `Client::new_login_with_qr_code_handler`. diff --git a/bindings/matrix-sdk-ffi/src/encryption.rs b/bindings/matrix-sdk-ffi/src/encryption.rs index 2a7276db0ec..ee00ef10dfa 100644 --- a/bindings/matrix-sdk-ffi/src/encryption.rs +++ b/bindings/matrix-sdk-ffi/src/encryption.rs @@ -434,11 +434,13 @@ impl Encryption { /// This method always tries to fetch the identity from the store, which we /// only have if the user is tracked, meaning that we are both members /// of the same encrypted room. If no user is found locally, a request will - /// be made to the homeserver. + /// be made to the homeserver unless `fallback_to_server` is set to `false`. /// /// # Arguments /// /// * `user_id` - The ID of the user that the identity belongs to. + /// * `fallback_to_server` - Should we request the user identity from the + /// homeserver if one isn't found locally. /// /// Returns a `UserIdentity` if one is found. Returns an error if there /// was an issue with the crypto store or with the request to the @@ -448,6 +450,7 @@ impl Encryption { pub async fn user_identity( &self, user_id: String, + fallback_to_server: bool, ) -> Result>, ClientError> { match self.inner.get_user_identity(user_id.as_str().try_into()?).await { Ok(Some(identity)) => { @@ -463,8 +466,12 @@ impl Encryption { info!("Requesting identity from the server."); - let identity = self.inner.request_user_identity(user_id.as_str().try_into()?).await?; - Ok(identity.map(|identity| Arc::new(UserIdentity { inner: identity }))) + if fallback_to_server { + let identity = self.inner.request_user_identity(user_id.as_str().try_into()?).await?; + Ok(identity.map(|identity| Arc::new(UserIdentity { inner: identity }))) + } else { + Ok(None) + } } }