ruma_federation_api/membership/create_leave_event/
v2.rs

1//! `/v2/` ([spec])
2//!
3//! [spec]: https://spec.matrix.org/latest/server-server-api/#put_matrixfederationv2send_leaveroomideventid
4
5use ruma_common::{
6    OwnedEventId, OwnedRoomId,
7    api::{request, response},
8    metadata,
9};
10use serde_json::value::RawValue as RawJsonValue;
11
12use crate::authentication::ServerSignatures;
13
14metadata! {
15    method: PUT,
16    rate_limited: false,
17    authentication: ServerSignatures,
18    path: "/_matrix/federation/v2/send_leave/{room_id}/{event_id}",
19}
20
21/// Request type for the `create_leave_event` endpoint.
22#[request]
23pub struct Request {
24    /// The room ID that is about to be left.
25    ///
26    /// Do not use this. Instead, use the `room_id` field inside the PDU.
27    #[ruma_api(path)]
28    pub room_id: OwnedRoomId,
29
30    /// The event ID for the leave event.
31    #[ruma_api(path)]
32    pub event_id: OwnedEventId,
33
34    /// The PDU.
35    #[ruma_api(body)]
36    pub pdu: Box<RawJsonValue>,
37}
38
39/// Response type for the `create_leave_event` endpoint.
40#[response]
41#[derive(Default)]
42pub struct Response {}
43
44impl Request {
45    /// Creates a new `Request` from the given room ID, event ID and PDU.
46    pub fn new(room_id: OwnedRoomId, event_id: OwnedEventId, pdu: Box<RawJsonValue>) -> Self {
47        Self { room_id, event_id, pdu }
48    }
49}
50
51impl Response {
52    /// Creates an empty `Response`.
53    pub fn new() -> Self {
54        Self {}
55    }
56}
57
58#[cfg(all(test, feature = "server"))]
59mod tests {
60    use ruma_common::api::OutgoingResponse;
61
62    use super::Response;
63
64    #[test]
65    fn response_body() {
66        let res = Response::new().try_into_http_response::<Vec<u8>>().unwrap();
67
68        assert_eq!(res.body(), b"{}");
69    }
70}