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