Skip to content

Commit cefd5a2

Browse files
committed
feat(ffi): make RoomPreviewInfo::room_type an enum, not an optional String
1 parent 9795290 commit cefd5a2

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

bindings/matrix-sdk-ffi/src/room_preview.rs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use anyhow::Context as _;
22
use matrix_sdk::{room_preview::RoomPreview as SdkRoomPreview, Client};
3-
use ruma::space::SpaceRoomJoinRule;
3+
use ruma::{room::RoomType as RumaRoomType, space::SpaceRoomJoinRule};
44
use tracing::warn;
55

6-
use crate::room_member::RoomMember;
7-
use crate::{client::JoinRule, error::ClientError, room::Membership, utils::AsyncRuntimeDropped};
6+
use crate::{
7+
client::JoinRule, error::ClientError, room::Membership, room_member::RoomMember,
8+
utils::AsyncRuntimeDropped,
9+
};
810

911
/// A room preview for a room. It's intended to be used to represent rooms that
1012
/// aren't joined yet.
@@ -26,8 +28,8 @@ impl RoomPreview {
2628
topic: info.topic.clone(),
2729
avatar_url: info.avatar_url.as_ref().map(|url| url.to_string()),
2830
num_joined_members: info.num_joined_members,
29-
room_type: info.room_type.as_ref().map(|room_type| room_type.to_string()),
3031
num_active_members: info.num_active_members,
32+
room_type: info.room_type.as_ref().into(),
3133
is_history_world_readable: info.is_world_readable,
3234
membership: info.state.map(|state| state.into()),
3335
join_rule: info
@@ -81,7 +83,7 @@ pub struct RoomPreviewInfo {
8183
/// The number of active members, if known (joined + invited).
8284
pub num_active_members: Option<u64>,
8385
/// The room type (space, custom) or nothing, if it's a regular room.
84-
pub room_type: Option<String>,
86+
pub room_type: RoomType,
8587
/// Is the history world-readable for this room?
8688
pub is_history_world_readable: bool,
8789
/// The membership state for the current user, if known.
@@ -111,3 +113,27 @@ impl TryFrom<SpaceRoomJoinRule> for JoinRule {
111113
})
112114
}
113115
}
116+
117+
/// The type of room for a [`RoomPreviewInfo`].
118+
#[derive(Debug, Clone, uniffi::Enum)]
119+
pub enum RoomType {
120+
/// It's a plain chat room.
121+
Room,
122+
/// It's a space that can group several rooms.
123+
Space,
124+
/// It's a custom implementation.
125+
Custom { value: String },
126+
}
127+
128+
impl From<Option<&RumaRoomType>> for RoomType {
129+
fn from(value: Option<&RumaRoomType>) -> Self {
130+
match value {
131+
Some(RumaRoomType::Space) => RoomType::Space,
132+
Some(RumaRoomType::_Custom(_)) => RoomType::Custom {
133+
// SAFETY: this was checked in the match branch above
134+
value: value.unwrap().to_string(),
135+
},
136+
_ => RoomType::Room,
137+
}
138+
}
139+
}

0 commit comments

Comments
 (0)