@@ -20,7 +20,7 @@ use matrix_sdk::deserialized_responses::{
20
20
AlgorithmInfo , EncryptionInfo , VerificationLevel , VerificationState ,
21
21
} ;
22
22
use matrix_sdk_base:: deserialized_responses:: { DecryptedRoomEvent , TimelineEvent } ;
23
- use matrix_sdk_test:: { async_test, ALICE } ;
23
+ use matrix_sdk_test:: { async_test, ALICE , BOB } ;
24
24
use ruma:: {
25
25
event_id,
26
26
events:: {
@@ -369,3 +369,75 @@ async fn test_relations_edit_overrides_pending_edit_poll() {
369
369
370
370
assert_pending ! ( stream) ;
371
371
}
372
+
373
+ #[ async_test]
374
+ async fn test_updated_reply_doesnt_lose_latest_edit ( ) {
375
+ let timeline = TestTimeline :: new ( ) ;
376
+ let mut stream = timeline. subscribe_events ( ) . await ;
377
+
378
+ let f = & timeline. factory ;
379
+
380
+ // Start with a message event.
381
+ let target = event_id ! ( "$1" ) ;
382
+ timeline. handle_live_event ( f. text_msg ( "hey" ) . sender ( & ALICE ) . event_id ( target) ) . await ;
383
+
384
+ {
385
+ let item = assert_next_matches ! ( stream, VectorDiff :: PushBack { value } => value) ;
386
+ assert ! ( item. latest_edit_json( ) . is_none( ) ) ;
387
+ assert_eq ! ( item. content( ) . as_message( ) . unwrap( ) . body( ) , "hey" ) ;
388
+ assert_pending ! ( stream) ;
389
+ }
390
+
391
+ // Have someone send a reply.
392
+ let reply = event_id ! ( "$2" ) ;
393
+ timeline
394
+ . handle_live_event ( f. text_msg ( "hallo" ) . sender ( & BOB ) . reply_to ( target) . event_id ( reply) )
395
+ . await ;
396
+
397
+ {
398
+ let item = assert_next_matches ! ( stream, VectorDiff :: PushBack { value } => value) ;
399
+ assert ! ( item. latest_edit_json( ) . is_none( ) ) ;
400
+ assert_eq ! ( item. content( ) . as_message( ) . unwrap( ) . body( ) , "hallo" ) ;
401
+ assert_pending ! ( stream) ;
402
+ }
403
+
404
+ // Edit the reply.
405
+ timeline
406
+ . handle_live_event (
407
+ f. text_msg ( "* guten tag" )
408
+ . sender ( & BOB )
409
+ . edit ( reply, MessageType :: text_plain ( "guten tag" ) . into ( ) ) ,
410
+ )
411
+ . await ;
412
+
413
+ {
414
+ let item = assert_next_matches ! ( stream, VectorDiff :: Set { index: 1 , value } => value) ;
415
+ assert ! ( item. latest_edit_json( ) . is_some( ) ) ;
416
+ assert_eq ! ( item. content( ) . as_message( ) . unwrap( ) . body( ) , "guten tag" ) ;
417
+ assert_pending ! ( stream) ;
418
+ }
419
+
420
+ // Edit the original.
421
+ timeline
422
+ . handle_live_event (
423
+ f. text_msg ( "* hello" )
424
+ . sender ( & ALICE )
425
+ . edit ( target, MessageType :: text_plain ( "hello" ) . into ( ) ) ,
426
+ )
427
+ . await ;
428
+
429
+ {
430
+ // The reply is updated.
431
+ let item = assert_next_matches ! ( stream, VectorDiff :: Set { index: 1 , value } => value) ;
432
+ // And still has the latest edit JSON.
433
+ assert ! ( item. latest_edit_json( ) . is_some( ) ) ;
434
+ assert_eq ! ( item. content( ) . as_message( ) . unwrap( ) . body( ) , "guten tag" ) ;
435
+
436
+ // The original is updated.
437
+ let item = assert_next_matches ! ( stream, VectorDiff :: Set { index: 0 , value } => value) ;
438
+ // And now has a latest edit JSON.
439
+ assert ! ( item. latest_edit_json( ) . is_some( ) ) ;
440
+
441
+ assert_pending ! ( stream) ;
442
+ }
443
+ }
0 commit comments