From ca025f8cca0b53cefe487ab10ffc61b350fd37cc Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Tue, 11 Mar 2025 09:59:31 +0200 Subject: [PATCH] feat(ffi): forget the room when rejecting invites - we're doing this as an extra layer of protection against spam attacks. --- bindings/matrix-sdk-ffi/src/room_preview.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/bindings/matrix-sdk-ffi/src/room_preview.rs b/bindings/matrix-sdk-ffi/src/room_preview.rs index e91459257..d9e7ba697 100644 --- a/bindings/matrix-sdk-ffi/src/room_preview.rs +++ b/bindings/matrix-sdk-ffi/src/room_preview.rs @@ -51,11 +51,23 @@ impl RoomPreview { /// Leave the room if the room preview state is either joined, invited or /// knocked. /// + /// If rejecting an invite then also forget it as an extra layer of + /// protection against spam attacks. + /// /// Will return an error otherwise. pub async fn leave(&self) -> Result<(), ClientError> { let room = self.client.get_room(&self.inner.room_id).context("missing room for a room preview")?; - room.leave().await.map_err(Into::into) + + let should_forget = matches!(room.state(), matrix_sdk::RoomState::Invited); + + room.leave().await.map_err(ClientError::from)?; + + if should_forget { + _ = self.forget().await; + } + + Ok(()) } /// Get the user who created the invite, if any.