Can get user information
This commit is contained in:
29
src/server/api/profile.rs
Normal file
29
src/server/api/profile.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use crate::extractors::client_auth::APIClientAuth;
|
||||
use crate::server::HttpResult;
|
||||
use crate::utils::matrix_utils::ApiMxcURI;
|
||||
use actix_web::{web, HttpResponse};
|
||||
use ruma::api::client::profile;
|
||||
use ruma::OwnedUserId;
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
pub struct UserIDInPath {
|
||||
user_id: OwnedUserId,
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
struct ProfileResponse {
|
||||
display_name: Option<String>,
|
||||
avatar: Option<ApiMxcURI>,
|
||||
}
|
||||
|
||||
/// Get user profile
|
||||
pub async fn get_profile(auth: APIClientAuth, path: web::Path<UserIDInPath>) -> HttpResult {
|
||||
let res = auth
|
||||
.send_request(profile::get_profile::v3::Request::new(path.user_id.clone()))
|
||||
.await?;
|
||||
|
||||
Ok(HttpResponse::Ok().json(ProfileResponse {
|
||||
display_name: res.displayname,
|
||||
avatar: res.avatar_url.map(ApiMxcURI),
|
||||
}))
|
||||
}
|
||||
Reference in New Issue
Block a user