@@ -252,13 +252,7 @@ impl EventCache {
252
252
253
253
room_cache
254
254
. inner
255
- . replace_all_events_by (
256
- events,
257
- prev_batch,
258
- Default :: default ( ) ,
259
- Default :: default ( ) ,
260
- Default :: default ( ) ,
261
- )
255
+ . replace_all_events_by ( events, prev_batch, Default :: default ( ) , Default :: default ( ) )
262
256
. await ?;
263
257
264
258
Ok ( ( ) )
@@ -462,22 +456,47 @@ impl RoomEventCacheInner {
462
456
}
463
457
}
464
458
459
+ fn handle_account_data ( & self , account_data : Vec < Raw < AnyRoomAccountDataEvent > > ) {
460
+ trace ! ( "Handling account data" ) ;
461
+ for raw_event in account_data {
462
+ match raw_event. deserialize ( ) {
463
+ Ok ( AnyRoomAccountDataEvent :: FullyRead ( ev) ) => {
464
+ // Propagate to observers. (We ignore the error if there aren't any.)
465
+ let _ = self . sender . send ( RoomEventCacheUpdate :: UpdateReadMarker {
466
+ event_id : ev. content . event_id ,
467
+ } ) ;
468
+ }
469
+
470
+ Ok ( _) => {
471
+ // We're not interested in other room account data updates,
472
+ // at this point.
473
+ }
474
+
475
+ Err ( e) => {
476
+ let event_type = raw_event. get_field :: < String > ( "type" ) . ok ( ) . flatten ( ) ;
477
+ warn ! ( event_type, "Failed to deserialize account data: {e}" ) ;
478
+ }
479
+ }
480
+ }
481
+ }
482
+
465
483
async fn handle_joined_room_update ( & self , updates : JoinedRoomUpdate ) -> Result < ( ) > {
466
484
self . handle_timeline (
467
485
updates. timeline ,
468
486
updates. ephemeral . clone ( ) ,
469
- updates. account_data ,
470
487
updates. ambiguity_changes ,
471
488
)
472
489
. await ?;
490
+
491
+ self . handle_account_data ( updates. account_data ) ;
492
+
473
493
Ok ( ( ) )
474
494
}
475
495
476
496
async fn handle_timeline (
477
497
& self ,
478
498
timeline : Timeline ,
479
499
ephemeral : Vec < Raw < AnySyncEphemeralRoomEvent > > ,
480
- account_data : Vec < Raw < AnyRoomAccountDataEvent > > ,
481
500
ambiguity_changes : BTreeMap < OwnedEventId , AmbiguityChange > ,
482
501
) -> Result < ( ) > {
483
502
if timeline. limited {
@@ -489,7 +508,6 @@ impl RoomEventCacheInner {
489
508
self . replace_all_events_by (
490
509
timeline. events ,
491
510
timeline. prev_batch ,
492
- account_data,
493
511
ephemeral,
494
512
ambiguity_changes,
495
513
)
@@ -501,7 +519,6 @@ impl RoomEventCacheInner {
501
519
self . append_new_events (
502
520
timeline. events ,
503
521
timeline. prev_batch ,
504
- account_data,
505
522
ephemeral,
506
523
ambiguity_changes,
507
524
)
@@ -512,8 +529,7 @@ impl RoomEventCacheInner {
512
529
}
513
530
514
531
async fn handle_left_room_update ( & self , updates : LeftRoomUpdate ) -> Result < ( ) > {
515
- self . handle_timeline ( updates. timeline , Vec :: new ( ) , Vec :: new ( ) , updates. ambiguity_changes )
516
- . await ?;
532
+ self . handle_timeline ( updates. timeline , Vec :: new ( ) , updates. ambiguity_changes ) . await ?;
517
533
Ok ( ( ) )
518
534
}
519
535
@@ -523,7 +539,6 @@ impl RoomEventCacheInner {
523
539
& self ,
524
540
events : Vec < SyncTimelineEvent > ,
525
541
prev_batch : Option < String > ,
526
- account_data : Vec < Raw < AnyRoomAccountDataEvent > > ,
527
542
ephemeral : Vec < Raw < AnySyncEphemeralRoomEvent > > ,
528
543
ambiguity_changes : BTreeMap < OwnedEventId , AmbiguityChange > ,
529
544
) -> Result < ( ) > {
@@ -541,7 +556,6 @@ impl RoomEventCacheInner {
541
556
room_events,
542
557
events,
543
558
prev_batch,
544
- account_data,
545
559
ephemeral,
546
560
ambiguity_changes,
547
561
)
@@ -554,15 +568,13 @@ impl RoomEventCacheInner {
554
568
& self ,
555
569
events : Vec < SyncTimelineEvent > ,
556
570
prev_batch : Option < String > ,
557
- account_data : Vec < Raw < AnyRoomAccountDataEvent > > ,
558
571
ephemeral : Vec < Raw < AnySyncEphemeralRoomEvent > > ,
559
572
ambiguity_changes : BTreeMap < OwnedEventId , AmbiguityChange > ,
560
573
) -> Result < ( ) > {
561
574
self . append_events_locked_impl (
562
575
self . events . write ( ) . await ,
563
576
events,
564
577
prev_batch,
565
- account_data,
566
578
ephemeral,
567
579
ambiguity_changes,
568
580
)
@@ -579,14 +591,12 @@ impl RoomEventCacheInner {
579
591
mut room_events : RwLockWriteGuard < ' _ , RoomEvents > ,
580
592
events : Vec < SyncTimelineEvent > ,
581
593
prev_batch : Option < String > ,
582
- account_data : Vec < Raw < AnyRoomAccountDataEvent > > ,
583
594
ephemeral : Vec < Raw < AnySyncEphemeralRoomEvent > > ,
584
595
ambiguity_changes : BTreeMap < OwnedEventId , AmbiguityChange > ,
585
596
) -> Result < ( ) > {
586
597
if events. is_empty ( )
587
598
&& prev_batch. is_none ( )
588
599
&& ephemeral. is_empty ( )
589
- && account_data. is_empty ( )
590
600
&& ambiguity_changes. is_empty ( )
591
601
{
592
602
return Ok ( ( ) ) ;
@@ -608,12 +618,8 @@ impl RoomEventCacheInner {
608
618
self . pagination_token_notifier . notify_one ( ) ;
609
619
}
610
620
611
- let _ = self . sender . send ( RoomEventCacheUpdate :: Append {
612
- events,
613
- account_data,
614
- ephemeral,
615
- ambiguity_changes,
616
- } ) ;
621
+ let _ =
622
+ self . sender . send ( RoomEventCacheUpdate :: Append { events, ephemeral, ambiguity_changes } ) ;
617
623
618
624
Ok ( ( ) )
619
625
}
@@ -819,13 +825,16 @@ pub enum RoomEventCacheUpdate {
819
825
/// The room has been cleared from events.
820
826
Clear ,
821
827
828
+ /// The fully read marker has moved to a different event.
829
+ UpdateReadMarker {
830
+ /// Event at which the read marker is now pointing.
831
+ event_id : OwnedEventId ,
832
+ } ,
833
+
822
834
/// The room has new events.
823
835
Append {
824
836
/// All the new events that have been added to the room's timeline.
825
837
events : Vec < SyncTimelineEvent > ,
826
- /// XXX: this is temporary, until account data lives in the event cache
827
- /// — or will it live there?
828
- account_data : Vec < Raw < AnyRoomAccountDataEvent > > ,
829
838
/// XXX: this is temporary, until read receipts are handled in the event
830
839
/// cache
831
840
ephemeral : Vec < Raw < AnySyncEphemeralRoomEvent > > ,
0 commit comments