@@ -380,13 +380,16 @@ def assert_bundle(event_json: JsonDict) -> None:
380
380
{"event_id" : edit_event_id , "sender" : self .user_id }, m_replace_dict
381
381
)
382
382
383
+ # /event should return the *original* event
383
384
channel = self .make_request (
384
385
"GET" ,
385
386
f"/rooms/{ self .room } /event/{ self .parent_id } " ,
386
387
access_token = self .user_token ,
387
388
)
388
389
self .assertEqual (200 , channel .code , channel .json_body )
389
- self .assertEqual (channel .json_body ["content" ], new_body )
390
+ self .assertEqual (
391
+ channel .json_body ["content" ], {"body" : "Hi!" , "msgtype" : "m.text" }
392
+ )
390
393
assert_bundle (channel .json_body )
391
394
392
395
# Request the room messages.
@@ -399,13 +402,15 @@ def assert_bundle(event_json: JsonDict) -> None:
399
402
assert_bundle (self ._find_event_in_chunk (channel .json_body ["chunk" ]))
400
403
401
404
# Request the room context.
405
+ # /context should return the edited event.
402
406
channel = self .make_request (
403
407
"GET" ,
404
408
f"/rooms/{ self .room } /context/{ self .parent_id } " ,
405
409
access_token = self .user_token ,
406
410
)
407
411
self .assertEqual (200 , channel .code , channel .json_body )
408
412
assert_bundle (channel .json_body ["event" ])
413
+ self .assertEqual (channel .json_body ["event" ]["content" ], new_body )
409
414
410
415
# Request sync, but limit the timeline so it becomes limited (and includes
411
416
# bundled aggregations).
@@ -470,14 +475,14 @@ def test_multi_edit(self) -> None:
470
475
471
476
channel = self .make_request (
472
477
"GET" ,
473
- f"/rooms/{ self .room } /event /{ self .parent_id } " ,
478
+ f"/rooms/{ self .room } /context /{ self .parent_id } " ,
474
479
access_token = self .user_token ,
475
480
)
476
481
self .assertEqual (200 , channel .code , channel .json_body )
477
482
478
- self .assertEqual (channel .json_body ["content" ], new_body )
483
+ self .assertEqual (channel .json_body ["event" ][ " content" ], new_body )
479
484
480
- relations_dict = channel .json_body ["unsigned" ].get ("m.relations" )
485
+ relations_dict = channel .json_body ["event" ][ " unsigned" ].get ("m.relations" )
481
486
self .assertIn (RelationTypes .REPLACE , relations_dict )
482
487
483
488
m_replace_dict = relations_dict [RelationTypes .REPLACE ]
@@ -492,10 +497,9 @@ def test_edit_reply(self) -> None:
492
497
"""Test that editing a reply works."""
493
498
494
499
# Create a reply to edit.
500
+ original_body = {"msgtype" : "m.text" , "body" : "A reply!" }
495
501
channel = self ._send_relation (
496
- RelationTypes .REFERENCE ,
497
- "m.room.message" ,
498
- content = {"msgtype" : "m.text" , "body" : "A reply!" },
502
+ RelationTypes .REFERENCE , "m.room.message" , content = original_body
499
503
)
500
504
reply = channel .json_body ["event_id" ]
501
505
@@ -508,38 +512,54 @@ def test_edit_reply(self) -> None:
508
512
)
509
513
edit_event_id = channel .json_body ["event_id" ]
510
514
515
+ # /event returns the original event
511
516
channel = self .make_request (
512
517
"GET" ,
513
518
f"/rooms/{ self .room } /event/{ reply } " ,
514
519
access_token = self .user_token ,
515
520
)
516
521
self .assertEqual (200 , channel .code , channel .json_body )
522
+ event_result = channel .json_body
523
+ self .assertDictContainsSubset (original_body , event_result ["content" ])
517
524
518
- # We expect to see the new body in the dict, as well as the reference
519
- # metadata sill intact.
520
- self .assertDictContainsSubset (new_body , channel .json_body ["content" ])
521
- self .assertDictContainsSubset (
522
- {
523
- "m.relates_to" : {
524
- "event_id" : self .parent_id ,
525
- "rel_type" : "m.reference" ,
526
- }
527
- },
528
- channel .json_body ["content" ],
525
+ # also check /context, which returns the *edited* event
526
+ channel = self .make_request (
527
+ "GET" ,
528
+ f"/rooms/{ self .room } /context/{ reply } " ,
529
+ access_token = self .user_token ,
529
530
)
531
+ self .assertEqual (200 , channel .code , channel .json_body )
532
+ context_result = channel .json_body ["event" ]
530
533
531
- # We expect that the edit relation appears in the unsigned relations
532
- # section.
533
- relations_dict = channel .json_body ["unsigned" ].get ("m.relations" )
534
- self .assertIn (RelationTypes .REPLACE , relations_dict )
534
+ # check that the relations are correct for both APIs
535
+ for result_event_dict , desc in (
536
+ (event_result , "/event" ),
537
+ (context_result , "/context" ),
538
+ ):
539
+ # The reference metadata should still be intact.
540
+ self .assertDictContainsSubset (
541
+ {
542
+ "m.relates_to" : {
543
+ "event_id" : self .parent_id ,
544
+ "rel_type" : "m.reference" ,
545
+ }
546
+ },
547
+ result_event_dict ["content" ],
548
+ desc ,
549
+ )
535
550
536
- m_replace_dict = relations_dict [RelationTypes .REPLACE ]
537
- for key in ["event_id" , "sender" , "origin_server_ts" ]:
538
- self .assertIn (key , m_replace_dict )
551
+ # We expect that the edit relation appears in the unsigned relations
552
+ # section.
553
+ relations_dict = result_event_dict ["unsigned" ].get ("m.relations" )
554
+ self .assertIn (RelationTypes .REPLACE , relations_dict , desc )
539
555
540
- self .assert_dict (
541
- {"event_id" : edit_event_id , "sender" : self .user_id }, m_replace_dict
542
- )
556
+ m_replace_dict = relations_dict [RelationTypes .REPLACE ]
557
+ for key in ["event_id" , "sender" , "origin_server_ts" ]:
558
+ self .assertIn (key , m_replace_dict , desc )
559
+
560
+ self .assert_dict (
561
+ {"event_id" : edit_event_id , "sender" : self .user_id }, m_replace_dict
562
+ )
543
563
544
564
def test_edit_thread (self ) -> None :
545
565
"""Test that editing a thread works."""
@@ -605,19 +625,31 @@ def test_edit_edit(self) -> None:
605
625
)
606
626
607
627
# Request the original event.
628
+ # /event should return the original event.
608
629
channel = self .make_request (
609
630
"GET" ,
610
631
f"/rooms/{ self .room } /event/{ self .parent_id } " ,
611
632
access_token = self .user_token ,
612
633
)
613
634
self .assertEqual (200 , channel .code , channel .json_body )
614
- # The edit to the edit should be ignored.
615
- self .assertEqual (channel .json_body ["content" ], new_body )
635
+ self .assertEqual (
636
+ channel .json_body ["content" ], {"body" : "Hi!" , "msgtype" : "m.text" }
637
+ )
616
638
617
639
# The relations information should not include the edit to the edit.
618
640
relations_dict = channel .json_body ["unsigned" ].get ("m.relations" )
619
641
self .assertIn (RelationTypes .REPLACE , relations_dict )
620
642
643
+ # /context should return the event updated for the *first* edit
644
+ # (The edit to the edit should be ignored.)
645
+ channel = self .make_request (
646
+ "GET" ,
647
+ f"/rooms/{ self .room } /context/{ self .parent_id } " ,
648
+ access_token = self .user_token ,
649
+ )
650
+ self .assertEqual (200 , channel .code , channel .json_body )
651
+ self .assertEqual (channel .json_body ["event" ]["content" ], new_body )
652
+
621
653
m_replace_dict = relations_dict [RelationTypes .REPLACE ]
622
654
for key in ["event_id" , "sender" , "origin_server_ts" ]:
623
655
self .assertIn (key , m_replace_dict )
0 commit comments