@@ -412,8 +412,67 @@ async fn remote_echo_without_txn_id() {
412412 } ) )
413413 . await ;
414414
415- let item =
416- assert_matches ! ( stream. next( ) . await , Some ( VecDiff :: UpdateAt { value, index: 1 } ) => value) ;
415+ // The local echo is removed
416+ assert_matches ! ( stream. next( ) . await , Some ( VecDiff :: Pop { .. } ) ) ;
417+ // This day divider shouldn't be present, or the previous one should be
418+ // removed. There being a two day dividers in a row is a bug, but it's
419+ // non-trivial to fix and rare enough that we can fix it later (only happens
420+ // when the first message on a given day is a local echo).
421+ let _day_divider = assert_matches ! ( stream. next( ) . await , Some ( VecDiff :: Push { value } ) => value) ;
422+
423+ // … and the remote echo is added.
424+ let item = assert_matches ! ( stream. next( ) . await , Some ( VecDiff :: Push { value } ) => value) ;
425+ assert_matches ! ( item. as_event( ) . unwrap( ) . key( ) , TimelineKey :: EventId ( _) ) ;
426+ }
427+
428+ #[ async_test]
429+ async fn remote_echo_new_position ( ) {
430+ let timeline = TestTimeline :: new ( ) ;
431+ let mut stream = timeline. stream ( ) ;
432+
433+ // Given a local event…
434+ let txn_id = timeline
435+ . handle_local_event ( AnyMessageLikeEventContent :: RoomMessage (
436+ RoomMessageEventContent :: text_plain ( "echo" ) ,
437+ ) )
438+ . await ;
439+
440+ let _day_divider = assert_matches ! ( stream. next( ) . await , Some ( VecDiff :: Push { value } ) => value) ;
441+
442+ let item = assert_matches ! ( stream. next( ) . await , Some ( VecDiff :: Push { value } ) => value) ;
443+ let txn_id_from_event = assert_matches ! (
444+ item. as_event( ) . unwrap( ) . key( ) ,
445+ TimelineKey :: TransactionId ( txn_id) => txn_id
446+ ) ;
447+ assert_eq ! ( txn_id, * txn_id_from_event) ;
448+
449+ // … and another event that comes back before the remote echo
450+ timeline. handle_live_message_event ( & BOB , RoomMessageEventContent :: text_plain ( "test" ) ) . await ;
451+ let _day_divider = assert_matches ! ( stream. next( ) . await , Some ( VecDiff :: Push { value } ) => value) ;
452+ let _bob_message = assert_matches ! ( stream. next( ) . await , Some ( VecDiff :: Push { value } ) => value) ;
453+
454+ // When the remote echo comes in…
455+ timeline
456+ . handle_live_custom_event ( json ! ( {
457+ "content" : {
458+ "body" : "echo" ,
459+ "msgtype" : "m.text" ,
460+ } ,
461+ "sender" : & * ALICE ,
462+ "event_id" : "$eeG0HA0FAZ37wP8kXlNkxx3I" ,
463+ "origin_server_ts" : 6 ,
464+ "type" : "m.room.message" ,
465+ "unsigned" : {
466+ "transaction_id" : txn_id,
467+ } ,
468+ } ) )
469+ . await ;
470+
471+ // … the local echo should be removed
472+ assert_matches ! ( stream. next( ) . await , Some ( VecDiff :: RemoveAt { index: 1 } ) ) ;
473+
474+ // … and the remote echo added
475+ let item = assert_matches ! ( stream. next( ) . await , Some ( VecDiff :: Push { value } ) => value) ;
417476 assert_matches ! ( item. as_event( ) . unwrap( ) . key( ) , TimelineKey :: EventId ( _) ) ;
418477}
419478
0 commit comments