ruma_federation_api/membership/create_invite/
v2.rs

1//! `/v2/` ([spec])
2//!
3//! [spec]: https://spec.matrix.org/latest/server-server-api/#put_matrixfederationv2inviteroomideventid
4
5#[cfg(feature = "unstable-msc4125")]
6use ruma_common::OwnedServerName;
7use ruma_common::{
8    api::{request, response},
9    metadata, OwnedEventId, OwnedRoomId, RoomVersionId,
10};
11use serde_json::value::RawValue as RawJsonValue;
12
13use crate::{authentication::ServerSignatures, membership::RawStrippedState};
14
15metadata! {
16    method: PUT,
17    rate_limited: false,
18    authentication: ServerSignatures,
19    path: "/_matrix/federation/v2/invite/{room_id}/{event_id}",
20}
21
22/// Request type for the `create_invite` endpoint.
23#[request]
24pub struct Request {
25    /// The room ID that the user is being invited to.
26    #[ruma_api(path)]
27    pub room_id: OwnedRoomId,
28
29    /// The event ID for the invite event, generated by the inviting server.
30    #[ruma_api(path)]
31    pub event_id: OwnedEventId,
32
33    /// The version of the room where the user is being invited to.
34    pub room_version: RoomVersionId,
35
36    /// The invite event which needs to be signed.
37    pub event: Box<RawJsonValue>,
38
39    /// An optional list of simplified events to help the receiver of the invite identify the room.
40    pub invite_room_state: Vec<RawStrippedState>,
41
42    /// An optional list of servers the invited homeserver should attempt to join or leave via,
43    /// according to [MSC4125](https://github.com/matrix-org/matrix-spec-proposals/pull/4125).
44    ///
45    /// If present, it must not be empty.
46    #[cfg(feature = "unstable-msc4125")]
47    #[serde(skip_serializing_if = "Option::is_none", rename = "org.matrix.msc4125.via")]
48    pub via: Option<Vec<OwnedServerName>>,
49}
50
51/// Response type for the `create_invite` endpoint.
52#[response]
53pub struct Response {
54    /// The signed invite event.
55    pub event: Box<RawJsonValue>,
56}
57
58impl Request {
59    /// Creates a new `Request` with the given room ID, event ID, room version, event and invite
60    /// room state.
61    pub fn new(
62        room_id: OwnedRoomId,
63        event_id: OwnedEventId,
64        room_version: RoomVersionId,
65        event: Box<RawJsonValue>,
66        invite_room_state: Vec<RawStrippedState>,
67    ) -> Self {
68        Self {
69            room_id,
70            event_id,
71            room_version,
72            event,
73            invite_room_state,
74            #[cfg(feature = "unstable-msc4125")]
75            via: None,
76        }
77    }
78}
79
80impl Response {
81    /// Creates a new `Response` with the given invite event.
82    pub fn new(event: Box<RawJsonValue>) -> Self {
83        Self { event }
84    }
85}