Upgrade Ruma: profile response
Handle the changes to the Response of the get_profile endpoint. The content of the response is private and fields must be accessed with methods. Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
This commit is contained in:
committed by
Ivan Enderlin
parent
a3a239f999
commit
33df0422e8
Generated
+8
-8
@@ -4658,7 +4658,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma"
|
||||
version = "0.12.6"
|
||||
source = "git+https://github.com/ruma/ruma?rev=d879f7df16ba9928a73649f8149dabeee939691e#d879f7df16ba9928a73649f8149dabeee939691e"
|
||||
source = "git+https://github.com/ruma/ruma?rev=0ecd23c32c58be9328fa5f3e33fe0458cc139213#0ecd23c32c58be9328fa5f3e33fe0458cc139213"
|
||||
dependencies = [
|
||||
"assign",
|
||||
"js_int",
|
||||
@@ -4675,7 +4675,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-client-api"
|
||||
version = "0.20.4"
|
||||
source = "git+https://github.com/ruma/ruma?rev=d879f7df16ba9928a73649f8149dabeee939691e#d879f7df16ba9928a73649f8149dabeee939691e"
|
||||
source = "git+https://github.com/ruma/ruma?rev=0ecd23c32c58be9328fa5f3e33fe0458cc139213#0ecd23c32c58be9328fa5f3e33fe0458cc139213"
|
||||
dependencies = [
|
||||
"as_variant",
|
||||
"assign",
|
||||
@@ -4698,7 +4698,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-common"
|
||||
version = "0.15.4"
|
||||
source = "git+https://github.com/ruma/ruma?rev=d879f7df16ba9928a73649f8149dabeee939691e#d879f7df16ba9928a73649f8149dabeee939691e"
|
||||
source = "git+https://github.com/ruma/ruma?rev=0ecd23c32c58be9328fa5f3e33fe0458cc139213#0ecd23c32c58be9328fa5f3e33fe0458cc139213"
|
||||
dependencies = [
|
||||
"as_variant",
|
||||
"base64",
|
||||
@@ -4731,7 +4731,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-events"
|
||||
version = "0.30.5"
|
||||
source = "git+https://github.com/ruma/ruma?rev=d879f7df16ba9928a73649f8149dabeee939691e#d879f7df16ba9928a73649f8149dabeee939691e"
|
||||
source = "git+https://github.com/ruma/ruma?rev=0ecd23c32c58be9328fa5f3e33fe0458cc139213#0ecd23c32c58be9328fa5f3e33fe0458cc139213"
|
||||
dependencies = [
|
||||
"as_variant",
|
||||
"indexmap",
|
||||
@@ -4757,7 +4757,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-federation-api"
|
||||
version = "0.11.2"
|
||||
source = "git+https://github.com/ruma/ruma?rev=d879f7df16ba9928a73649f8149dabeee939691e#d879f7df16ba9928a73649f8149dabeee939691e"
|
||||
source = "git+https://github.com/ruma/ruma?rev=0ecd23c32c58be9328fa5f3e33fe0458cc139213#0ecd23c32c58be9328fa5f3e33fe0458cc139213"
|
||||
dependencies = [
|
||||
"headers",
|
||||
"http",
|
||||
@@ -4777,7 +4777,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-html"
|
||||
version = "0.4.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=d879f7df16ba9928a73649f8149dabeee939691e#d879f7df16ba9928a73649f8149dabeee939691e"
|
||||
source = "git+https://github.com/ruma/ruma?rev=0ecd23c32c58be9328fa5f3e33fe0458cc139213#0ecd23c32c58be9328fa5f3e33fe0458cc139213"
|
||||
dependencies = [
|
||||
"as_variant",
|
||||
"html5ever",
|
||||
@@ -4788,7 +4788,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-identifiers-validation"
|
||||
version = "0.10.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=d879f7df16ba9928a73649f8149dabeee939691e#d879f7df16ba9928a73649f8149dabeee939691e"
|
||||
source = "git+https://github.com/ruma/ruma?rev=0ecd23c32c58be9328fa5f3e33fe0458cc139213#0ecd23c32c58be9328fa5f3e33fe0458cc139213"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"thiserror 2.0.11",
|
||||
@@ -4797,7 +4797,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-macros"
|
||||
version = "0.15.2"
|
||||
source = "git+https://github.com/ruma/ruma?rev=d879f7df16ba9928a73649f8149dabeee939691e#d879f7df16ba9928a73649f8149dabeee939691e"
|
||||
source = "git+https://github.com/ruma/ruma?rev=0ecd23c32c58be9328fa5f3e33fe0458cc139213#0ecd23c32c58be9328fa5f3e33fe0458cc139213"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"proc-macro-crate",
|
||||
|
||||
+2
-2
@@ -59,7 +59,7 @@ proptest = { version = "1.6.0", default-features = false, features = ["std"] }
|
||||
rand = "0.8.5"
|
||||
reqwest = { version = "0.12.12", default-features = false }
|
||||
rmp-serde = "1.3.0"
|
||||
ruma = { git = "https://github.com/ruma/ruma", rev = "d879f7df16ba9928a73649f8149dabeee939691e", features = [
|
||||
ruma = { git = "https://github.com/ruma/ruma", rev = "0ecd23c32c58be9328fa5f3e33fe0458cc139213", features = [
|
||||
"client-api-c",
|
||||
"compat-upload-signatures",
|
||||
"compat-arbitrary-length-ids",
|
||||
@@ -79,7 +79,7 @@ ruma = { git = "https://github.com/ruma/ruma", rev = "d879f7df16ba9928a73649f814
|
||||
"unstable-msc4286",
|
||||
"unstable-msc4306"
|
||||
] }
|
||||
ruma-common = { git = "https://github.com/ruma/ruma", rev = "d879f7df16ba9928a73649f8149dabeee939691e" }
|
||||
ruma-common = { git = "https://github.com/ruma/ruma", rev = "0ecd23c32c58be9328fa5f3e33fe0458cc139213" }
|
||||
sentry = "0.36.0"
|
||||
sentry-tracing = "0.36.0"
|
||||
serde = { version = "1.0.217", features = ["rc"] }
|
||||
|
||||
@@ -39,7 +39,7 @@ use matrix_sdk::{
|
||||
},
|
||||
sliding_sync::Version as SdkSlidingSyncVersion,
|
||||
store::RoomLoadSettings as SdkRoomLoadSettings,
|
||||
AuthApi, AuthSession, Client as MatrixClient, SessionChange, SessionTokens,
|
||||
Account, AuthApi, AuthSession, Client as MatrixClient, SessionChange, SessionTokens,
|
||||
STATE_STORE_DATABASE_NAME,
|
||||
};
|
||||
use matrix_sdk_common::{stream::StreamExt, SendOutsideWasm, SyncOutsideWasm};
|
||||
@@ -53,7 +53,12 @@ use matrix_sdk_ui::{
|
||||
use mime::Mime;
|
||||
use oauth2::Scope;
|
||||
use ruma::{
|
||||
api::client::{alias::get_alias, error::ErrorKind, uiaa::UserIdentifier},
|
||||
api::client::{
|
||||
alias::get_alias,
|
||||
error::ErrorKind,
|
||||
profile::{AvatarUrl, DisplayName},
|
||||
uiaa::UserIdentifier,
|
||||
},
|
||||
events::{
|
||||
direct::DirectEventContent,
|
||||
fully_read::FullyReadEventContent,
|
||||
@@ -1233,15 +1238,8 @@ impl Client {
|
||||
}
|
||||
|
||||
pub async fn get_profile(&self, user_id: String) -> Result<UserProfile, ClientError> {
|
||||
let owned_user_id = UserId::parse(user_id.clone())?;
|
||||
|
||||
let response = self.inner.account().fetch_user_profile_of(&owned_user_id).await?;
|
||||
|
||||
Ok(UserProfile {
|
||||
user_id,
|
||||
display_name: response.displayname.clone(),
|
||||
avatar_url: response.avatar_url.as_ref().map(|url| url.to_string()),
|
||||
})
|
||||
let user_id = <&UserId>::try_from(user_id.as_str())?;
|
||||
UserProfile::fetch(&self.inner.account(), user_id).await
|
||||
}
|
||||
|
||||
pub async fn notification_client(
|
||||
@@ -1812,6 +1810,18 @@ pub struct UserProfile {
|
||||
pub avatar_url: Option<String>,
|
||||
}
|
||||
|
||||
impl UserProfile {
|
||||
/// Fetch the profile for the given user ID, using the given [`Account`]
|
||||
/// API.
|
||||
pub(crate) async fn fetch(account: &Account, user_id: &UserId) -> Result<Self, ClientError> {
|
||||
let response = account.fetch_user_profile_of(user_id).await?;
|
||||
let display_name = response.get_static::<DisplayName>()?;
|
||||
let avatar_url = response.get_static::<AvatarUrl>()?.map(|url| url.to_string());
|
||||
|
||||
Ok(UserProfile { user_id: user_id.to_string(), display_name, avatar_url })
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&search_users::v3::User> for UserProfile {
|
||||
fn from(value: &search_users::v3::User) -> Self {
|
||||
UserProfile {
|
||||
|
||||
@@ -254,18 +254,14 @@ impl SessionVerificationController {
|
||||
return;
|
||||
};
|
||||
|
||||
let Ok(sender_profile) = self.account.fetch_user_profile_of(sender).await else {
|
||||
let Ok(sender_profile) = UserProfile::fetch(&self.account, sender).await else {
|
||||
error!("Failed fetching user profile for verification request");
|
||||
return;
|
||||
};
|
||||
|
||||
if let Some(delegate) = &*self.delegate.read().unwrap() {
|
||||
delegate.did_receive_verification_request(SessionVerificationRequestDetails {
|
||||
sender_profile: UserProfile {
|
||||
user_id: request.other_user_id().to_string(),
|
||||
display_name: sender_profile.displayname,
|
||||
avatar_url: sender_profile.avatar_url.as_ref().map(|url| url.to_string()),
|
||||
},
|
||||
sender_profile,
|
||||
flow_id: request.flow_id().into(),
|
||||
device_id: other_device_data.device_id().into(),
|
||||
device_display_name: other_device_data.display_name().map(str::to_string),
|
||||
|
||||
@@ -109,6 +109,7 @@ ruma = { workspace = true, features = [
|
||||
"unstable-msc4230",
|
||||
"unstable-msc2967",
|
||||
"unstable-msc4108",
|
||||
"unstable-msc4133",
|
||||
"unstable-msc4278",
|
||||
] }
|
||||
serde.workspace = true
|
||||
|
||||
@@ -269,23 +269,25 @@ impl Account {
|
||||
Ok(upload_response.content_uri)
|
||||
}
|
||||
|
||||
/// Get the profile of the account.
|
||||
/// Get the profile of this account.
|
||||
///
|
||||
/// Allows to get both the display name and avatar URL in a single call.
|
||||
/// Allows to get all the profile data in a single call.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use matrix_sdk::Client;
|
||||
/// use ruma::api::client::profile::{AvatarUrl, DisplayName};
|
||||
/// # use url::Url;
|
||||
/// # async {
|
||||
/// # let homeserver = Url::parse("http://localhost:8080")?;
|
||||
/// # let client = Client::new(homeserver).await?;
|
||||
///
|
||||
/// let profile = client.account().fetch_user_profile().await?;
|
||||
/// println!(
|
||||
/// "You are '{:?}' with avatar '{:?}'",
|
||||
/// profile.displayname, profile.avatar_url
|
||||
/// );
|
||||
/// let display_name = profile.get_static::<DisplayName>()?;
|
||||
/// let avatar_url = profile.get_static::<AvatarUrl>()?;
|
||||
///
|
||||
/// println!("You are '{display_name:?}' with avatar '{avatar_url:?}'");
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
pub async fn fetch_user_profile(&self) -> Result<get_profile::v3::Response> {
|
||||
|
||||
@@ -441,9 +441,13 @@ mod tests {
|
||||
}
|
||||
|
||||
fn build_url_from_widget_settings(settings: WidgetSettings) -> String {
|
||||
let mut profile = get_profile::v3::Response::new();
|
||||
profile.set("avatar_url", "some-url".into());
|
||||
profile.set("displayname", "hello".into());
|
||||
|
||||
settings
|
||||
._generate_webview_url(
|
||||
get_profile::v3::Response::new(Some("some-url".into()), Some("hello".into())),
|
||||
profile,
|
||||
"@test:user.org".try_into().unwrap(),
|
||||
"!room_id:room.org".try_into().unwrap(),
|
||||
"ABCDEFG".into(),
|
||||
|
||||
@@ -13,7 +13,10 @@
|
||||
// limitations under the License.
|
||||
|
||||
use language_tags::LanguageTag;
|
||||
use ruma::{api::client::profile::get_profile, DeviceId, RoomId, UserId};
|
||||
use ruma::{
|
||||
api::client::profile::{get_profile, AvatarUrl, DisplayName},
|
||||
DeviceId, RoomId, UserId,
|
||||
};
|
||||
use url::Url;
|
||||
|
||||
use crate::Room;
|
||||
@@ -110,12 +113,17 @@ impl WidgetSettings {
|
||||
homeserver_url: Url,
|
||||
client_props: ClientProperties,
|
||||
) -> Result<Url, url::ParseError> {
|
||||
let avatar_url = profile.avatar_url.map(|url| url.to_string()).unwrap_or_default();
|
||||
let avatar_url = profile
|
||||
.get_static::<AvatarUrl>()
|
||||
.ok()
|
||||
.flatten()
|
||||
.map(|url| url.to_string())
|
||||
.unwrap_or_default();
|
||||
|
||||
let query_props = url_params::QueryProperties {
|
||||
widget_id: self.widget_id.clone(),
|
||||
avatar_url,
|
||||
display_name: profile.displayname.unwrap_or_default(),
|
||||
display_name: profile.get_static::<DisplayName>().ok().flatten().unwrap_or_default(),
|
||||
user_id: user_id.into(),
|
||||
room_id: room_id.into(),
|
||||
language: client_props.language.to_string(),
|
||||
|
||||
@@ -2,7 +2,10 @@ use std::{env, process::exit};
|
||||
|
||||
use matrix_sdk::{
|
||||
Client, Result as MatrixResult,
|
||||
ruma::{OwnedMxcUri, UserId, api::client::profile},
|
||||
ruma::{
|
||||
OwnedMxcUri, UserId,
|
||||
api::client::profile::{self, AvatarUrl, DisplayName},
|
||||
},
|
||||
};
|
||||
use url::Url;
|
||||
|
||||
@@ -27,7 +30,10 @@ async fn get_profile(client: Client, mxid: &UserId) -> MatrixResult<UserProfile>
|
||||
// Use the response and construct a UserProfile struct.
|
||||
// See https://docs.rs/ruma-client-api/0.9.0/ruma_client_api/r0/profile/get_profile/struct.Response.html
|
||||
// for details on the Response for this Request
|
||||
let user_profile = UserProfile { avatar_url: resp.avatar_url, displayname: resp.displayname };
|
||||
let user_profile = UserProfile {
|
||||
avatar_url: resp.get_static::<AvatarUrl>()?,
|
||||
displayname: resp.get_static::<DisplayName>()?,
|
||||
};
|
||||
Ok(user_profile)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user