Can get room avatar
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use crate::controllers::HttpResult;
|
||||
use crate::controllers::matrix::media_controller;
|
||||
use crate::extractors::matrix_client_extractor::MatrixClientExtractor;
|
||||
use actix_web::{HttpResponse, web};
|
||||
use actix_web::{HttpRequest, HttpResponse, web};
|
||||
use futures_util::{StreamExt, stream};
|
||||
use matrix_sdk::ruma::{OwnedRoomId, OwnedUserId};
|
||||
use matrix_sdk::{Room, RoomMemberships};
|
||||
@@ -56,3 +57,20 @@ pub async fn single_room_info(
|
||||
Some(r) => HttpResponse::Ok().json(APIRoomInfo::from_room(&r).await?),
|
||||
})
|
||||
}
|
||||
|
||||
/// Get room avatar
|
||||
pub async fn room_avatar(
|
||||
req: HttpRequest,
|
||||
client: MatrixClientExtractor,
|
||||
path: web::Path<RoomIdInPath>,
|
||||
) -> HttpResult {
|
||||
let Some(room) = client.client.client.get_room(&path.id) else {
|
||||
return Ok(HttpResponse::NotFound().json("Room not found"));
|
||||
};
|
||||
|
||||
let Some(uri) = room.avatar_url() else {
|
||||
return Ok(HttpResponse::NotFound().json("Room has no avatar"));
|
||||
};
|
||||
|
||||
media_controller::serve_media(req, uri).await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user