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