From 8d829ff49a1e33e6704367ec48cf1b20bce0ef63 Mon Sep 17 00:00:00 2001 From: Jonas Richard Richter Date: Tue, 10 Dec 2024 11:03:31 +0100 Subject: [PATCH] feat(ffi): Expose the method to send custom events with JSON content (#4390) This patch adds the Room::send_raw method to the bindings, making it usable from e.g. Swift. Signed-off-by: Jonas Richard Richter --- bindings/matrix-sdk-ffi/CHANGELOG.md | 1 + bindings/matrix-sdk-ffi/src/room.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/bindings/matrix-sdk-ffi/CHANGELOG.md b/bindings/matrix-sdk-ffi/CHANGELOG.md index 922f8f305c7..e41d3540d1e 100644 --- a/bindings/matrix-sdk-ffi/CHANGELOG.md +++ b/bindings/matrix-sdk-ffi/CHANGELOG.md @@ -33,3 +33,4 @@ Additions: - Add `Encryption::get_user_identity` which returns `UserIdentity` - Add `ClientBuilder::room_key_recipient_strategy` +- Add `Room::send_raw` diff --git a/bindings/matrix-sdk-ffi/src/room.rs b/bindings/matrix-sdk-ffi/src/room.rs index eeb6eb4af17..47712d0ddf8 100644 --- a/bindings/matrix-sdk-ffi/src/room.rs +++ b/bindings/matrix-sdk-ffi/src/room.rs @@ -378,6 +378,22 @@ impl Room { Ok(()) } + /// Send a raw event to the room. + /// + /// # Arguments + /// + /// * `event_type` - The type of the event to send. + /// + /// * `content` - The content of the event to send encoded as JSON string. + pub async fn send_raw(&self, event_type: String, content: String) -> Result<(), ClientError> { + let content_json: serde_json::Value = serde_json::from_str(&content) + .map_err(|e| ClientError::Generic { msg: format!("Failed to parse JSON: {e}") })?; + + self.inner.send_raw(&event_type, content_json).await?; + + Ok(()) + } + /// Redacts an event from the room. /// /// # Arguments