Skip to content

Commit

Permalink
feat(ffi): make RoomPreviewInfo::room_type an enum, not an optional…
Browse files Browse the repository at this point in the history
… String
  • Loading branch information
jmartinesp committed Nov 14, 2024
1 parent aae6790 commit c3deea5
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions bindings/matrix-sdk-ffi/src/room_preview.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -81,7 +83,7 @@ pub struct RoomPreviewInfo {
/// The number of active members, if known (joined + invited).
pub num_active_members: Option<u64>,
/// The room type (space, custom) or nothing, if it's a regular room.
pub room_type: Option<String>,
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.
Expand Down Expand Up @@ -111,3 +113,23 @@ impl TryFrom<SpaceRoomJoinRule> for JoinRule {
})
}
}

#[derive(Debug, Clone, uniffi::Enum)]
pub enum RoomType {
Room,
Space,
Custom { value: String },
}

impl From<Option<&RumaRoomType>> 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,
}
}
}

0 comments on commit c3deea5

Please sign in to comment.