@@ -29,8 +29,6 @@ use ruma::{
29
29
} ;
30
30
use tracing:: { error, instrument, trace, warn} ;
31
31
32
- use super :: chunk_debug_string;
33
-
34
32
/// This type represents all events of a single room.
35
33
#[ derive( Debug ) ]
36
34
pub struct RoomEvents {
@@ -320,11 +318,14 @@ impl RoomEvents {
320
318
/// events for this room.
321
319
pub fn debug_string ( & self ) -> Vec < String > {
322
320
let mut result = Vec :: new ( ) ;
323
- for c in self . chunks ( ) {
324
- let content = chunk_debug_string ( c. content ( ) ) ;
325
- let line = format ! ( "chunk #{}: {content}" , c. identifier( ) . index( ) ) ;
321
+
322
+ for chunk in self . chunks ( ) {
323
+ let content = chunk_debug_string ( chunk. content ( ) ) ;
324
+ let line = format ! ( "chunk #{}: {content}" , chunk. identifier( ) . index( ) ) ;
325
+
326
326
result. push ( line) ;
327
327
}
328
+
328
329
result
329
330
}
330
331
}
@@ -339,12 +340,36 @@ impl RoomEvents {
339
340
}
340
341
}
341
342
343
+ /// Create a debug string for a [`ChunkContent`] for an event/gap pair.
344
+ fn chunk_debug_string ( content : & ChunkContent < Event , Gap > ) -> String {
345
+ match content {
346
+ ChunkContent :: Gap ( Gap { prev_token } ) => {
347
+ format ! ( "gap['{prev_token}']" )
348
+ }
349
+ ChunkContent :: Items ( vec) => {
350
+ let items = vec
351
+ . iter ( )
352
+ . map ( |event| {
353
+ // Limit event ids to 8 chars *after* the $.
354
+ event. event_id ( ) . map_or_else (
355
+ || "<no event id>" . to_owned ( ) ,
356
+ |id| id. as_str ( ) . chars ( ) . take ( 1 + 8 ) . collect ( ) ,
357
+ )
358
+ } )
359
+ . collect :: < Vec < _ > > ( )
360
+ . join ( ", " ) ;
361
+
362
+ format ! ( "events[{items}]" )
363
+ }
364
+ }
365
+ }
366
+
342
367
#[ cfg( test) ]
343
368
mod tests {
344
369
use assert_matches:: assert_matches;
345
370
use assert_matches2:: assert_let;
346
- use matrix_sdk_test:: event_factory:: EventFactory ;
347
- use ruma:: { user_id, EventId , OwnedEventId } ;
371
+ use matrix_sdk_test:: { event_factory:: EventFactory , ALICE , DEFAULT_TEST_ROOM_ID } ;
372
+ use ruma:: { event_id , user_id, EventId , OwnedEventId } ;
348
373
349
374
use super :: * ;
350
375
@@ -704,4 +729,25 @@ mod tests {
704
729
}
705
730
) ;
706
731
}
732
+
733
+ #[ test]
734
+ fn test_debug_string ( ) {
735
+ let event_factory = EventFactory :: new ( ) . room ( & DEFAULT_TEST_ROOM_ID ) . sender ( * ALICE ) ;
736
+
737
+ let mut room_events = RoomEvents :: new ( ) ;
738
+ room_events. push_events ( vec ! [
739
+ event_factory
740
+ . text_msg( "hey" )
741
+ . event_id( event_id!( "$123456789101112131415617181920" ) )
742
+ . into_event( ) ,
743
+ event_factory. text_msg( "you" ) . event_id( event_id!( "$2" ) ) . into_event( ) ,
744
+ ] ) ;
745
+ room_events. push_gap ( Gap { prev_token : "raclette" . to_owned ( ) } ) ;
746
+
747
+ let output = room_events. debug_string ( ) ;
748
+
749
+ assert_eq ! ( output. len( ) , 2 ) ;
750
+ assert_eq ! ( & output[ 0 ] , "chunk #0: events[$12345678, $2]" ) ;
751
+ assert_eq ! ( & output[ 1 ] , "chunk #1: gap['raclette']" ) ;
752
+ }
707
753
}
0 commit comments