ruma_federation_api/membership/create_invite/
v1.rs1use ruma_common::{
6 api::{request, response},
7 metadata, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedServerName, OwnedUserId,
8};
9use ruma_events::{room::member::RoomMemberEventContent, StateEventType};
10use serde::{Deserialize, Serialize};
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/v1/invite/{room_id}/{event_id}",
20}
21
22#[request]
24pub struct Request {
25 #[ruma_api(path)]
27 pub room_id: OwnedRoomId,
28
29 #[ruma_api(path)]
31 pub event_id: OwnedEventId,
32
33 pub sender: OwnedUserId,
35
36 pub origin: OwnedServerName,
38
39 pub origin_server_ts: MilliSecondsSinceUnixEpoch,
41
42 #[serde(rename = "type")]
44 pub kind: StateEventType,
45
46 pub state_key: OwnedUserId,
48
49 pub content: RoomMemberEventContent,
51
52 #[serde(default, skip_serializing_if = "UnsignedEventContent::is_empty")]
54 pub unsigned: UnsignedEventContent,
55}
56
57#[response]
59pub struct Response {
60 #[ruma_api(body)]
62 #[serde(with = "crate::serde::v1_pdu")]
63 pub event: Box<RawJsonValue>,
64}
65
66#[derive(Clone, Debug, Default, Serialize, Deserialize)]
68#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
69pub struct UnsignedEventContent {
70 #[serde(skip_serializing_if = "<[_]>::is_empty")]
74 pub invite_room_state: Vec<RawStrippedState>,
75}
76
77impl UnsignedEventContent {
78 pub fn new() -> Self {
80 Default::default()
81 }
82
83 pub fn is_empty(&self) -> bool {
85 self.invite_room_state.is_empty()
86 }
87}
88
89#[derive(Debug)]
91#[allow(clippy::exhaustive_structs)]
92pub struct RequestInit {
93 pub room_id: OwnedRoomId,
95
96 pub event_id: OwnedEventId,
98
99 pub sender: OwnedUserId,
101
102 pub origin: OwnedServerName,
104
105 pub origin_server_ts: MilliSecondsSinceUnixEpoch,
107
108 pub state_key: OwnedUserId,
110
111 pub content: RoomMemberEventContent,
113
114 pub unsigned: UnsignedEventContent,
116}
117
118impl From<RequestInit> for Request {
119 fn from(init: RequestInit) -> Self {
121 Self {
122 room_id: init.room_id,
123 event_id: init.event_id,
124 sender: init.sender,
125 origin: init.origin,
126 origin_server_ts: init.origin_server_ts,
127 kind: StateEventType::RoomMember,
128 state_key: init.state_key,
129 content: init.content,
130 unsigned: init.unsigned,
131 }
132 }
133}
134
135impl Response {
136 pub fn new(event: Box<RawJsonValue>) -> Self {
138 Self { event }
139 }
140}