@@ -406,39 +406,47 @@ impl EventCacheInner {
406
406
} ;
407
407
408
408
// Handle and cache events and relations
409
- let mut relations = self . relations . write ( ) . await ;
410
409
for ev in & joined_room_update. timeline . events {
411
410
if let Ok ( AnySyncTimelineEvent :: MessageLike ( ev) ) = ev. event . deserialize ( ) {
412
411
if let Some ( AnyMessageLikeEventContent :: RoomMessage ( c) ) = ev. original_content ( )
413
412
{
414
- if let Some ( Relation :: Replacement ( relation) ) = c. relates_to {
415
- if let Some ( replacements) = relations. get_mut ( & relation. event_id ) {
416
- replacements. insert ( ev. event_id ( ) . to_owned ( ) ) ;
417
- } else {
418
- relations. insert (
419
- relation. event_id ,
420
- BTreeSet :: from_iter ( vec ! [ ev. event_id( ) . to_owned( ) ] ) ,
421
- ) ;
413
+ if let Some ( relation) = c. relates_to {
414
+ match relation {
415
+ Relation :: Replacement ( replacement) => {
416
+ self . insert_or_update_relationship (
417
+ & replacement. event_id ,
418
+ ev. event_id ( ) ,
419
+ )
420
+ . await ;
421
+ }
422
+ Relation :: Reply { in_reply_to } => {
423
+ self . insert_or_update_relationship (
424
+ & in_reply_to. event_id ,
425
+ ev. event_id ( ) ,
426
+ )
427
+ . await ;
428
+ }
429
+ Relation :: Thread ( thread) => {
430
+ self . insert_or_update_relationship (
431
+ & thread. event_id ,
432
+ ev. event_id ( ) ,
433
+ )
434
+ . await ;
435
+ }
436
+ // Do nothing for custom
437
+ _ => ( ) ,
422
438
}
423
439
}
424
440
} else if let Some ( AnyMessageLikeEventContent :: RoomRedaction ( c) ) =
425
441
ev. original_content ( )
426
442
{
427
443
if let Some ( redacted_ev_id) = c. redacts {
428
- let original_ev_id = redacted_ev_id;
429
- if let Some ( replacements) = relations. get_mut ( & original_ev_id) {
430
- replacements. insert ( ev. event_id ( ) . to_owned ( ) ) ;
431
- } else {
432
- relations. insert (
433
- original_ev_id,
434
- BTreeSet :: from_iter ( vec ! [ ev. event_id( ) . to_owned( ) ] ) ,
435
- ) ;
436
- }
444
+ self . insert_or_update_relationship ( & redacted_ev_id, ev. event_id ( ) )
445
+ . await ;
437
446
}
438
447
}
439
448
}
440
449
}
441
- drop ( relations) ;
442
450
443
451
let mut events = self . events . write ( ) . await ;
444
452
for ev in & joined_room_update. timeline . events {
@@ -496,6 +504,18 @@ impl EventCacheInner {
496
504
}
497
505
}
498
506
}
507
+
508
+ async fn insert_or_update_relationship ( & self , orig_ev_id : & EventId , related_ev_id : & EventId ) {
509
+ let mut relations = self . relations . write ( ) . await ;
510
+
511
+ if let Some ( replacements) = relations. get_mut ( orig_ev_id) {
512
+ replacements. insert ( related_ev_id. to_owned ( ) ) ;
513
+ } else {
514
+ relations
515
+ . insert ( orig_ev_id. to_owned ( ) , BTreeSet :: from_iter ( vec ! [ related_ev_id. to_owned( ) ] ) ) ;
516
+ }
517
+ drop ( relations) ;
518
+ }
499
519
}
500
520
501
521
/// A subset of an event cache, for a room.
0 commit comments