From 192b9ce808f9d08cbc2582fe76e9b38082811fbb Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Wed, 14 Jun 2023 10:59:03 +0200 Subject: [PATCH] feat(ui+ffi): Implement `Room::id` as a shortcut. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's possible to do `room.inner_room().room_id()` but it's just simpler to call `room.id()`. This patch adds this shortcut. It's especially useful for FFI users, where creating a “full room” (`room_item.full_room().room_id()`) may be expensive. --- bindings/matrix-sdk-ffi/src/room_list.rs | 4 ++++ crates/matrix-sdk-ui/src/room_list/room.rs | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/bindings/matrix-sdk-ffi/src/room_list.rs b/bindings/matrix-sdk-ffi/src/room_list.rs index 9cf93c82d..d4ea7d7fe 100644 --- a/bindings/matrix-sdk-ffi/src/room_list.rs +++ b/bindings/matrix-sdk-ffi/src/room_list.rs @@ -194,6 +194,10 @@ pub struct RoomListItem { #[uniffi::export] impl RoomListItem { + fn id(&self) -> String { + self.inner.id().to_string() + } + fn name(&self) -> Option { RUNTIME.block_on(async { self.inner.name().await }) } diff --git a/crates/matrix-sdk-ui/src/room_list/room.rs b/crates/matrix-sdk-ui/src/room_list/room.rs index 6d5c15963..afa6072a3 100644 --- a/crates/matrix-sdk-ui/src/room_list/room.rs +++ b/crates/matrix-sdk-ui/src/room_list/room.rs @@ -4,7 +4,7 @@ use std::sync::Arc; use async_once_cell::OnceCell as AsyncOnceCell; use matrix_sdk::{SlidingSync, SlidingSyncRoom}; -use ruma::api::client::sync::sync_events::v4::RoomSubscription; +use ruma::{api::client::sync::sync_events::v4::RoomSubscription, RoomId}; use super::Error; use crate::{timeline::EventTimelineItem, Timeline}; @@ -58,6 +58,11 @@ impl Room { }) } + /// Get the room ID. + pub fn id(&self) -> &RoomId { + self.inner.room.room_id() + } + /// Get the best possible name for the room. /// /// If the sliding sync room has received a name from the server, then use