ruma_client_api/membership/
leave_room.rs

1//! `POST /_matrix/client/*/rooms/{roomId}/leave`
2//!
3//! Leave a room.
4
5pub mod v3 {
6    //! `/v3/` ([spec])
7    //!
8    //! [spec]: https://spec.matrix.org/latest/client-server-api/#post_matrixclientv3roomsroomidleave
9
10    use ruma_common::{
11        api::{request, response, Metadata},
12        metadata, OwnedRoomId,
13    };
14
15    const METADATA: Metadata = metadata! {
16        method: POST,
17        rate_limited: true,
18        authentication: AccessToken,
19        history: {
20            1.0 => "/_matrix/client/r0/rooms/:room_id/leave",
21            1.1 => "/_matrix/client/v3/rooms/:room_id/leave",
22        }
23    };
24
25    /// Request type for the `leave_room` endpoint.
26    #[request(error = crate::Error)]
27    pub struct Request {
28        /// The room to leave.
29        #[ruma_api(path)]
30        pub room_id: OwnedRoomId,
31
32        /// Optional reason to be included as the `reason` on the subsequent membership event.
33        #[serde(skip_serializing_if = "Option::is_none")]
34        pub reason: Option<String>,
35    }
36
37    /// Response type for the `leave_room` endpoint.
38    #[response(error = crate::Error)]
39    #[derive(Default)]
40    pub struct Response {}
41
42    impl Request {
43        /// Creates a new `Request` with the given room id.
44        pub fn new(room_id: OwnedRoomId) -> Self {
45            Self { room_id, reason: None }
46        }
47    }
48
49    impl Response {
50        /// Creates an empty `Response`.
51        pub fn new() -> Self {
52            Self {}
53        }
54    }
55}