ruma_client_api/room/
report_room.rs

1//! `POST /_matrix/client/*/rooms/{roomId}/report`
2//!
3//! Report a room as inappropriate.
4
5pub mod v3 {
6    //! `/v3/` ([spec])
7    //!
8    //! [spec]: https://spec.matrix.org/latest/client-server-api/#post_matrixclientv3roomsroomidreport
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            unstable => "/_matrix/client/unstable/org.matrix.msc4151/rooms/{room_id}/report",
21            1.13 => "/_matrix/client/v3/rooms/{room_id}/report",
22        }
23    };
24
25    /// Request type for the `report_room` endpoint.
26    #[request(error = crate::Error)]
27    pub struct Request {
28        /// The ID of the room to report.
29        #[ruma_api(path)]
30        pub room_id: OwnedRoomId,
31
32        /// The reason to report the room, may be empty.
33        // We deserialize a missing field as an empty string for backwards compatibility. The field
34        // was initially specified as optional in Matrix 1.13 and then clarified as being required
35        // in Matrix 1.14 to align with its initial definition in MSC4151.
36        // See: https://github.com/matrix-org/matrix-spec/pull/2093#discussion_r1993171166
37        #[serde(default)]
38        pub reason: String,
39    }
40
41    /// Response type for the `report_room` endpoint.
42    #[response(error = crate::Error)]
43    #[derive(Default)]
44    pub struct Response {}
45
46    impl Request {
47        /// Creates a new `Request` with the given room ID and reason.
48        pub fn new(room_id: OwnedRoomId, reason: String) -> Self {
49            Self { room_id, reason }
50        }
51    }
52
53    impl Response {
54        /// Creates an empty `Response`.
55        pub fn new() -> Self {
56            Self {}
57        }
58    }
59}