Skip to content

Commit 4ae82dd

Browse files
committed
feat(bindings): Allow user identities to only be fetched from storage
1 parent d860749 commit 4ae82dd

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

bindings/matrix-sdk-ffi/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ All notable changes to this project will be documented in this file.
88

99
### Breaking changes
1010

11+
- The `Encryption::user_identity()` method has received a new argument. The
12+
`fallback_to_server` argument controls if we should attempt to fetch the user
13+
identity from the homeserver if it wasn't found in the local storage.
14+
([#5870](https://github.com/matrix-org/matrix-rust-sdk/pull/5870))
1115
- Expose the power level required to modify `m.space.child` on
1216
`room::power_levels::RoomPowerLevelsValues`.
1317
- Rename `Client::login_with_qr_code` to `Client::new_login_with_qr_code_handler`.

bindings/matrix-sdk-ffi/src/encryption.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,13 @@ impl Encryption {
434434
/// This method always tries to fetch the identity from the store, which we
435435
/// only have if the user is tracked, meaning that we are both members
436436
/// of the same encrypted room. If no user is found locally, a request will
437-
/// be made to the homeserver.
437+
/// be made to the homeserver unless `fallback_to_server` is set to `false`.
438438
///
439439
/// # Arguments
440440
///
441441
/// * `user_id` - The ID of the user that the identity belongs to.
442+
/// * `fallback_to_server` - Should we request the user identity from the
443+
/// homeserver if one isn't found locally.
442444
///
443445
/// Returns a `UserIdentity` if one is found. Returns an error if there
444446
/// was an issue with the crypto store or with the request to the
@@ -448,6 +450,7 @@ impl Encryption {
448450
pub async fn user_identity(
449451
&self,
450452
user_id: String,
453+
fallback_to_server: bool,
451454
) -> Result<Option<Arc<UserIdentity>>, ClientError> {
452455
match self.inner.get_user_identity(user_id.as_str().try_into()?).await {
453456
Ok(Some(identity)) => {
@@ -463,8 +466,12 @@ impl Encryption {
463466

464467
info!("Requesting identity from the server.");
465468

466-
let identity = self.inner.request_user_identity(user_id.as_str().try_into()?).await?;
467-
Ok(identity.map(|identity| Arc::new(UserIdentity { inner: identity })))
469+
if fallback_to_server {
470+
let identity = self.inner.request_user_identity(user_id.as_str().try_into()?).await?;
471+
Ok(identity.map(|identity| Arc::new(UserIdentity { inner: identity })))
472+
} else {
473+
Ok(None)
474+
}
468475
}
469476
}
470477

0 commit comments

Comments
 (0)