Skip to content

Commit 7dba05f

Browse files
authored
feat(sdk): Add Room::report_room
solves this #4681 - add room report_room api from https://spec.matrix.org/latest/client-server-api/#post_matrixclientv3roomsroomidreport - expose report_room on room ffi --------- Signed-off-by: hanadi92 <hanadi.tamimi@gmail.com>
1 parent f02a7d1 commit 7dba05f

File tree

5 files changed

+62
-2
lines changed

5 files changed

+62
-2
lines changed

bindings/matrix-sdk-ffi/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ Additions:
3838
- Add `ClientBuilder::room_key_recipient_strategy`
3939
- Add `Room::send_raw`
4040
- Expose `withdraw_verification` to `UserIdentity`
41+
- Expose `report_room` to `Room`

bindings/matrix-sdk-ffi/src/room.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use matrix_sdk::{
1313
use matrix_sdk_ui::timeline::{default_event_filter, RoomExt};
1414
use mime::Mime;
1515
use ruma::{
16-
api::client::room::report_content,
16+
api::client::room::{report_content, report_room},
1717
assign,
1818
events::{
1919
call::notify,
@@ -389,6 +389,24 @@ impl Room {
389389
Ok(())
390390
}
391391

392+
/// Reports a room as inappropriate to the server.
393+
/// The caller is not required to be joined to the room to report it.
394+
///
395+
/// # Arguments
396+
///
397+
/// * `reason` - The reason the room is being reported.
398+
///
399+
/// # Errors
400+
///
401+
/// Returns an error if the room is not found or on rate limit
402+
pub async fn report_room(&self, reason: Option<String>) -> Result<(), ClientError> {
403+
let mut request = report_room::v3::Request::new(self.inner.room_id().into());
404+
request.reason = reason;
405+
406+
self.inner.client().send(request).await?;
407+
Ok(())
408+
}
409+
392410
/// Ignores a user.
393411
///
394412
/// # Arguments

crates/matrix-sdk/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ simpler methods:
2828
- [**breaking**] The HTTP client only allows TLS 1.2 or newer, as recommended by
2929
[BCP 195](https://datatracker.ietf.org/doc/bcp195/).
3030
([#4647](https://github.com/matrix-org/matrix-rust-sdk/pull/4647))
31+
- Add `Room::report_room` api. ([#4713](https://github.com/matrix-org/matrix-rust-sdk/pull/4713))
3132

3233
### Bug Fixes
3334

crates/matrix-sdk/src/room/mod.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ use ruma::{
7474
read_marker::set_read_marker,
7575
receipt::create_receipt,
7676
redact::redact_event,
77-
room::{get_room_event, report_content},
77+
room::{get_room_event, report_content, report_room},
7878
state::{get_state_events_for_key, send_state_event},
7979
tag::{create_tag, delete_tag},
8080
typing::create_typing_event::{self, v3::Typing},
@@ -3021,6 +3021,23 @@ impl Room {
30213021
Ok(self.client.send(request).await?)
30223022
}
30233023

3024+
/// Reports a room as inappropriate to the server.
3025+
/// The caller is not required to be joined to the room to report it.
3026+
///
3027+
/// # Arguments
3028+
///
3029+
/// * `reason` - The reason the room is being reported.
3030+
///
3031+
/// # Errors
3032+
///
3033+
/// Returns an error if the room is not found or on rate limit
3034+
pub async fn report_room(&self, reason: Option<String>) -> Result<report_room::v3::Response> {
3035+
let mut request = report_room::v3::Request::new(self.inner.room_id().to_owned());
3036+
request.reason = reason;
3037+
3038+
Ok(self.client.send(request).await?)
3039+
}
3040+
30243041
/// Set a flag on the room to indicate that the user has explicitly marked
30253042
/// it as (un)read.
30263043
pub async fn set_unread_flag(&self, unread: bool) -> Result<()> {

crates/matrix-sdk/tests/integration/room/joined.rs

+23
Original file line numberDiff line numberDiff line change
@@ -1186,3 +1186,26 @@ async fn test_room_member_updates_sender_on_partial_members_update() {
11861186
assert_let!(RoomMembersUpdate::Partial(user_ids) = next);
11871187
assert_eq!(user_ids, BTreeSet::from_iter(vec![user_id!("@alice:b.c").to_owned()]));
11881188
}
1189+
1190+
#[async_test]
1191+
async fn test_report_room() {
1192+
let (client, server) = logged_in_client_with_server().await;
1193+
let reason = "this makes me sad";
1194+
1195+
Mock::given(method("POST"))
1196+
.and(path_regex(r"^/_matrix/client/.*/rooms/.*/report$"))
1197+
.and(body_json(json!({
1198+
"reason": reason,
1199+
})))
1200+
.and(header("authorization", "Bearer 1234"))
1201+
.respond_with(ResponseTemplate::new(200).set_body_json(&*test_json::EMPTY))
1202+
.mount(&server)
1203+
.await;
1204+
1205+
mock_sync(&server, &*test_json::SYNC, None).await;
1206+
let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));
1207+
let _response = client.sync_once(sync_settings).await.unwrap();
1208+
let room = client.get_room(&DEFAULT_TEST_ROOM_ID).unwrap();
1209+
1210+
room.report_room(Some(reason.to_owned())).await.unwrap();
1211+
}

0 commit comments

Comments
 (0)