From 1af32774e26ae4de54e2c6333e753f0aa01cd642 Mon Sep 17 00:00:00 2001 From: Jonas Richard Richter Date: Mon, 9 Dec 2024 10:55:48 +0100 Subject: [PATCH 1/5] feat(ffi): Add method to send custom events with JSON content --- bindings/matrix-sdk-ffi/src/room.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/bindings/matrix-sdk-ffi/src/room.rs b/bindings/matrix-sdk-ffi/src/room.rs index eeb6eb4af17..5b3e28c6cf5 100644 --- a/bindings/matrix-sdk-ffi/src/room.rs +++ b/bindings/matrix-sdk-ffi/src/room.rs @@ -378,6 +378,26 @@ 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 as JSON string. + pub async fn send_custom_event( + &self, + event_type: String, + content: String, + ) -> Result<(), ClientError> { + let content_json: serde_json::Value = match serde_json::from_str(&content) { + Ok(json) => json, + Err(e) => return Err(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 From bdf7739e66da1d62153badacf914c60892cd2175 Mon Sep 17 00:00:00 2001 From: Jonas Richard Richter Date: Mon, 9 Dec 2024 10:58:59 +0100 Subject: [PATCH 2/5] chore: Update changelog --- bindings/matrix-sdk-ffi/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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` From c769e22b5a840222d45bd220e02d29f4cdc3dda0 Mon Sep 17 00:00:00 2001 From: Jonas Richard Richter Date: Mon, 9 Dec 2024 11:18:42 +0100 Subject: [PATCH 3/5] fix(ffi): Fix formatting --- bindings/matrix-sdk-ffi/src/room.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bindings/matrix-sdk-ffi/src/room.rs b/bindings/matrix-sdk-ffi/src/room.rs index 5b3e28c6cf5..b20e3f1b5ab 100644 --- a/bindings/matrix-sdk-ffi/src/room.rs +++ b/bindings/matrix-sdk-ffi/src/room.rs @@ -392,7 +392,9 @@ impl Room { ) -> Result<(), ClientError> { let content_json: serde_json::Value = match serde_json::from_str(&content) { Ok(json) => json, - Err(e) => return Err(ClientError::Generic { msg: format!("Failed to parse JSON: {}", e) }), + Err(e) => { + return Err(ClientError::Generic { msg: format!("Failed to parse JSON: {}", e) }) + } }; self.inner.send_raw(&event_type, content_json).await?; Ok(()) From 4e3a88842749757452f426137fb1a86a9a0d3723 Mon Sep 17 00:00:00 2001 From: Jonas Richard Richter Date: Mon, 9 Dec 2024 15:47:54 +0100 Subject: [PATCH 4/5] fix(ffi): Add requested improvements --- bindings/matrix-sdk-ffi/src/room.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/room.rs b/bindings/matrix-sdk-ffi/src/room.rs index b20e3f1b5ab..9cf6d66a5b9 100644 --- a/bindings/matrix-sdk-ffi/src/room.rs +++ b/bindings/matrix-sdk-ffi/src/room.rs @@ -384,19 +384,17 @@ impl Room { /// /// * `event_type` - The type of the event to send. /// - /// * `content` - The content of the event to send as JSON string. - pub async fn send_custom_event( + /// * `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 = match serde_json::from_str(&content) { - Ok(json) => json, - Err(e) => { - return Err(ClientError::Generic { msg: format!("Failed to parse JSON: {}", e) }) - } - }; + 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(()) } From 12794bcb193d2e8d3eef60deefe15e5a1ed0dec2 Mon Sep 17 00:00:00 2001 From: Jonas Richard Richter Date: Tue, 10 Dec 2024 07:54:56 +0100 Subject: [PATCH 5/5] fix(ffi): Fix formatting --- bindings/matrix-sdk-ffi/src/room.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/room.rs b/bindings/matrix-sdk-ffi/src/room.rs index 9cf6d66a5b9..47712d0ddf8 100644 --- a/bindings/matrix-sdk-ffi/src/room.rs +++ b/bindings/matrix-sdk-ffi/src/room.rs @@ -385,16 +385,12 @@ impl Room { /// * `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> { + 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(()) }