ruma_client_api/space/
get_hierarchy.rs1pub mod v1 {
6 use js_int::UInt;
11 use ruma_common::{
12 api::{request, response, Metadata},
13 metadata, OwnedRoomId,
14 };
15
16 use crate::space::SpaceHierarchyRoomsChunk;
17
18 const METADATA: Metadata = metadata! {
19 method: GET,
20 rate_limited: true,
21 authentication: AccessToken,
22 history: {
23 unstable => "/_matrix/client/unstable/org.matrix.msc2946/rooms/:room_id/hierarchy",
24 1.2 => "/_matrix/client/v1/rooms/:room_id/hierarchy",
25 }
26 };
27
28 #[request(error = crate::Error)]
30 pub struct Request {
31 #[ruma_api(path)]
33 pub room_id: OwnedRoomId,
34
35 #[ruma_api(query)]
40 pub from: Option<String>,
41
42 #[ruma_api(query)]
44 pub limit: Option<UInt>,
45
46 #[ruma_api(query)]
50 pub max_depth: Option<UInt>,
51
52 #[ruma_api(query)]
58 #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")]
59 pub suggested_only: bool,
60 }
61
62 #[response(error = crate::Error)]
64 #[derive(Default)]
65 pub struct Response {
66 #[serde(skip_serializing_if = "Option::is_none")]
70 pub next_batch: Option<String>,
71
72 pub rooms: Vec<SpaceHierarchyRoomsChunk>,
74 }
75
76 impl Request {
77 pub fn new(room_id: OwnedRoomId) -> Self {
79 Self { room_id, from: None, limit: None, max_depth: None, suggested_only: false }
80 }
81 }
82
83 impl Response {
84 pub fn new() -> Self {
86 Default::default()
87 }
88 }
89}
90
91#[cfg(all(test, feature = "client"))]
92mod tests {
93 use ruma_common::api::IncomingResponse;
94 use serde_json::{json, to_vec as to_json_vec};
95
96 use super::v1::Response;
97
98 #[test]
99 fn deserialize_response() {
100 let body = json!({
101 "rooms": [
102 {
103 "room_id": "!room:localhost",
104 "num_joined_members": 5,
105 "world_readable": false,
106 "guest_can_join": false,
107 "join_rule": "restricted",
108 "allowed_room_ids": ["!otherroom:localhost"],
109 "children_state": [
110 {
111 "content": {
112 "via": [
113 "example.org"
114 ]
115 },
116 "origin_server_ts": 1_629_413_349,
117 "sender": "@alice:example.org",
118 "state_key": "!a:example.org",
119 "type": "m.space.child"
120 }
121 ],
122 },
123 ],
124 });
125 let response = http::Response::new(to_json_vec(&body).unwrap());
126
127 let response = Response::try_from_http_response(response).unwrap();
128 let room = &response.rooms[0];
129 assert_eq!(room.room_id, "!room:localhost");
130 let space_child = room.children_state[0].deserialize().unwrap();
131 assert_eq!(space_child.state_key, "!a:example.org");
132 }
133}