1
0
Fork 0
mirror of https://forgejo.ellis.link/continuwuation/continuwuity.git synced 2025-07-30 03:38:31 +00:00
continuwuity/src/api/client_server/space.rs

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

20 lines
823 B
Rust
Raw Normal View History

2023-07-02 16:06:54 +02:00
use ruma::api::client::space::get_hierarchy;
use crate::{services, Result, Ruma};
2023-07-02 16:06:54 +02:00
/// # `GET /_matrix/client/v1/rooms/{room_id}/hierarchy``
///
/// Paginates over the space tree in a depth-first manner to locate child rooms
/// of a given space.
pub async fn get_hierarchy_route(body: Ruma<get_hierarchy::v1::Request>) -> Result<get_hierarchy::v1::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
2023-07-02 16:06:54 +02:00
let skip = body.from.as_ref().and_then(|s| s.parse::<usize>().ok()).unwrap_or(0);
2023-07-02 16:06:54 +02:00
let limit = body.limit.map_or(10, u64::from).min(100) as usize;
2023-07-02 16:06:54 +02:00
let max_depth = body.max_depth.map_or(3, u64::from).min(10) as usize + 1; // +1 to skip the space room itself
2023-07-02 16:06:54 +02:00
services().rooms.spaces.get_hierarchy(sender_user, &body.room_id, limit, skip, max_depth, body.suggested_only).await
2023-07-02 16:06:54 +02:00
}