@@ -184,7 +184,7 @@ impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> {
184184 }
185185
186186 self . adjust_date_dividers ( date_divider_adjuster) ;
187- self . check_invariants ( ) ;
187+ self . check_invariants ( settings ) ;
188188 }
189189
190190 async fn handle_remote_aggregation (
@@ -339,11 +339,13 @@ impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> {
339339 }
340340
341341 self . adjust_date_dividers ( date_divider_adjuster) ;
342- self . check_invariants ( ) ;
342+ self . check_invariants ( settings ) ;
343343 }
344344
345- fn check_invariants ( & self ) {
346- self . check_no_duplicate_read_receipts ( ) ;
345+ fn check_invariants ( & self , settings : & TimelineSettings ) {
346+ if settings. state_events_can_show_read_receipts {
347+ self . check_no_duplicate_read_receipts ( ) ;
348+ }
347349 self . check_no_unused_unique_ids ( ) ;
348350 }
349351
@@ -460,6 +462,19 @@ impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> {
460462 }
461463 }
462464
465+ /// Whether this event can show read receipts, or if they should be moved
466+ /// to the previous event.
467+ fn can_show_read_receipts (
468+ & self ,
469+ settings : & TimelineSettings ,
470+ event : & AnySyncTimelineEvent ,
471+ ) -> bool {
472+ match event {
473+ AnySyncTimelineEvent :: State ( _) => settings. state_events_can_show_read_receipts ,
474+ AnySyncTimelineEvent :: MessageLike ( _) => true ,
475+ }
476+ }
477+
463478 /// After a deserialization error, adds a failed-to-parse item to the
464479 /// timeline if configured to do so, or logs the error (and optionally
465480 /// save metadata) if not.
@@ -478,6 +493,7 @@ impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> {
478493 Option < TimelineAction > ,
479494 Option < OwnedEventId > ,
480495 bool ,
496+ bool ,
481497 ) > {
482498 let state_key: Option < String > = raw. get_field ( "state_key" ) . ok ( ) . flatten ( ) ;
483499
@@ -537,6 +553,7 @@ impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> {
537553 Some ( TimelineAction :: failed_to_parse ( event_type, deserialization_error) ) ,
538554 None ,
539555 true ,
556+ true ,
540557 ) )
541558 }
542559
@@ -552,7 +569,7 @@ impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> {
552569 // Remember the event before returning prematurely.
553570 // See [`ObservableItems::all_remote_events`].
554571 self . add_or_update_remote_event (
555- EventMeta :: new ( event_id, false , None ) ,
572+ EventMeta :: new ( event_id, false , false , None ) ,
556573 sender. as_deref ( ) ,
557574 origin_server_ts,
558575 position,
@@ -630,65 +647,74 @@ impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> {
630647 _ => ( event. kind . into_raw ( ) , None ) ,
631648 } ;
632649
633- let ( event_id, sender, timestamp, txn_id, timeline_action, thread_root, should_add) =
634- match raw. deserialize ( ) {
635- // Classical path: the event is valid, can be deserialized, everything is alright.
636- Ok ( event) => {
637- let ( in_reply_to, thread_root) = self . meta . process_event_relations (
638- & event,
639- & raw ,
640- bundled_edit_encryption_info,
641- & self . items ,
642- self . focus . is_thread ( ) ,
643- ) ;
650+ let (
651+ event_id,
652+ sender,
653+ timestamp,
654+ txn_id,
655+ timeline_action,
656+ thread_root,
657+ should_add,
658+ can_show_read_receipts,
659+ ) = match raw. deserialize ( ) {
660+ // Classical path: the event is valid, can be deserialized, everything is alright.
661+ Ok ( event) => {
662+ let ( in_reply_to, thread_root) = self . meta . process_event_relations (
663+ & event,
664+ & raw ,
665+ bundled_edit_encryption_info,
666+ & self . items ,
667+ self . focus . is_thread ( ) ,
668+ ) ;
669+
670+ let should_add = self . should_add_event_item (
671+ room_data_provider,
672+ settings,
673+ & event,
674+ thread_root. as_deref ( ) ,
675+ position,
676+ ) ;
677+
678+ let can_show_read_receipts = self . can_show_read_receipts ( settings, & event) ;
644679
645- let should_add = self . should_add_event_item (
680+ (
681+ event. event_id ( ) . to_owned ( ) ,
682+ event. sender ( ) . to_owned ( ) ,
683+ event. origin_server_ts ( ) ,
684+ event. transaction_id ( ) . map ( ToOwned :: to_owned) ,
685+ TimelineAction :: from_event (
686+ event,
687+ & raw ,
646688 room_data_provider,
647- settings,
648- & event,
649- thread_root. as_deref ( ) ,
650- position,
651- ) ;
652-
653- (
654- event. event_id ( ) . to_owned ( ) ,
655- event. sender ( ) . to_owned ( ) ,
656- event. origin_server_ts ( ) ,
657- event. transaction_id ( ) . map ( ToOwned :: to_owned) ,
658- TimelineAction :: from_event (
659- event,
660- & raw ,
661- room_data_provider,
662- utd_info. map ( |utd_info| {
663- ( utd_info, self . meta . unable_to_decrypt_hook . as_ref ( ) )
664- } ) ,
665- in_reply_to,
666- thread_root. clone ( ) ,
667- thread_summary,
668- )
669- . await ,
670- thread_root,
671- should_add,
689+ utd_info
690+ . map ( |utd_info| ( utd_info, self . meta . unable_to_decrypt_hook . as_ref ( ) ) ) ,
691+ in_reply_to,
692+ thread_root. clone ( ) ,
693+ thread_summary,
672694 )
673- }
695+ . await ,
696+ thread_root,
697+ should_add,
698+ can_show_read_receipts,
699+ )
700+ }
674701
675- // The event seems invalid…
676- Err ( e) => {
677- if let Some ( tuple) = self
678- . maybe_add_error_item ( position, room_data_provider, & raw , e, settings)
679- . await
680- {
681- tuple
682- } else {
683- return false ;
684- }
702+ // The event seems invalid…
703+ Err ( e) => {
704+ if let Some ( tuple) =
705+ self . maybe_add_error_item ( position, room_data_provider, & raw , e, settings) . await
706+ {
707+ tuple
708+ } else {
709+ return false ;
685710 }
686- } ;
711+ }
712+ } ;
687713
688714 // Remember the event.
689715 // See [`ObservableItems::all_remote_events`].
690716 self . add_or_update_remote_event (
691- EventMeta :: new ( event_id. clone ( ) , should_add, thread_root) ,
717+ EventMeta :: new ( event_id. clone ( ) , should_add, can_show_read_receipts , thread_root) ,
692718 Some ( & sender) ,
693719 Some ( timestamp) ,
694720 position,
@@ -887,9 +913,11 @@ impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> {
887913 TimelineItemPosition :: UpdateAt { .. } => {
888914 if let Some ( event) =
889915 self . items . get_remote_event_by_event_id_mut ( & event_meta. event_id )
890- && event. visible != event_meta. visible
916+ && ( event. visible != event_meta. visible
917+ || event. can_show_read_receipts != event_meta. can_show_read_receipts )
891918 {
892919 event. visible = event_meta. visible ;
920+ event. can_show_read_receipts = event_meta. can_show_read_receipts ;
893921
894922 if settings. track_read_receipts {
895923 // Since the event's visibility changed, we need to update the read
0 commit comments