Skip to main content

ruma_client_api/membership/
kick_user.rs

1//! `POST /_matrix/client/*/rooms/{roomId}/kick`
2//!
3//! Kick a user from a room.
4
5pub mod v3 {
6    //! `/v3/` ([spec])
7    //!
8    //! [spec]: https://spec.matrix.org/v1.18/client-server-api/#post_matrixclientv3roomsroomidkick
9
10    use ruma_common::{
11        OwnedRoomId, OwnedUserId,
12        api::{auth_scheme::AccessToken, request, response},
13        metadata,
14    };
15
16    metadata! {
17        method: POST,
18        rate_limited: false,
19        authentication: AccessToken,
20        history: {
21            1.0 => "/_matrix/client/r0/rooms/{room_id}/kick",
22            1.1 => "/_matrix/client/v3/rooms/{room_id}/kick",
23        }
24    }
25
26    /// Request type for the `kick_user` endpoint.
27    #[request]
28    pub struct Request {
29        /// The room to kick the user from.
30        #[ruma_api(path)]
31        pub room_id: OwnedRoomId,
32
33        /// The user to kick.
34        pub user_id: OwnedUserId,
35
36        /// The reason for kicking the user.
37        #[serde(skip_serializing_if = "Option::is_none")]
38        pub reason: Option<String>,
39
40        /// A flag indicating whether all the user's events should be immediately redacted.
41        ///
42        /// This uses the unstable prefix defined in [MSC4293].
43        ///
44        /// [MSC4293]: https://github.com/matrix-org/matrix-spec-proposals/pull/4293
45        #[cfg(feature = "unstable-msc4293")]
46        #[serde(
47            default,
48            rename = "org.matrix.msc4293.redact_events",
49            skip_serializing_if = "ruma_common::serde::is_default"
50        )]
51        pub redact_events: bool,
52    }
53
54    /// Response type for the `kick_user` endpoint.
55    #[response]
56    #[derive(Default)]
57    pub struct Response {}
58
59    impl Request {
60        /// Creates a new `Request` with the given room id and room id.
61        pub fn new(room_id: OwnedRoomId, user_id: OwnedUserId) -> Self {
62            Self {
63                room_id,
64                user_id,
65                reason: None,
66                #[cfg(feature = "unstable-msc4293")]
67                redact_events: false,
68            }
69        }
70    }
71
72    impl Response {
73        /// Creates an empty `Response`.
74        pub fn new() -> Self {
75            Self {}
76        }
77    }
78}