@@ -217,9 +217,9 @@ def test_redact_event_as_moderator_ratelimit(self) -> None:
217
217
self ._redact_event (self .mod_access_token , self .room_id , msg_id )
218
218
219
219
@override_config ({"experimental_features" : {"msc3912_enabled" : True }})
220
- def test_redact_relations (self ) -> None :
221
- """Tests that we can redact the relations of an event at the same time as the
222
- event itself.
220
+ def test_redact_relations_with_types (self ) -> None :
221
+ """Tests that we can redact the relations of an event of specific types
222
+ at the same time as the event itself.
223
223
"""
224
224
# Send a root event.
225
225
res = self .helper .send_event (
@@ -317,6 +317,104 @@ def test_redact_relations(self) -> None:
317
317
)
318
318
self .assertNotIn ("redacted_because" , event_dict , event_dict )
319
319
320
+ @override_config ({"experimental_features" : {"msc3912_enabled" : True }})
321
+ def test_redact_all_relations (self ) -> None :
322
+ """Tests that we can redact all the relations of an event at the same time as the
323
+ event itself.
324
+ """
325
+ # Send a root event.
326
+ res = self .helper .send_event (
327
+ room_id = self .room_id ,
328
+ type = EventTypes .Message ,
329
+ content = {"msgtype" : "m.text" , "body" : "hello" },
330
+ tok = self .mod_access_token ,
331
+ )
332
+ root_event_id = res ["event_id" ]
333
+
334
+ # Send an edit to this root event.
335
+ res = self .helper .send_event (
336
+ room_id = self .room_id ,
337
+ type = EventTypes .Message ,
338
+ content = {
339
+ "body" : " * hello world" ,
340
+ "m.new_content" : {
341
+ "body" : "hello world" ,
342
+ "msgtype" : "m.text" ,
343
+ },
344
+ "m.relates_to" : {
345
+ "event_id" : root_event_id ,
346
+ "rel_type" : RelationTypes .REPLACE ,
347
+ },
348
+ "msgtype" : "m.text" ,
349
+ },
350
+ tok = self .mod_access_token ,
351
+ )
352
+ edit_event_id = res ["event_id" ]
353
+
354
+ # Also send a threaded message whose root is the same as the edit's.
355
+ res = self .helper .send_event (
356
+ room_id = self .room_id ,
357
+ type = EventTypes .Message ,
358
+ content = {
359
+ "msgtype" : "m.text" ,
360
+ "body" : "message 1" ,
361
+ "m.relates_to" : {
362
+ "event_id" : root_event_id ,
363
+ "rel_type" : RelationTypes .THREAD ,
364
+ },
365
+ },
366
+ tok = self .mod_access_token ,
367
+ )
368
+ threaded_event_id = res ["event_id" ]
369
+
370
+ # Also send a reaction, again with the same root.
371
+ res = self .helper .send_event (
372
+ room_id = self .room_id ,
373
+ type = EventTypes .Reaction ,
374
+ content = {
375
+ "m.relates_to" : {
376
+ "rel_type" : RelationTypes .ANNOTATION ,
377
+ "event_id" : root_event_id ,
378
+ "key" : "👍" ,
379
+ }
380
+ },
381
+ tok = self .mod_access_token ,
382
+ )
383
+ reaction_event_id = res ["event_id" ]
384
+
385
+ # Redact the root event, specifying that we also want to delete all events that
386
+ # relate to it.
387
+ self ._redact_event (
388
+ self .mod_access_token ,
389
+ self .room_id ,
390
+ root_event_id ,
391
+ with_relations = ["*" ],
392
+ )
393
+
394
+ # Check that the root event got redacted.
395
+ event_dict = self .helper .get_event (
396
+ self .room_id , root_event_id , self .mod_access_token
397
+ )
398
+ self .assertIn ("redacted_because" , event_dict , event_dict )
399
+
400
+ # Check that the edit got redacted.
401
+ event_dict = self .helper .get_event (
402
+ self .room_id , edit_event_id , self .mod_access_token
403
+ )
404
+ self .assertIn ("redacted_because" , event_dict , event_dict )
405
+
406
+ # Check that the threaded message got redacted.
407
+ event_dict = self .helper .get_event (
408
+ self .room_id , threaded_event_id , self .mod_access_token
409
+ )
410
+ self .assertIn ("redacted_because" , event_dict , event_dict )
411
+
412
+ # Check that the reaction got redacted.
413
+ event_dict = self .helper .get_event (
414
+ self .room_id , reaction_event_id , self .mod_access_token
415
+ )
416
+ self .assertIn ("redacted_because" , event_dict , event_dict )
417
+
320
418
@override_config ({"experimental_features" : {"msc3912_enabled" : True }})
321
419
def test_redact_relations_no_perms (self ) -> None :
322
420
"""Tests that, when redacting a message along with its relations, if not all
0 commit comments