From 76763a80fecac65f87fd5aaa34f93e36734d37cd Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Mon, 20 Mar 2023 17:30:25 +0100 Subject: [PATCH] ffi: Add binding for get_dm_room --- bindings/matrix-sdk-ffi/src/client.rs | 8 ++++++++ crates/matrix-sdk/src/encryption/mod.rs | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/bindings/matrix-sdk-ffi/src/client.rs b/bindings/matrix-sdk-ffi/src/client.rs index 96c33168f..f9698a983 100644 --- a/bindings/matrix-sdk-ffi/src/client.rs +++ b/bindings/matrix-sdk-ffi/src/client.rs @@ -3,6 +3,7 @@ use std::sync::{Arc, RwLock}; use anyhow::{anyhow, Context}; use matrix_sdk::{ media::{MediaFileHandle as SdkMediaFileHandle, MediaFormat, MediaRequest, MediaThumbnailSize}, + room::Room as SdkRoom, ruma::{ api::client::{ account::whoami, @@ -497,6 +498,13 @@ impl Client { pub fn rooms(&self) -> Vec> { self.client.rooms().into_iter().map(|room| Arc::new(Room::new(room))).collect() } + + pub fn get_dm_room(&self, user_id: String) -> Result>, ClientError> { + let user_id = UserId::parse(user_id)?; + let sdk_room = self.client.get_dm_room(&user_id).map(SdkRoom::Joined); + let dm = sdk_room.map(|room| Arc::new(Room::new(room))); + Ok(dm) + } } impl Client { diff --git a/crates/matrix-sdk/src/encryption/mod.rs b/crates/matrix-sdk/src/encryption/mod.rs index 9db51849d..2978591ca 100644 --- a/crates/matrix-sdk/src/encryption/mod.rs +++ b/crates/matrix-sdk/src/encryption/mod.rs @@ -339,7 +339,8 @@ impl Client { Ok(()) } - fn get_dm_room(&self, user_id: &UserId) -> Option { + /// Get the existing DM room with the given user, if any. + pub fn get_dm_room(&self, user_id: &UserId) -> Option { let rooms = self.joined_rooms(); // Find the room we share with the `user_id` and only with `user_id`