Files
continuwuity/src/api/client/space.rs
T

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

48 lines
1.3 KiB
Rust
Raw Normal View History

2024-07-16 08:05:25 +00:00
use axum::extract::State;
use conduwuit::{Err, Result};
use ruma::{UInt, api::client::space::get_hierarchy, assign};
use service::rooms::summary::Accessibility;
2024-03-16 16:09:11 -04:00
2025-02-07 07:09:45 +00:00
use crate::Ruma;
2024-03-05 19:48:54 -05:00
const MAX_MAX_DEPTH: u32 = 10;
/// # `GET /_matrix/client/v1/rooms/{room_id}/hierarchy`
2023-07-02 16:06:54 +02:00
///
/// Paginates over 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> {
// We don't do pagination for this route (and therefore ignore `limit`), since
// there's no reasonable way to handle a space hierarchy changing during
// pagination.
2024-03-25 17:05:11 -04:00
let max_depth = body
.max_depth
.map(|max_depth| max_depth.min(UInt::from(MAX_MAX_DEPTH)));
let hierarchy = services
.rooms
.summary
.get_room_hierarchy_for_user(
body.identity.sender_user(),
body.room_id.clone(),
max_depth,
body.suggested_only,
)
.await?;
match hierarchy {
| Accessibility::Accessible(rooms) =>
Ok(assign!(get_hierarchy::v1::Response::new(), { rooms: rooms })),
| Accessibility::Inaccessible => {
Err!(Request(Forbidden("You may not preview this room."), FORBIDDEN))
},
| Accessibility::NotFound => {
Err!(Request(Forbidden("This room does not exist."), FORBIDDEN))
},
2024-03-16 16:09:11 -04:00
}
2023-07-02 16:06:54 +02:00
}