1
1
use anyhow:: Context as _;
2
2
use matrix_sdk:: { room_preview:: RoomPreview as SdkRoomPreview , Client } ;
3
3
use ruma:: room:: { JoinRuleSummary , RoomType as RumaRoomType } ;
4
- use tracing:: warn;
5
4
6
5
use crate :: {
7
6
client:: { AllowRule , JoinRule } ,
@@ -22,9 +21,9 @@ pub struct RoomPreview {
22
21
#[ matrix_sdk_ffi_macros:: export]
23
22
impl RoomPreview {
24
23
/// Returns the room info the preview contains.
25
- pub fn info ( & self ) -> Result < RoomPreviewInfo , ClientError > {
24
+ pub fn info ( & self ) -> RoomPreviewInfo {
26
25
let info = & self . inner ;
27
- Ok ( RoomPreviewInfo {
26
+ RoomPreviewInfo {
28
27
room_id : info. room_id . to_string ( ) ,
29
28
canonical_alias : info. canonical_alias . as_ref ( ) . map ( |alias| alias. to_string ( ) ) ,
30
29
name : info. name . clone ( ) ,
@@ -35,18 +34,13 @@ impl RoomPreview {
35
34
room_type : info. room_type . as_ref ( ) . into ( ) ,
36
35
is_history_world_readable : info. is_world_readable ,
37
36
membership : info. state . map ( |state| state. into ( ) ) ,
38
- join_rule : info
39
- . join_rule
40
- . as_ref ( )
41
- . map ( TryInto :: try_into)
42
- . transpose ( )
43
- . map_err ( |_| anyhow:: anyhow!( "unhandled JoinRuleSummary kind" ) ) ?,
37
+ join_rule : info. join_rule . as_ref ( ) . map ( Into :: into) ,
44
38
is_direct : info. is_direct ,
45
39
heroes : info
46
40
. heroes
47
41
. as_ref ( )
48
42
. map ( |heroes| heroes. iter ( ) . map ( |h| h. to_owned ( ) . into ( ) ) . collect ( ) ) ,
49
- } )
43
+ }
50
44
}
51
45
52
46
/// Leave the room if the room preview state is either joined, invited or
@@ -122,11 +116,9 @@ pub struct RoomPreviewInfo {
122
116
pub heroes : Option < Vec < RoomHero > > ,
123
117
}
124
118
125
- impl TryFrom < & JoinRuleSummary > for JoinRule {
126
- type Error = ( ) ;
127
-
128
- fn try_from ( join_rule : & JoinRuleSummary ) -> Result < Self , ( ) > {
129
- Ok ( match join_rule {
119
+ impl From < & JoinRuleSummary > for JoinRule {
120
+ fn from ( join_rule : & JoinRuleSummary ) -> Self {
121
+ match join_rule {
130
122
JoinRuleSummary :: Invite => JoinRule :: Invite ,
131
123
JoinRuleSummary :: Knock => JoinRule :: Knock ,
132
124
JoinRuleSummary :: Private => JoinRule :: Private ,
@@ -145,12 +137,8 @@ impl TryFrom<&JoinRuleSummary> for JoinRule {
145
137
. collect ( ) ,
146
138
} ,
147
139
JoinRuleSummary :: Public => JoinRule :: Public ,
148
- JoinRuleSummary :: _Custom( _) => JoinRule :: Custom { repr : join_rule. as_str ( ) . to_owned ( ) } ,
149
- _ => {
150
- warn ! ( "unhandled JoinRuleSummary: {}" , join_rule. as_str( ) ) ;
151
- return Err ( ( ) ) ;
152
- }
153
- } )
140
+ _ => JoinRule :: Custom { repr : join_rule. as_str ( ) . to_owned ( ) } ,
141
+ }
154
142
}
155
143
}
156
144
0 commit comments