@@ -26,10 +26,22 @@ pub struct Mention {
26
26
27
27
#[ derive( Clone , Debug , PartialEq , Eq ) ]
28
28
pub enum MentionKind {
29
- Room ,
29
+ Room ( RoomIdentificationType ) ,
30
30
User ,
31
31
}
32
32
33
+ impl MentionKind {
34
+ pub fn is_room ( & self ) -> bool {
35
+ matches ! ( self , MentionKind :: Room ( _) )
36
+ }
37
+ }
38
+
39
+ #[ derive( Clone , Debug , PartialEq , Eq ) ]
40
+ pub enum RoomIdentificationType {
41
+ Id ,
42
+ Alias ,
43
+ }
44
+
33
45
impl Mention {
34
46
fn new (
35
47
uri : String ,
@@ -134,17 +146,24 @@ impl Mention {
134
146
fn from_room ( room_uri : & str ) -> Option < Mention > {
135
147
// In all cases, use the alias/room ID being linked to as the
136
148
// anchor’s text.
149
+ let room_id_type: RoomIdentificationType ;
137
150
let text = match parse_matrix_id ( room_uri) ? {
138
- MatrixId :: Room ( room_id) => room_id. to_string ( ) ,
139
- MatrixId :: RoomAlias ( room_alias) => room_alias. to_string ( ) ,
151
+ MatrixId :: Room ( room_id) => {
152
+ room_id_type = RoomIdentificationType :: Id ;
153
+ room_id. to_string ( )
154
+ }
155
+ MatrixId :: RoomAlias ( room_alias) => {
156
+ room_id_type = RoomIdentificationType :: Alias ;
157
+ room_alias. to_string ( )
158
+ }
140
159
_ => return None ,
141
160
} ;
142
161
143
162
Some ( Mention :: new (
144
163
room_uri. to_string ( ) ,
145
164
text. clone ( ) ,
146
165
text,
147
- MentionKind :: Room ,
166
+ MentionKind :: Room ( room_id_type ) ,
148
167
) )
149
168
}
150
169
}
@@ -200,7 +219,7 @@ fn parse_external_id(uri: &str) -> Result<MatrixToUri, IdParseError> {
200
219
mod test {
201
220
use ruma_common:: { MatrixToUri , MatrixUri } ;
202
221
203
- use crate :: mention:: { Mention , MentionKind } ;
222
+ use crate :: mention:: { Mention , MentionKind , RoomIdentificationType } ;
204
223
205
224
#[ test]
206
225
fn parse_uri_matrix_to_valid_user ( ) {
@@ -232,7 +251,10 @@ mod test {
232
251
assert_eq ! ( parsed. uri( ) , uri) ;
233
252
assert_eq ! ( parsed. mx_id( ) , "!roomid:example.org" ) ;
234
253
assert_eq ! ( parsed. display_text( ) , "!roomid:example.org" ) ;
235
- assert_eq ! ( parsed. kind( ) , & MentionKind :: Room ) ;
254
+ assert_eq ! (
255
+ parsed. kind( ) ,
256
+ & MentionKind :: Room ( RoomIdentificationType :: Id )
257
+ ) ;
236
258
}
237
259
238
260
#[ test]
@@ -243,7 +265,10 @@ mod test {
243
265
assert_eq ! ( parsed. uri( ) , uri) ;
244
266
assert_eq ! ( parsed. mx_id( ) , "!roomid:example.org" ) ;
245
267
assert_eq ! ( parsed. display_text( ) , "!roomid:example.org" ) ;
246
- assert_eq ! ( parsed. kind( ) , & MentionKind :: Room ) ;
268
+ assert_eq ! (
269
+ parsed. kind( ) ,
270
+ & MentionKind :: Room ( RoomIdentificationType :: Id )
271
+ ) ;
247
272
}
248
273
249
274
#[ test]
@@ -254,7 +279,10 @@ mod test {
254
279
assert_eq ! ( parsed. uri( ) , uri) ;
255
280
assert_eq ! ( parsed. mx_id( ) , "#room:example.org" ) ;
256
281
assert_eq ! ( parsed. display_text( ) , "#room:example.org" ) ;
257
- assert_eq ! ( parsed. kind( ) , & MentionKind :: Room ) ;
282
+ assert_eq ! (
283
+ parsed. kind( ) ,
284
+ & MentionKind :: Room ( RoomIdentificationType :: Alias )
285
+ ) ;
258
286
}
259
287
260
288
#[ test]
@@ -265,7 +293,10 @@ mod test {
265
293
assert_eq ! ( parsed. uri( ) , uri) ;
266
294
assert_eq ! ( parsed. mx_id( ) , "#room:example.org" ) ;
267
295
assert_eq ! ( parsed. display_text( ) , "#room:example.org" ) ;
268
- assert_eq ! ( parsed. kind( ) , & MentionKind :: Room ) ;
296
+ assert_eq ! (
297
+ parsed. kind( ) ,
298
+ & MentionKind :: Room ( RoomIdentificationType :: Alias )
299
+ ) ;
269
300
}
270
301
271
302
#[ test]
@@ -319,7 +350,10 @@ mod test {
319
350
assert_eq ! ( parsed. uri( ) , uri) ;
320
351
assert_eq ! ( parsed. mx_id( ) , "!roomid:example.org" ) ;
321
352
assert_eq ! ( parsed. display_text( ) , "!roomid:example.org" ) ;
322
- assert_eq ! ( parsed. kind( ) , & MentionKind :: Room ) ;
353
+ assert_eq ! (
354
+ parsed. kind( ) ,
355
+ & MentionKind :: Room ( RoomIdentificationType :: Id )
356
+ ) ;
323
357
}
324
358
325
359
#[ test]
@@ -347,7 +381,10 @@ mod test {
347
381
assert_eq ! ( parsed. uri( ) , uri) ;
348
382
assert_eq ! ( parsed. mx_id( ) , "!room:example.org" ) ;
349
383
assert_eq ! ( parsed. display_text( ) , "!room:example.org" ) ; // note the display_text is overridden
350
- assert_eq ! ( parsed. kind( ) , & MentionKind :: Room ) ;
384
+ assert_eq ! (
385
+ parsed. kind( ) ,
386
+ & MentionKind :: Room ( RoomIdentificationType :: Id )
387
+ ) ;
351
388
}
352
389
353
390
#[ test]
@@ -361,7 +398,10 @@ mod test {
361
398
assert_eq ! ( parsed. uri( ) , uri) ;
362
399
assert_eq ! ( parsed. mx_id( ) , "#room:example.org" ) ;
363
400
assert_eq ! ( parsed. display_text( ) , "#room:example.org" ) ; // note the display_text is overridden
364
- assert_eq ! ( parsed. kind( ) , & MentionKind :: Room ) ;
401
+ assert_eq ! (
402
+ parsed. kind( ) ,
403
+ & MentionKind :: Room ( RoomIdentificationType :: Alias )
404
+ ) ;
365
405
}
366
406
367
407
#[ test]
0 commit comments