From e81ed2741b4ebe98fe41cabdfee2ac28a52a8e37 Mon Sep 17 00:00:00 2001 From: strawberry Date: Tue, 1 Oct 2024 23:49:00 -0400 Subject: [PATCH] add room reporting as per MSC4151 Signed-off-by: strawberry --- crates/ruma-client-api/src/room.rs | 1 + .../ruma-client-api/src/room/report_room.rs | 57 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 crates/ruma-client-api/src/room/report_room.rs diff --git a/crates/ruma-client-api/src/room.rs b/crates/ruma-client-api/src/room.rs index b18c58fe..2253f495 100644 --- a/crates/ruma-client-api/src/room.rs +++ b/crates/ruma-client-api/src/room.rs @@ -7,6 +7,7 @@ pub mod get_room_event; #[cfg(feature = "unstable-msc3266")] pub mod get_summary; pub mod report_content; +pub mod report_room; pub mod upgrade_room; use ruma_common::serde::StringEnum; diff --git a/crates/ruma-client-api/src/room/report_room.rs b/crates/ruma-client-api/src/room/report_room.rs new file mode 100644 index 00000000..b845250b --- /dev/null +++ b/crates/ruma-client-api/src/room/report_room.rs @@ -0,0 +1,57 @@ +//! `POST /_matrix/client/*/rooms/{roomId}/report` +//! +//! Reports an abusive room. + +pub mod v3 { + //! `MSC4151` ([MSC]) + //! + //! [MSC]: https://github.com/matrix-org/matrix-spec-proposals/pull/4151 + + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedRoomId, + }; + + const METADATA: Metadata = metadata! { + method: POST, + rate_limited: false, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/unstable/org.matrix.msc4151/rooms/:room_id/report", + 1.0 => "/_matrix/client/v3/rooms/:room_id/report", + } + }; + + /// Request type for the `report_room` endpoint. + #[request(error = crate::Error)] + pub struct Request { + /// The room ID being reported. + #[ruma_api(path)] + pub room_id: OwnedRoomId, + + /// Reason to report room. + /// + /// May be blank. + #[serde(skip_serializing_if = "Option::is_none")] + pub reason: Option, + } + + /// Response type for the `report_room` endpoint. + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + + impl Request { + /// Creates a new `Request` with the given room ID and reason. + pub fn new(room_id: OwnedRoomId, reason: Option) -> Self { + Self { room_id, reason } + } + } + + impl Response { + /// Creates an empty `Response`. + pub fn new() -> Self { + Self {} + } + } +}