ruma_client_api/state/get_stripped_state.rs
1//! `POST /_matrix/client/*/stripped_state/{room_id_or_alias}`
2//!
3//! Returns stripped state events in a room.
4
5pub mod unstable {
6 //! `/unstable/org.continuwuity.msc4560.stripped_state/` ([MSC4560])
7 //!
8 //! [MSC4560]: https://github.com/matrix-org/matrix-spec-proposals/pull/4560
9
10 use std::collections::BTreeSet;
11
12 use js_int::UInt;
13 use ruma_common::{
14 OwnedRoomOrAliasId, OwnedServerName,
15 api::{auth_scheme::AccessTokenOptional, request, response},
16 metadata,
17 serde::Raw,
18 };
19 use ruma_events::{AnyStrippedStateEvent, StateEventType};
20
21 /// The maximum number of vias that may be included in the request.
22 ///
23 /// If more than this many vias are included, `M_INVALID_PARAM` will be returned.
24 pub const MAX_VIAS: usize = 32;
25
26 metadata! {
27 method: POST,
28 rate_limited: true,
29 authentication: AccessTokenOptional,
30 history: {
31 unstable("org.continuwuity.msc4560") => "/_matrix/client/unstable/org.continuwuity.msc4560.stripped_state/{room_id_or_alias}",
32 }
33 }
34
35 /// Request type for the `get_stripped_state` endpoint.
36 #[request]
37 pub struct Request {
38 /// The room to look up the state for.
39 #[ruma_api(path)]
40 pub room_id_or_alias: OwnedRoomOrAliasId,
41
42 /// A list of servers the homeserver should attempt to use to fetch the room's state,
43 /// if it is not a resident of the room.
44 ///
45 /// Defaults to an empty `BTreeSet`.
46 #[serde(default, skip_serializing_if = "Vec::is_empty")]
47 #[ruma_api(query)]
48 pub via: Vec<OwnedServerName>,
49
50 /// A list of state event types to fetch.
51 ///
52 /// This may only include event types listed in
53 /// [`ruma_events::ALLOWED_STRIPPED_STATE_EVENTS`].
54 ///
55 /// Defaults to an empty `BTreeSet`.
56 #[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
57 pub state: BTreeSet<StateEventType>,
58
59 /// Controls whether the response will include the number of members
60 /// joined to the room.
61 ///
62 /// Defaults to `false`.
63 #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")]
64 pub num_joined_members: bool,
65 }
66
67 impl Request {
68 /// Creates a new `Request` with the given room ID or alias and the given vias.
69 pub fn new(room_id_or_alias: OwnedRoomOrAliasId, via: Vec<OwnedServerName>) -> Self {
70 Self { room_id_or_alias, via, state: BTreeSet::new(), num_joined_members: false }
71 }
72
73 /// Returns whether this `Request` requests no data from the server.
74 pub fn is_empty(&self) -> bool {
75 let Self { room_id_or_alias: _, via: _, state, num_joined_members } = &self;
76
77 state.is_empty() && !*num_joined_members
78 }
79 }
80
81 /// Response type for the `get_stripped_state` endpoint.
82 #[response]
83 pub struct Response {
84 /// The requested stripped state events.
85 pub state: Vec<Raw<AnyStrippedStateEvent>>,
86
87 /// The number of members joined to the room, if `num_joined_members` was
88 /// set to `true` in the request.
89 #[serde(skip_serializing_if = "Option::is_none")]
90 pub num_joined_members: Option<UInt>,
91
92 /// The server that provided the data included in this response.
93 ///
94 /// This will be
95 /// the local server's server name if it was able to generate the stripped state
96 /// locally.
97 pub via: OwnedServerName,
98 }
99
100 impl Response {
101 /// Creates a new `Response` with the given via.
102 pub fn new(via: OwnedServerName) -> Self {
103 Self { state: vec![], num_joined_members: None, via }
104 }
105 }
106}