Skip to content

Commit

Permalink
ffi: make RoomListItem::is_direct sync again
Browse files Browse the repository at this point in the history
And comment why some methods it's calling are async under the hood.
  • Loading branch information
bnjbvr committed May 1, 2024
1 parent ff40ef0 commit a3061eb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bindings/matrix-sdk-ffi/src/room_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
Expand Down
7 changes: 7 additions & 0 deletions crates/matrix-sdk-base/src/rooms/normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> {
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?;

Expand Down Expand Up @@ -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<Option<RoomMember>> {
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");
Expand All @@ -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],
Expand Down

0 comments on commit a3061eb

Please sign in to comment.