ffi: Add binding for get_dm_room

This commit is contained in:
Florian Renaud
2023-03-20 17:30:25 +01:00
committed by GitHub
parent 72ae9dd885
commit 76763a80fe
2 changed files with 10 additions and 1 deletions

View File

@@ -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<Arc<Room>> {
self.client.rooms().into_iter().map(|room| Arc::new(Room::new(room))).collect()
}
pub fn get_dm_room(&self, user_id: String) -> Result<Option<Arc<Room>>, 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 {

View File

@@ -339,7 +339,8 @@ impl Client {
Ok(())
}
fn get_dm_room(&self, user_id: &UserId) -> Option<room::Joined> {
/// Get the existing DM room with the given user, if any.
pub fn get_dm_room(&self, user_id: &UserId) -> Option<room::Joined> {
let rooms = self.joined_rooms();
// Find the room we share with the `user_id` and only with `user_id`