diff --git a/bindings/matrix-sdk-ffi/CHANGELOG.md b/bindings/matrix-sdk-ffi/CHANGELOG.md index b18f93b475e..4f2d2f570df 100644 --- a/bindings/matrix-sdk-ffi/CHANGELOG.md +++ b/bindings/matrix-sdk-ffi/CHANGELOG.md @@ -38,3 +38,4 @@ Additions: - Add `ClientBuilder::room_key_recipient_strategy` - Add `Room::send_raw` - Expose `withdraw_verification` to `UserIdentity` +- Expose `report_room` to `Room` diff --git a/bindings/matrix-sdk-ffi/src/room.rs b/bindings/matrix-sdk-ffi/src/room.rs index 59198535fc3..ee66e5b3fef 100644 --- a/bindings/matrix-sdk-ffi/src/room.rs +++ b/bindings/matrix-sdk-ffi/src/room.rs @@ -13,7 +13,7 @@ use matrix_sdk::{ use matrix_sdk_ui::timeline::{default_event_filter, RoomExt}; use mime::Mime; use ruma::{ - api::client::room::report_content, + api::client::room::{report_content, report_room}, assign, events::{ call::notify, @@ -389,6 +389,24 @@ impl Room { Ok(()) } + /// Reports a room as inappropriate to the server. + /// The caller is not required to be joined to the room to report it. + /// + /// # Arguments + /// + /// * `reason` - The reason the room is being reported. + /// + /// # Errors + /// + /// Returns an error if the room is not found or on rate limit + pub async fn report_room(&self, reason: Option) -> Result<(), ClientError> { + let mut request = report_room::v3::Request::new(self.inner.room_id().into()); + request.reason = reason; + + self.inner.client().send(request).await?; + Ok(()) + } + /// Ignores a user. /// /// # Arguments diff --git a/crates/matrix-sdk/CHANGELOG.md b/crates/matrix-sdk/CHANGELOG.md index b274cd2c5f9..60968b26e56 100644 --- a/crates/matrix-sdk/CHANGELOG.md +++ b/crates/matrix-sdk/CHANGELOG.md @@ -28,6 +28,7 @@ simpler methods: - [**breaking**] The HTTP client only allows TLS 1.2 or newer, as recommended by [BCP 195](https://datatracker.ietf.org/doc/bcp195/). ([#4647](https://github.com/matrix-org/matrix-rust-sdk/pull/4647)) +- Add `Room::report_room` api. ([#4713](https://github.com/matrix-org/matrix-rust-sdk/pull/4713)) ### Bug Fixes diff --git a/crates/matrix-sdk/src/room/mod.rs b/crates/matrix-sdk/src/room/mod.rs index 43488c0cc6d..490b41476b6 100644 --- a/crates/matrix-sdk/src/room/mod.rs +++ b/crates/matrix-sdk/src/room/mod.rs @@ -74,7 +74,7 @@ use ruma::{ read_marker::set_read_marker, receipt::create_receipt, redact::redact_event, - room::{get_room_event, report_content}, + room::{get_room_event, report_content, report_room}, state::{get_state_events_for_key, send_state_event}, tag::{create_tag, delete_tag}, typing::create_typing_event::{self, v3::Typing}, @@ -3021,6 +3021,23 @@ impl Room { Ok(self.client.send(request).await?) } + /// Reports a room as inappropriate to the server. + /// The caller is not required to be joined to the room to report it. + /// + /// # Arguments + /// + /// * `reason` - The reason the room is being reported. + /// + /// # Errors + /// + /// Returns an error if the room is not found or on rate limit + pub async fn report_room(&self, reason: Option) -> Result { + let mut request = report_room::v3::Request::new(self.inner.room_id().to_owned()); + request.reason = reason; + + Ok(self.client.send(request).await?) + } + /// Set a flag on the room to indicate that the user has explicitly marked /// it as (un)read. pub async fn set_unread_flag(&self, unread: bool) -> Result<()> { diff --git a/crates/matrix-sdk/tests/integration/room/joined.rs b/crates/matrix-sdk/tests/integration/room/joined.rs index a5511446421..3909ae44b7a 100644 --- a/crates/matrix-sdk/tests/integration/room/joined.rs +++ b/crates/matrix-sdk/tests/integration/room/joined.rs @@ -1186,3 +1186,26 @@ async fn test_room_member_updates_sender_on_partial_members_update() { assert_let!(RoomMembersUpdate::Partial(user_ids) = next); assert_eq!(user_ids, BTreeSet::from_iter(vec![user_id!("@alice:b.c").to_owned()])); } + +#[async_test] +async fn test_report_room() { + let (client, server) = logged_in_client_with_server().await; + let reason = "this makes me sad"; + + Mock::given(method("POST")) + .and(path_regex(r"^/_matrix/client/.*/rooms/.*/report$")) + .and(body_json(json!({ + "reason": reason, + }))) + .and(header("authorization", "Bearer 1234")) + .respond_with(ResponseTemplate::new(200).set_body_json(&*test_json::EMPTY)) + .mount(&server) + .await; + + mock_sync(&server, &*test_json::SYNC, None).await; + let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000)); + let _response = client.sync_once(sync_settings).await.unwrap(); + let room = client.get_room(&DEFAULT_TEST_ROOM_ID).unwrap(); + + room.report_room(Some(reason.to_owned())).await.unwrap(); +}