ruma_federation_api/membership/create_invite/
v1.rs1use ruma_common::{
6 MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedServerName, OwnedUserId,
7 api::{request, response},
8 metadata,
9};
10use ruma_events::{StateEventType, room::member::RoomMemberEventContent};
11use serde::{Deserialize, Serialize};
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/v1/invite/{room_id}/{event_id}",
21}
22
23#[request]
25pub struct Request {
26 #[ruma_api(path)]
28 pub room_id: OwnedRoomId,
29
30 #[ruma_api(path)]
32 pub event_id: OwnedEventId,
33
34 pub sender: OwnedUserId,
36
37 pub origin: OwnedServerName,
39
40 pub origin_server_ts: MilliSecondsSinceUnixEpoch,
42
43 #[serde(rename = "type")]
45 pub kind: StateEventType,
46
47 pub state_key: OwnedUserId,
49
50 pub content: RoomMemberEventContent,
52
53 #[serde(default, skip_serializing_if = "UnsignedEventContent::is_empty")]
55 pub unsigned: UnsignedEventContent,
56}
57
58#[response]
60pub struct Response {
61 #[ruma_api(body)]
63 #[serde(with = "crate::serde::v1_pdu")]
64 pub event: Box<RawJsonValue>,
65}
66
67#[derive(Clone, Debug, Default, Serialize, Deserialize)]
69#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
70pub struct UnsignedEventContent {
71 #[serde(skip_serializing_if = "<[_]>::is_empty")]
75 pub invite_room_state: Vec<RawStrippedState>,
76}
77
78impl UnsignedEventContent {
79 pub fn new() -> Self {
81 Default::default()
82 }
83
84 pub fn is_empty(&self) -> bool {
86 self.invite_room_state.is_empty()
87 }
88}
89
90#[derive(Debug)]
92#[allow(clippy::exhaustive_structs)]
93pub struct RequestInit {
94 pub room_id: OwnedRoomId,
96
97 pub event_id: OwnedEventId,
99
100 pub sender: OwnedUserId,
102
103 pub origin: OwnedServerName,
105
106 pub origin_server_ts: MilliSecondsSinceUnixEpoch,
108
109 pub state_key: OwnedUserId,
111
112 pub content: RoomMemberEventContent,
114
115 pub unsigned: UnsignedEventContent,
117}
118
119impl From<RequestInit> for Request {
120 fn from(init: RequestInit) -> Self {
122 Self {
123 room_id: init.room_id,
124 event_id: init.event_id,
125 sender: init.sender,
126 origin: init.origin,
127 origin_server_ts: init.origin_server_ts,
128 kind: StateEventType::RoomMember,
129 state_key: init.state_key,
130 content: init.content,
131 unsigned: init.unsigned,
132 }
133 }
134}
135
136impl Response {
137 pub fn new(event: Box<RawJsonValue>) -> Self {
139 Self { event }
140 }
141}