ruma_federation_api/membership/create_join_event/
v2.rs

1//! `/v2/` ([spec])
2//!
3//! [spec]: https://spec.matrix.org/latest/server-server-api/#put_matrixfederationv2send_joinroomideventid
4
5use ruma_common::{
6    OwnedEventId, OwnedRoomId,
7    api::{request, response},
8    metadata,
9};
10use serde::{Deserialize, Serialize};
11use serde_json::value::RawValue as RawJsonValue;
12
13use crate::authentication::ServerSignatures;
14
15metadata! {
16    method: PUT,
17    rate_limited: false,
18    authentication: ServerSignatures,
19    path: "/_matrix/federation/v2/send_join/{room_id}/{event_id}",
20}
21
22/// Request type for the `create_join_event` endpoint.
23#[request]
24pub struct Request {
25    /// The room ID that is about to be joined.
26    ///
27    /// Do not use this. Instead, use the `room_id` field inside the PDU.
28    #[ruma_api(path)]
29    pub room_id: OwnedRoomId,
30
31    /// The event ID for the join event.
32    #[ruma_api(path)]
33    pub event_id: OwnedEventId,
34
35    /// The PDU.
36    #[ruma_api(body)]
37    pub pdu: Box<RawJsonValue>,
38
39    /// Indicates whether the calling server can accept a reduced response.
40    ///
41    /// If `true`, membership events are omitted from `state` and redundant events are omitted from
42    /// `auth_chain` in the response.
43    ///
44    /// If the room to be joined has no `m.room.name` nor `m.room.canonical_alias` events in its
45    /// current state, the resident server should determine the room members who would be
46    /// included in the `m.heroes` property of the room summary as defined in the [Client-Server
47    /// `/sync` response]. The resident server should include these members' membership events in
48    /// the response `state` field, and include the auth chains for these membership events in
49    /// the response `auth_chain` field.
50    ///
51    /// [Client-Server `/sync` response]: https://spec.matrix.org/latest/client-server-api/#get_matrixclientv3sync
52    #[ruma_api(query)]
53    #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")]
54    pub omit_members: bool,
55}
56
57/// Response type for the `create_join_event` endpoint.
58#[response]
59pub struct Response {
60    /// Full state of the room.
61    #[ruma_api(body)]
62    pub room_state: RoomState,
63}
64
65impl Request {
66    /// Creates a new `Request` from the given room ID, event ID and PDU.
67    pub fn new(room_id: OwnedRoomId, event_id: OwnedEventId, pdu: Box<RawJsonValue>) -> Self {
68        Self { room_id, event_id, pdu, omit_members: false }
69    }
70}
71
72impl Response {
73    /// Creates a new `Response` with the given room state.
74    pub fn new(room_state: RoomState) -> Self {
75        Self { room_state }
76    }
77}
78
79/// Full state of the room.
80#[derive(Clone, Debug, Default, Deserialize, Serialize)]
81#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
82pub struct RoomState {
83    /// Whether `m.room.member` events have been omitted from `state`.
84    ///
85    /// Defaults to `false`.
86    #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")]
87    pub members_omitted: bool,
88
89    /// The full set of authorization events that make up the state of the room,
90    /// and their authorization events, recursively.
91    ///
92    /// If the request had `omit_members` set to `true`, then any events that are returned in
93    /// `state` may be omitted from `auth_chain`, whether or not membership events are omitted
94    /// from `state`.
95    pub auth_chain: Vec<Box<RawJsonValue>>,
96
97    /// The room state.
98    ///
99    /// If the request had `omit_members` set to `true`, events of type `m.room.member` may be
100    /// omitted from the response to reduce the size of the response. If this is done,
101    /// `members_omitted` must be set to `true`.
102    pub state: Vec<Box<RawJsonValue>>,
103
104    /// The signed copy of the membership event sent to other servers by the
105    /// resident server, including the resident server's signature.
106    ///
107    /// Required if the room version supports restricted join rules.
108    #[serde(skip_serializing_if = "Option::is_none")]
109    pub event: Option<Box<RawJsonValue>>,
110
111    /// A list of the servers active in the room (ie, those with joined members) before the join.
112    ///
113    /// Required if `members_omitted` is set to `true`.
114    #[serde(skip_serializing_if = "Option::is_none")]
115    pub servers_in_room: Option<Vec<String>>,
116}
117
118impl RoomState {
119    /// Creates an empty `RoomState`.
120    pub fn new() -> Self {
121        Self::default()
122    }
123}