Files
continuwuity/src/api/server/hierarchy.rs
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
1.1 KiB
Rust
Raw Normal View History

2024-07-16 08:05:25 +00:00
use axum::extract::State;
use conduwuit::{Err, Result, info};
2025-02-07 07:09:45 +00:00
use ruma::api::federation::space::get_hierarchy;
use service::rooms::summary::Accessibility;
2024-06-05 04:32:58 +00:00
2025-02-06 20:08:00 +00:00
use crate::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(
State(services): State<crate::State>,
body: Ruma<get_hierarchy::v1::Request>,
2024-07-16 08:05:25 +00:00
) -> Result<get_hierarchy::v1::Response> {
if !services
.rooms
.state_cache
.server_in_room(services.globals.server_name(), &body.room_id)
.await
{
info!(
origin = body.origin().as_str(),
"Refusing to serve state for room we aren't participating in"
);
return Err!(Request(NotFound("This server is not participating in that room.")));
}
let response = services
2025-02-06 20:08:00 +00:00
.rooms
.summary
.get_local_room_summary_for_server(body.origin(), &body.room_id, body.suggested_only)
.await;
2025-02-06 20:08:00 +00:00
if let Accessibility::Accessible(response) = response {
Ok(response)
} else {
Err!(Request(NotFound("This room is not accessible.")))
2024-06-05 04:32:58 +00:00
}
}