@@ -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