diff --git a/bindings/matrix-sdk-ffi/src/room_preview.rs b/bindings/matrix-sdk-ffi/src/room_preview.rs index 5de8e5981c..dfb261decf 100644 --- a/bindings/matrix-sdk-ffi/src/room_preview.rs +++ b/bindings/matrix-sdk-ffi/src/room_preview.rs @@ -1,10 +1,12 @@ use anyhow::Context as _; use matrix_sdk::{room_preview::RoomPreview as SdkRoomPreview, Client}; -use ruma::space::SpaceRoomJoinRule; +use ruma::{room::RoomType as RumaRoomType, space::SpaceRoomJoinRule}; use tracing::warn; -use crate::room_member::RoomMember; -use crate::{client::JoinRule, error::ClientError, room::Membership, utils::AsyncRuntimeDropped}; +use crate::{ + client::JoinRule, error::ClientError, room::Membership, room_member::RoomMember, + utils::AsyncRuntimeDropped, +}; /// A room preview for a room. It's intended to be used to represent rooms that /// aren't joined yet. @@ -26,8 +28,8 @@ impl RoomPreview { topic: info.topic.clone(), avatar_url: info.avatar_url.as_ref().map(|url| url.to_string()), num_joined_members: info.num_joined_members, - room_type: info.room_type.as_ref().map(|room_type| room_type.to_string()), num_active_members: info.num_active_members, + room_type: info.room_type.as_ref().into(), is_history_world_readable: info.is_world_readable, membership: info.state.map(|state| state.into()), join_rule: info @@ -81,7 +83,7 @@ pub struct RoomPreviewInfo { /// The number of active members, if known (joined + invited). pub num_active_members: Option, /// The room type (space, custom) or nothing, if it's a regular room. - pub room_type: Option, + pub room_type: RoomType, /// Is the history world-readable for this room? pub is_history_world_readable: bool, /// The membership state for the current user, if known. @@ -111,3 +113,23 @@ impl TryFrom for JoinRule { }) } } + +#[derive(Debug, Clone, uniffi::Enum)] +pub enum RoomType { + Room, + Space, + Custom { value: String }, +} + +impl From> for RoomType { + fn from(value: Option<&RumaRoomType>) -> Self { + match value { + Some(RumaRoomType::Space) => RoomType::Space, + Some(RumaRoomType::_Custom(_)) => RoomType::Custom { + // SAFETY: this was checked in the match branch above + value: value.unwrap().to_string(), + }, + _ => RoomType::Room, + } + } +}