1
1
use anyhow:: Context as _;
2
2
use matrix_sdk:: { room_preview:: RoomPreview as SdkRoomPreview , Client } ;
3
- use ruma:: space:: SpaceRoomJoinRule ;
3
+ use ruma:: { room :: RoomType as RumaRoomType , space:: SpaceRoomJoinRule } ;
4
4
use tracing:: warn;
5
5
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
+ } ;
8
10
9
11
/// A room preview for a room. It's intended to be used to represent rooms that
10
12
/// aren't joined yet.
@@ -26,8 +28,8 @@ impl RoomPreview {
26
28
topic : info. topic . clone ( ) ,
27
29
avatar_url : info. avatar_url . as_ref ( ) . map ( |url| url. to_string ( ) ) ,
28
30
num_joined_members : info. num_joined_members ,
29
- room_type : info. room_type . as_ref ( ) . map ( |room_type| room_type. to_string ( ) ) ,
30
31
num_active_members : info. num_active_members ,
32
+ room_type : info. room_type . as_ref ( ) . into ( ) ,
31
33
is_history_world_readable : info. is_world_readable ,
32
34
membership : info. state . map ( |state| state. into ( ) ) ,
33
35
join_rule : info
@@ -81,7 +83,7 @@ pub struct RoomPreviewInfo {
81
83
/// The number of active members, if known (joined + invited).
82
84
pub num_active_members : Option < u64 > ,
83
85
/// The room type (space, custom) or nothing, if it's a regular room.
84
- pub room_type : Option < String > ,
86
+ pub room_type : RoomType ,
85
87
/// Is the history world-readable for this room?
86
88
pub is_history_world_readable : bool ,
87
89
/// The membership state for the current user, if known.
@@ -111,3 +113,27 @@ impl TryFrom<SpaceRoomJoinRule> for JoinRule {
111
113
} )
112
114
}
113
115
}
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