Can get single profile information
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
use crate::controllers::HttpResult;
|
||||
use crate::extractors::matrix_client_extractor::MatrixClientExtractor;
|
||||
use actix_web::{HttpResponse, web};
|
||||
use matrix_sdk::ruma::api::client::profile::{AvatarUrl, DisplayName, get_profile};
|
||||
use matrix_sdk::ruma::{OwnedMxcUri, OwnedUserId};
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
pub struct UserIDInPath {
|
||||
user_id: OwnedUserId,
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
struct ProfileResponse {
|
||||
display_name: Option<String>,
|
||||
avatar: Option<OwnedMxcUri>,
|
||||
}
|
||||
|
||||
impl ProfileResponse {
|
||||
pub fn from(r: get_profile::v3::Response) -> anyhow::Result<Self> {
|
||||
Ok(Self {
|
||||
display_name: r.get_static::<DisplayName>()?,
|
||||
avatar: r.get_static::<AvatarUrl>()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Get user profile
|
||||
pub async fn get_profile(
|
||||
client: MatrixClientExtractor,
|
||||
path: web::Path<UserIDInPath>,
|
||||
) -> HttpResult {
|
||||
let profile = client
|
||||
.client
|
||||
.client
|
||||
.account()
|
||||
.fetch_user_profile_of(&path.user_id)
|
||||
.await?;
|
||||
|
||||
Ok(HttpResponse::Ok().json(ProfileResponse::from(profile)?))
|
||||
}
|
||||
@@ -3,7 +3,7 @@ use crate::controllers::matrix::media_controller;
|
||||
use crate::extractors::matrix_client_extractor::MatrixClientExtractor;
|
||||
use actix_web::{HttpRequest, HttpResponse, web};
|
||||
use futures_util::{StreamExt, stream};
|
||||
use matrix_sdk::ruma::{OwnedRoomId, OwnedUserId};
|
||||
use matrix_sdk::ruma::{OwnedMxcUri, OwnedRoomId, OwnedUserId};
|
||||
use matrix_sdk::{Room, RoomMemberships};
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
@@ -11,7 +11,7 @@ pub struct APIRoomInfo {
|
||||
id: OwnedRoomId,
|
||||
name: Option<String>,
|
||||
members: Vec<OwnedUserId>,
|
||||
has_avatar: bool,
|
||||
avatar: Option<OwnedMxcUri>,
|
||||
}
|
||||
|
||||
impl APIRoomInfo {
|
||||
@@ -25,7 +25,7 @@ impl APIRoomInfo {
|
||||
.into_iter()
|
||||
.map(|r| r.user_id().to_owned())
|
||||
.collect::<Vec<_>>(),
|
||||
has_avatar: r.avatar_url().is_some(),
|
||||
avatar: r.avatar_url(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
pub mod matrix_profile_controller;
|
||||
pub mod matrix_room_controller;
|
||||
pub mod media_controller;
|
||||
|
||||
Reference in New Issue
Block a user