ruma_federation_api/space/get_hierarchy/
unstable.rs

1//! `/unstable/org.matrix.msc2946/` ([MSC])
2//!
3//! [MSC]: https://github.com/matrix-org/matrix-spec-proposals/pull/2946
4
5use ruma_common::{
6    api::{path_builder::SinglePath, request, response, Metadata},
7    room::RoomSummary,
8    OwnedRoomId,
9};
10
11use crate::space::SpaceHierarchyParentSummary;
12
13/// Request type for the `hierarchy` endpoint.
14#[request]
15pub struct Request {
16    /// The room ID of the space to get a hierarchy for.
17    #[ruma_api(path)]
18    pub room_id: OwnedRoomId,
19
20    /// Whether or not the server should only consider suggested rooms.
21    ///
22    /// Suggested rooms are annotated in their `m.space.child` event contents.
23    #[ruma_api(query)]
24    #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")]
25    pub suggested_only: bool,
26}
27
28impl Request {
29    /// Creates a `Request` with the given room ID.
30    pub fn new(room_id: OwnedRoomId) -> Self {
31        Self { room_id, suggested_only: false }
32    }
33}
34
35impl Metadata for Request {
36    const METHOD: http::Method = super::v1::Request::METHOD;
37    const RATE_LIMITED: bool = super::v1::Request::RATE_LIMITED;
38    type Authentication = <super::v1::Request as Metadata>::Authentication;
39    type PathBuilder = <super::v1::Request as Metadata>::PathBuilder;
40    const PATH_BUILDER: Self::PathBuilder =
41        SinglePath::new("/_matrix/federation/unstable/org.matrix.msc2946/hierarchy/{room_id}");
42}
43
44impl From<super::v1::Request> for Request {
45    fn from(value: super::v1::Request) -> Self {
46        let super::v1::Request { room_id, suggested_only } = value;
47        Self { room_id, suggested_only }
48    }
49}
50
51impl From<Request> for super::v1::Request {
52    fn from(value: Request) -> Self {
53        let Request { room_id, suggested_only } = value;
54        Self { room_id, suggested_only }
55    }
56}
57
58/// Response type for the `hierarchy` endpoint.
59#[response]
60pub struct Response {
61    /// A summary of the space’s children.
62    ///
63    /// Rooms which the requesting server cannot peek/join will be excluded.
64    pub children: Vec<RoomSummary>,
65
66    /// The list of room IDs the requesting server doesn’t have a viable way to peek/join.
67    ///
68    /// Rooms which the responding server cannot provide details on will be outright
69    /// excluded from the response instead.
70    pub inaccessible_children: Vec<OwnedRoomId>,
71
72    /// A summary of the requested room.
73    pub room: SpaceHierarchyParentSummary,
74}
75
76impl Response {
77    /// Creates a new `Response` with the given room summary.
78    pub fn new(room_summary: SpaceHierarchyParentSummary) -> Self {
79        Self { children: Vec::new(), inaccessible_children: Vec::new(), room: room_summary }
80    }
81}
82
83impl From<super::v1::Response> for Response {
84    fn from(value: super::v1::Response) -> Self {
85        let super::v1::Response { children, inaccessible_children, room } = value;
86        Self { children, inaccessible_children, room }
87    }
88}
89
90impl From<Response> for super::v1::Response {
91    fn from(value: Response) -> Self {
92        let Response { children, inaccessible_children, room } = value;
93        Self { children, inaccessible_children, room }
94    }
95}