ruma_federation_api/
space.rs

1//! Spaces endpoints.
2
3use js_int::UInt;
4use ruma_common::{
5    room::RoomType, serde::Raw, space::SpaceRoomJoinRule, OwnedMxcUri, OwnedRoomAliasId,
6    OwnedRoomId,
7};
8use ruma_events::space::child::HierarchySpaceChildEvent;
9use serde::{Deserialize, Serialize};
10
11pub mod get_hierarchy;
12
13/// The summary of a parent space.
14///
15/// To create an instance of this type, first create a `SpaceHierarchyParentSummaryInit` and convert
16/// it via `SpaceHierarchyParentSummary::from` / `.into()`.
17#[derive(Clone, Debug, Deserialize, Serialize)]
18#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
19pub struct SpaceHierarchyParentSummary {
20    /// The canonical alias of the room, if any.
21    ///
22    /// If you activate the `compat-empty-string-null` feature, this field being an empty
23    /// string in JSON will result in `None` here during deserialization.
24    #[serde(skip_serializing_if = "Option::is_none")]
25    #[cfg_attr(
26        feature = "compat-empty-string-null",
27        serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none")
28    )]
29    pub canonical_alias: Option<OwnedRoomAliasId>,
30
31    /// The name of the room, if any.
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub name: Option<String>,
34
35    /// The number of members joined to the room.
36    pub num_joined_members: UInt,
37
38    /// The ID of the room.
39    pub room_id: OwnedRoomId,
40
41    /// The topic of the room, if any.
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub topic: Option<String>,
44
45    /// Whether the room may be viewed by guest users without joining.
46    pub world_readable: bool,
47
48    /// Whether guest users may join the room and participate in it.
49    ///
50    /// If they can, they will be subject to ordinary power level rules like any other user.
51    pub guest_can_join: bool,
52
53    /// The URL for the room's avatar, if one is set.
54    ///
55    /// If you activate the `compat-empty-string-null` feature, this field being an empty string in
56    /// JSON will result in `None` here during deserialization.
57    #[serde(skip_serializing_if = "Option::is_none")]
58    #[cfg_attr(
59        feature = "compat-empty-string-null",
60        serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none")
61    )]
62    pub avatar_url: Option<OwnedMxcUri>,
63
64    /// The join rule of the room.
65    #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")]
66    pub join_rule: SpaceRoomJoinRule,
67
68    /// The type of room from `m.room.create`, if any.
69    #[serde(skip_serializing_if = "Option::is_none")]
70    pub room_type: Option<RoomType>,
71
72    /// The stripped `m.space.child` events of the space-room.
73    ///
74    /// If the room is not a space-room, this should be empty.
75    pub children_state: Vec<Raw<HierarchySpaceChildEvent>>,
76
77    /// If the room is a restricted room, these are the room IDs which are specified by the join
78    /// rules.
79    #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")]
80    pub allowed_room_ids: Vec<OwnedRoomId>,
81}
82
83/// Initial set of mandatory fields of `SpaceHierarchyParentSummary`.
84///
85/// This struct will not be updated even if additional fields are added to
86/// `SpaceHierarchyParentSummary` in a new (non-breaking) release of the Matrix specification.
87#[derive(Debug)]
88#[allow(clippy::exhaustive_structs)]
89pub struct SpaceHierarchyParentSummaryInit {
90    /// The number of members joined to the room.
91    pub num_joined_members: UInt,
92
93    /// The ID of the room.
94    pub room_id: OwnedRoomId,
95
96    /// Whether the room may be viewed by guest users without joining.
97    pub world_readable: bool,
98
99    /// Whether guest users may join the room and participate in it.
100    ///
101    /// If they can, they will be subject to ordinary power level rules like any other user.
102    pub guest_can_join: bool,
103
104    /// The join rule of the room.
105    pub join_rule: SpaceRoomJoinRule,
106
107    /// The stripped `m.space.child` events of the space-room.
108    ///
109    /// If the room is not a space-room, this should be empty.
110    pub children_state: Vec<Raw<HierarchySpaceChildEvent>>,
111
112    /// If the room is a restricted room, these are the room IDs which are specified by the join
113    /// rules.
114    pub allowed_room_ids: Vec<OwnedRoomId>,
115}
116
117impl From<SpaceHierarchyParentSummaryInit> for SpaceHierarchyParentSummary {
118    fn from(init: SpaceHierarchyParentSummaryInit) -> Self {
119        let SpaceHierarchyParentSummaryInit {
120            num_joined_members,
121            room_id,
122            world_readable,
123            guest_can_join,
124            join_rule,
125            children_state,
126            allowed_room_ids,
127        } = init;
128
129        Self {
130            canonical_alias: None,
131            name: None,
132            num_joined_members,
133            room_id,
134            topic: None,
135            world_readable,
136            guest_can_join,
137            avatar_url: None,
138            join_rule,
139            room_type: None,
140            children_state,
141            allowed_room_ids,
142        }
143    }
144}
145
146/// The summary of a space's child.
147///
148/// To create an instance of this type, first create a `SpaceHierarchyChildSummaryInit` and convert
149/// it via `SpaceHierarchyChildSummary::from` / `.into()`.
150#[derive(Clone, Debug, Deserialize, Serialize)]
151#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
152pub struct SpaceHierarchyChildSummary {
153    /// The canonical alias of the room, if any.
154    ///
155    /// If you activate the `compat-empty-string-null` feature, this field being an empty string in
156    /// JSON will result in `None` here during deserialization.
157    #[serde(skip_serializing_if = "Option::is_none")]
158    #[cfg_attr(
159        feature = "compat-empty-string-null",
160        serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none")
161    )]
162    pub canonical_alias: Option<OwnedRoomAliasId>,
163
164    /// The name of the room, if any.
165    #[serde(skip_serializing_if = "Option::is_none")]
166    pub name: Option<String>,
167
168    /// The number of members joined to the room.
169    pub num_joined_members: UInt,
170
171    /// The ID of the room.
172    pub room_id: OwnedRoomId,
173
174    /// The topic of the room, if any.
175    #[serde(skip_serializing_if = "Option::is_none")]
176    pub topic: Option<String>,
177
178    /// Whether the room may be viewed by guest users without joining.
179    pub world_readable: bool,
180
181    /// Whether guest users may join the room and participate in it.
182    ///
183    /// If they can, they will be subject to ordinary power level rules like any other user.
184    pub guest_can_join: bool,
185
186    /// The URL for the room's avatar, if one is set.
187    ///
188    /// If you activate the `compat-empty-string-null` feature, this field being an empty string in
189    /// JSON will result in `None` here during deserialization.
190    #[serde(skip_serializing_if = "Option::is_none")]
191    #[cfg_attr(
192        feature = "compat-empty-string-null",
193        serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none")
194    )]
195    pub avatar_url: Option<OwnedMxcUri>,
196
197    /// The join rule of the room.
198    #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")]
199    pub join_rule: SpaceRoomJoinRule,
200
201    /// The type of room from `m.room.create`, if any.
202    #[serde(skip_serializing_if = "Option::is_none")]
203    pub room_type: Option<RoomType>,
204
205    /// If the room is a restricted room, these are the room IDs which are specified by the join
206    /// rules.
207    #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")]
208    pub allowed_room_ids: Vec<OwnedRoomId>,
209}
210
211/// Initial set of mandatory fields of `SpaceHierarchyChildSummary`.
212///
213/// This struct will not be updated even if additional fields are added to
214/// `SpaceHierarchyChildSummary` in a new (non-breaking) release of the Matrix specification.
215#[derive(Debug)]
216#[allow(clippy::exhaustive_structs)]
217pub struct SpaceHierarchyChildSummaryInit {
218    /// The number of members joined to the room.
219    pub num_joined_members: UInt,
220
221    /// The ID of the room.
222    pub room_id: OwnedRoomId,
223
224    /// Whether the room may be viewed by guest users without joining.
225    pub world_readable: bool,
226
227    /// Whether guest users may join the room and participate in it.
228    ///
229    /// If they can, they will be subject to ordinary power level rules like any other user.
230    pub guest_can_join: bool,
231
232    /// The join rule of the room.
233    pub join_rule: SpaceRoomJoinRule,
234
235    /// If the room is a restricted room, these are the room IDs which are specified by the join
236    /// rules.
237    pub allowed_room_ids: Vec<OwnedRoomId>,
238}
239
240impl From<SpaceHierarchyChildSummaryInit> for SpaceHierarchyChildSummary {
241    fn from(init: SpaceHierarchyChildSummaryInit) -> Self {
242        let SpaceHierarchyChildSummaryInit {
243            num_joined_members,
244            room_id,
245            world_readable,
246            guest_can_join,
247            join_rule,
248            allowed_room_ids,
249        } = init;
250
251        Self {
252            canonical_alias: None,
253            name: None,
254            num_joined_members,
255            room_id,
256            topic: None,
257            world_readable,
258            guest_can_join,
259            avatar_url: None,
260            join_rule,
261            room_type: None,
262            allowed_room_ids,
263        }
264    }
265}
266
267impl From<SpaceHierarchyParentSummary> for SpaceHierarchyChildSummary {
268    fn from(parent: SpaceHierarchyParentSummary) -> Self {
269        let SpaceHierarchyParentSummary {
270            canonical_alias,
271            name,
272            num_joined_members,
273            room_id,
274            topic,
275            world_readable,
276            guest_can_join,
277            avatar_url,
278            join_rule,
279            room_type,
280            children_state: _,
281            allowed_room_ids,
282        } = parent;
283
284        Self {
285            canonical_alias,
286            name,
287            num_joined_members,
288            room_id,
289            topic,
290            world_readable,
291            guest_can_join,
292            avatar_url,
293            join_rule,
294            room_type,
295            allowed_room_ids,
296        }
297    }
298}