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