ruma_federation_api/event/get_stripped_state.rs
1//! `POST /_matrix/federation/*/stripped_state/{room_id}`
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 OwnedRoomId,
15 api::{request, response},
16 metadata,
17 serde::Raw,
18 };
19 use ruma_events::{AnyStrippedStateEvent, StateEventType};
20
21 use crate::authentication::ServerSignatures;
22
23 metadata! {
24 method: POST,
25 rate_limited: true,
26 authentication: ServerSignatures,
27 path: "/_matrix/federation/unstable/org.continuwuity.msc4560.stripped_state/{room_id}",
28 }
29
30 /// Request type for the `get_stripped_state` endpoint.
31 #[request]
32 pub struct Request {
33 /// The room to look up the state for.
34 #[ruma_api(path)]
35 pub room_id: OwnedRoomId,
36
37 /// A list of state event types to fetch.
38 ///
39 /// This may only include event types listed in
40 /// [`ruma_events::ALLOWED_STRIPPED_STATE_EVENTS`].
41 ///
42 /// Defaults to an empty `BTreeSet`.
43 #[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
44 pub state: BTreeSet<StateEventType>,
45
46 /// Controls whether the response will include the number of members
47 /// joined to the room.
48 ///
49 /// Defaults to `false`.
50 #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")]
51 pub num_joined_members: bool,
52 }
53
54 impl Request {
55 /// Creates a new `Request` with the given room ID.
56 pub fn new(room_id: OwnedRoomId) -> Self {
57 Self { room_id, state: BTreeSet::new(), num_joined_members: false }
58 }
59
60 /// Returns whether this `Request` requests no data from the server.
61 pub fn is_empty(&self) -> bool {
62 let Self { room_id: _, state, num_joined_members } = &self;
63
64 state.is_empty() && !*num_joined_members
65 }
66 }
67
68 /// Response type for the `get_stripped_state` endpoint.
69 #[response]
70 #[derive(Default)]
71 pub struct Response {
72 /// The requested stripped state events.
73 pub state: Vec<Raw<AnyStrippedStateEvent>>,
74
75 /// The number of members joined to the room, if `num_joined_members` was
76 /// set to `true` in the request.
77 #[serde(skip_serializing_if = "Option::is_none")]
78 pub num_joined_members: Option<UInt>,
79 }
80
81 impl Response {
82 /// Creates a new empty `Response`.
83 pub fn new() -> Self {
84 Self::default()
85 }
86 }
87}