Merge branch 'hierarchy' into 'next'

feat: space hierarchies

See merge request famedly/conduit!495
This commit is contained in:
Timo Kösters 2023-07-03 13:56:47 +00:00
commit 833c1505f1
13 changed files with 556 additions and 48 deletions

View file

@ -3,7 +3,7 @@ use ruma::{
api::client::{context::get_context, error::ErrorKind, filter::LazyLoadOptions},
events::StateEventType,
};
use std::{collections::HashSet, convert::TryFrom};
use std::collections::HashSet;
use tracing::error;
/// # `GET /_matrix/client/r0/rooms/{roomId}/context`
@ -70,9 +70,7 @@ pub async fn get_context_route(
}
// Use limit with maximum 100
let limit = usize::try_from(body.limit)
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Limit value is invalid."))?
.min(100);
let limit = u64::from(body.limit).min(100) as usize;
let base_event = base_event.to_room_event();

View file

@ -133,12 +133,7 @@ pub async fn get_message_events_route(
from,
)?;
// Use limit or else 10, with maximum 100
let limit = body
.limit
.try_into()
.map_or(10_usize, |l: u32| l as usize)
.min(100);
let limit = u64::from(body.limit).min(100) as usize;
let next_token;

View file

@ -21,6 +21,7 @@ mod report;
mod room;
mod search;
mod session;
mod space;
mod state;
mod sync;
mod tag;
@ -55,6 +56,7 @@ pub use report::*;
pub use room::*;
pub use search::*;
pub use session::*;
pub use space::*;
pub use state::*;
pub use sync::*;
pub use tag::*;

View file

@ -31,7 +31,8 @@ pub async fn search_events_route(
.collect()
});
let limit = filter.limit.map_or(10, |l| u64::from(l) as usize);
// Use limit or else 10, with maximum 100
let limit = filter.limit.map_or(10, u64::from).min(100) as usize;
let mut searches = Vec::new();

View file

@ -0,0 +1,34 @@
use crate::{services, Result, Ruma};
use ruma::api::client::space::get_hierarchy;
/// # `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");
let skip = body
.from
.as_ref()
.and_then(|s| s.parse::<usize>().ok())
.unwrap_or(0);
let limit = body.limit.map_or(10, u64::from).min(100) as usize;
let max_depth = body.max_depth.map_or(3, u64::from).min(10) as usize + 1; // +1 to skip the space room itself
services()
.rooms
.spaces
.get_hierarchy(
sender_user,
&body.room_id,
limit,
skip,
max_depth,
body.suggested_only,
)
.await
}

View file

@ -151,7 +151,7 @@ where
.try_into_http_request::<Vec<u8>>(
&actual_destination_str,
SendAccessToken::IfRequired(""),
&[MatrixVersion::V1_0],
&[MatrixVersion::V1_4],
)
.map_err(|e| {
warn!(