2024-07-16 08:05:25 +00:00
|
|
|
use axum::extract::State;
|
2024-06-05 04:32:58 +00:00
|
|
|
use ruma::api::{client::error::ErrorKind, federation::space::get_hierarchy};
|
|
|
|
|
2024-07-16 08:05:25 +00:00
|
|
|
use crate::{Error, Result, Ruma};
|
2024-06-05 04:32:58 +00:00
|
|
|
|
|
|
|
/// # `GET /_matrix/federation/v1/hierarchy/{roomId}`
|
|
|
|
///
|
|
|
|
/// Gets the space tree in a depth-first manner to locate child rooms of a given
|
|
|
|
/// space.
|
2024-07-16 08:05:25 +00:00
|
|
|
pub(crate) async fn get_hierarchy_route(
|
2024-12-15 00:05:47 -05:00
|
|
|
State(services): State<crate::State>,
|
|
|
|
body: Ruma<get_hierarchy::v1::Request>,
|
2024-07-16 08:05:25 +00:00
|
|
|
) -> Result<get_hierarchy::v1::Response> {
|
2024-08-08 17:18:30 +00:00
|
|
|
if services.rooms.metadata.exists(&body.room_id).await {
|
2024-07-16 08:05:25 +00:00
|
|
|
services
|
2024-06-05 04:32:58 +00:00
|
|
|
.rooms
|
|
|
|
.spaces
|
2024-10-24 12:03:56 +00:00
|
|
|
.get_federation_hierarchy(&body.room_id, body.origin(), body.suggested_only)
|
2024-06-05 04:32:58 +00:00
|
|
|
.await
|
|
|
|
} else {
|
|
|
|
Err(Error::BadRequest(ErrorKind::NotFound, "Room does not exist."))
|
|
|
|
}
|
|
|
|
}
|