-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FFI: Expose UserIdentity::is_verified
and add a new Encryption::user_identity
method.
#4142
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ use matrix_sdk::{ | |
encryption::{backups, recovery}, | ||
}; | ||
use thiserror::Error; | ||
use tracing::{error, info}; | ||
use zeroize::Zeroize; | ||
|
||
use super::RUNTIME; | ||
|
@@ -413,16 +414,40 @@ impl Encryption { | |
|
||
/// Get the E2EE identity of a user. | ||
/// | ||
/// Returns Ok(None) if this user does not exist. | ||
/// 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. | ||
/// | ||
/// Returns an error if there was a problem contacting the crypto store, or | ||
/// if our client is not logged in. | ||
pub async fn get_user_identity( | ||
/// # Arguments | ||
/// | ||
/// * `user_id` - The ID of the user that the identity belongs to. | ||
/// | ||
/// 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 | ||
/// homeserver. | ||
/// | ||
/// This will always return `None` if the client hasn't been logged in. | ||
pub async fn user_identity( | ||
&self, | ||
user_id: String, | ||
) -> Result<Option<Arc<UserIdentity>>, ClientError> { | ||
let identity = self.inner.get_user_identity(user_id.as_str().try_into()?).await?; | ||
Ok(identity.map(|i| Arc::new(UserIdentity { inner: i }))) | ||
match self.inner.get_user_identity(user_id.as_str().try_into()?).await { | ||
Ok(Some(identity)) => { | ||
return Ok(Some(Arc::new(UserIdentity { inner: identity }))); | ||
} | ||
Ok(None) => { | ||
info!("No identity found in the store."); | ||
} | ||
Err(error) => { | ||
error!("Failed fetching identity from the store: {}", error); | ||
} | ||
}; | ||
|
||
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 }))) | ||
} | ||
} | ||
|
||
|
@@ -461,6 +486,14 @@ impl UserIdentity { | |
pub(crate) fn master_key(&self) -> Option<String> { | ||
self.inner.master_key().get_first_key().map(|k| k.to_base64()) | ||
} | ||
|
||
/// Is the user identity considered to be verified. | ||
/// | ||
/// If the identity belongs to another user, our own user identity needs to | ||
/// be verified as well for the identity to be considered to be verified. | ||
pub fn is_verified(&self) -> bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am wondering if this data should be live? Maybe not for now but in the future the app could be more reactive if we had a way to get a live There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'd really like this to be a property on |
||
self.inner.is_verified() | ||
} | ||
} | ||
|
||
#[derive(uniffi::Object)] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should just copy paste the underlying documentation instead of rolling a new one 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did but removing the middle section as it seems overly technical from the perspective of an SDK user to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see, I was looking at the one inside the crypto crate which seemed just perfect. I'm just worried something will change on one level or another and then the documentation will be out of date.