Can get the name of a room through the API
This commit is contained in:
parent
53186d2e24
commit
4589b3b339
@ -57,6 +57,7 @@ async fn main() -> std::io::Result<()> {
|
|||||||
.route("/api", web::get().to(api::api_home))
|
.route("/api", web::get().to(api::api_home))
|
||||||
.route("/api", web::post().to(api::api_home))
|
.route("/api", web::post().to(api::api_home))
|
||||||
.route("/api/account/whoami", web::get().to(api::account::who_am_i))
|
.route("/api/account/whoami", web::get().to(api::account::who_am_i))
|
||||||
|
.route("/api/room/{room_id}/name", web::get().to(api::rooms::name))
|
||||||
.service(web::resource("/api/ws").route(web::get().to(api::ws::ws)))
|
.service(web::resource("/api/ws").route(web::get().to(api::ws::ws)))
|
||||||
})
|
})
|
||||||
.workers(4)
|
.workers(4)
|
||||||
|
@ -3,6 +3,7 @@ use crate::server::HttpResult;
|
|||||||
use actix_web::HttpResponse;
|
use actix_web::HttpResponse;
|
||||||
|
|
||||||
pub mod account;
|
pub mod account;
|
||||||
|
pub mod rooms;
|
||||||
pub mod ws;
|
pub mod ws;
|
||||||
|
|
||||||
/// API Home route
|
/// API Home route
|
||||||
|
31
src/server/api/rooms.rs
Normal file
31
src/server/api/rooms.rs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
use crate::extractors::client_auth::APIClientAuth;
|
||||||
|
use crate::server::HttpResult;
|
||||||
|
use actix_web::{web, HttpResponse};
|
||||||
|
use ruma::api::client::state;
|
||||||
|
use ruma::events::StateEventType;
|
||||||
|
use ruma::OwnedRoomId;
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
pub struct RoomIDInPath {
|
||||||
|
room_id: OwnedRoomId,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Serialize)]
|
||||||
|
struct GetRoomNameResponse {
|
||||||
|
name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get room name
|
||||||
|
pub async fn name(auth: APIClientAuth, path: web::Path<RoomIDInPath>) -> HttpResult {
|
||||||
|
let res = auth
|
||||||
|
.send_request(state::get_state_events_for_key::v3::Request::new(
|
||||||
|
path.room_id.clone(),
|
||||||
|
StateEventType::RoomName,
|
||||||
|
String::default(),
|
||||||
|
))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(HttpResponse::Ok().json(GetRoomNameResponse {
|
||||||
|
name: res.content.get_field("name")?.unwrap_or("").to_string(),
|
||||||
|
}))
|
||||||
|
}
|
@ -28,6 +28,8 @@ pub enum HttpFailure {
|
|||||||
MatrixApiClientError(#[from] ruma::api::client::Error),
|
MatrixApiClientError(#[from] ruma::api::client::Error),
|
||||||
#[error("a matrix client error occurred: {0}")]
|
#[error("a matrix client error occurred: {0}")]
|
||||||
MatrixClientError(String),
|
MatrixClientError(String),
|
||||||
|
#[error("a serde_json error occurred: {0}")]
|
||||||
|
SerdeJsonError(#[from] serde_json::error::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ResponseError for HttpFailure {
|
impl ResponseError for HttpFailure {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user