From a3061eb39ae6c0abd5d75fce79947450416f0807 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Wed, 1 May 2024 11:35:36 +0200 Subject: [PATCH] ffi: make RoomListItem::is_direct sync again And comment why some methods it's calling are async under the hood. --- bindings/matrix-sdk-ffi/src/room_list.rs | 4 ++-- crates/matrix-sdk-base/src/rooms/normal.rs | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/room_list.rs b/bindings/matrix-sdk-ffi/src/room_list.rs index 8cf412ae533..19d439addd5 100644 --- a/bindings/matrix-sdk-ffi/src/room_list.rs +++ b/bindings/matrix-sdk-ffi/src/room_list.rs @@ -498,8 +498,8 @@ impl RoomListItem { self.inner.avatar_url().map(|uri| uri.to_string()) } - async fn is_direct(&self) -> bool { - self.inner.inner_room().is_direct().await.unwrap_or(false) + fn is_direct(&self) -> bool { + RUNTIME.block_on(self.inner.inner_room().is_direct()).unwrap_or(false) } fn canonical_alias(&self) -> Option { diff --git a/crates/matrix-sdk-base/src/rooms/normal.rs b/crates/matrix-sdk-base/src/rooms/normal.rs index f37bab13620..4b4b465c187 100644 --- a/crates/matrix-sdk-base/src/rooms/normal.rs +++ b/crates/matrix-sdk-base/src/rooms/normal.rs @@ -323,12 +323,15 @@ impl Room { } /// Is this room considered a direct message. + /// + /// Async because it can read room info from storage. #[instrument(skip_all, fields(room_id = ?self.room_id))] pub async fn is_direct(&self) -> StoreResult { match self.state() { RoomState::Joined | RoomState::Left => { Ok(!self.inner.read().base_info.dm_targets.is_empty()) } + RoomState::Invited => { let member = self.get_member(self.own_user_id()).await?; @@ -679,6 +682,8 @@ impl Room { /// Returns `None` if the member was never part of this room, otherwise /// return a `RoomMember` that can be in a joined, invited, left, banned /// state. + /// + /// Async because it can read from storage. pub async fn get_member(&self, user_id: &UserId) -> StoreResult> { let Some(raw_event) = self.store.get_member_event(self.room_id(), user_id).await? else { debug!(%user_id, "Member event not found in state store"); @@ -699,6 +704,8 @@ impl Room { } /// The current `MemberRoomInfo` for this room. + /// + /// Async because it can read from storage. async fn member_room_info<'a>( &self, display_names: &'a [String],