Skip to content

Commit

Permalink
sdk: move get_profile from Client to Account (#3238)
Browse files Browse the repository at this point in the history
This also renames and streamlines the existing `Account::get_profile` function to `Account::fetch_profile` which now calls the more general function.
  • Loading branch information
jmartinesp authored Mar 19, 2024
1 parent 8c2831a commit 0c4b62f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion bindings/matrix-sdk-ffi/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ impl Client {
pub fn get_profile(&self, user_id: String) -> Result<UserProfile, ClientError> {
RUNTIME.block_on(async move {
let owned_user_id = UserId::parse(user_id.clone())?;
let response = self.inner.get_profile(&owned_user_id).await?;
let response = self.inner.account().fetch_user_profile_of(&owned_user_id).await?;

let user_profile = UserProfile {
user_id,
Expand Down
1 change: 1 addition & 0 deletions crates/matrix-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Breaking changes:
- Replace `impl MediaEventContent` with `&impl MediaEventContent` in
`Media::get_file`/`Media::remove_file`/`Media::get_thumbnail`/`Media::remove_thumbnail`
- A custom sliding sync proxy set with `ClientBuilder::sliding_sync_proxy` now takes precedence over a discovered proxy.
- `Client::get_profile` was moved to `Account` and renamed to `Account::fetch_user_profile_of`. `Account::get_profile` was renamed to `Account::fetch_user_profile`.

Additions:

Expand Down
19 changes: 15 additions & 4 deletions crates/matrix-sdk/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,18 +261,29 @@ impl Account {
/// # async {
/// # let homeserver = Url::parse("http://localhost:8080")?;
/// # let client = Client::new(homeserver).await?;
/// let profile = client.account().get_profile().await?;
/// let profile = client.account().fetch_user_profile().await?;
/// println!(
/// "You are '{:?}' with avatar '{:?}'",
/// profile.displayname, profile.avatar_url
/// );
/// # anyhow::Ok(()) };
/// ```
pub async fn get_profile(&self) -> Result<get_profile::v3::Response> {
pub async fn fetch_user_profile(&self) -> Result<get_profile::v3::Response> {
let user_id = self.client.user_id().ok_or(Error::AuthenticationRequired)?;
self.fetch_user_profile_of(user_id).await
}

/// Get the profile for a given user id
///
/// # Arguments
///
/// * `user_id` the matrix id this function downloads the profile for
pub async fn fetch_user_profile_of(
&self,
user_id: &UserId,
) -> Result<get_profile::v3::Response> {
let request = get_profile::v3::Request::new(user_id.to_owned());
let request_config = self.client.request_config().force_auth();
Ok(self.client.send(request, Some(request_config)).await?)
Ok(self.client.send(request, Some(RequestConfig::short_retry().force_auth())).await?)
}

/// Change the password of the account.
Expand Down
11 changes: 0 additions & 11 deletions crates/matrix-sdk/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ use ruma::{
},
filter::{create_filter::v3::Request as FilterUploadRequest, FilterDefinition},
membership::{join_room_by_id, join_room_by_id_or_alias},
profile::get_profile,
push::{set_pusher, Pusher},
room::create_room,
session::login::v3::DiscoveryInfo,
Expand Down Expand Up @@ -2048,16 +2047,6 @@ impl Client {
self.send(request, None).await
}

/// Get the profile for a given user id
///
/// # Arguments
///
/// * `user_id` the matrix id this function downloads the profile for
pub async fn get_profile(&self, user_id: &UserId) -> Result<get_profile::v3::Response> {
let request = get_profile::v3::Request::new(user_id.to_owned());
Ok(self.send(request, Some(RequestConfig::short_retry())).await?)
}

/// Get the notification settings of the current owner of the client.
pub async fn notification_settings(&self) -> NotificationSettings {
let ruleset = self.account().push_rules().await.unwrap_or_else(|_| Ruleset::new());
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk/src/widget/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl WidgetSettings {
props: ClientProperties,
) -> Result<Url, url::ParseError> {
self._generate_webview_url(
room.client().account().get_profile().await.unwrap_or_default(),
room.client().account().fetch_user_profile().await.unwrap_or_default(),
room.own_user_id(),
room.room_id(),
room.client().device_id().unwrap_or("UNKNOWN".into()),
Expand Down

0 comments on commit 0c4b62f

Please sign in to comment.