@@ -561,45 +561,36 @@ impl<P: RoomDataProvider> TimelineStateTransaction<'_, P> {
561561
562562 let receipt_thread = self . focus . receipt_thread ( ) ;
563563
564- let mut read_receipts;
565-
566- if matches ! ( receipt_thread, ReceiptThread :: Unthreaded | ReceiptThread :: Main ) {
564+ let receipts = if matches ! ( receipt_thread, ReceiptThread :: Unthreaded | ReceiptThread :: Main )
565+ {
567566 // If the requested receipt thread is unthreaded or main, we maintain maximal
568567 // compatibility with clients using either unthreaded or main-thread read
569568 // receipts by allowing both here.
570569
571570 // First, load the main receipts.
572- read_receipts =
571+ let mut main_receipts =
573572 room_data_provider. load_event_receipts ( event_id, ReceiptThread :: Main ) . await ;
574573
575574 // Then, load the unthreaded receipts.
576575 let unthreaded_receipts =
577576 room_data_provider. load_event_receipts ( event_id, ReceiptThread :: Unthreaded ) . await ;
578577
579- // Only insert unthreaded receipts that are more recent. Ideally we'd compare
580- // the receipted event position, but we don't have access to that
581- // here.
582- for ( user_id, unthreaded_receipt) in unthreaded_receipts {
583- if let Some ( main_receipt) = read_receipts. get ( & user_id) {
584- if unthreaded_receipt. ts > main_receipt. ts {
585- read_receipts. insert ( user_id, unthreaded_receipt) ;
586- }
587- } else {
588- read_receipts. insert ( user_id, unthreaded_receipt) ;
589- }
590- }
578+ // We can safely extend both here: if a key is already set, then that means that
579+ // the user has the unthreaded and main receipt on the main event,
580+ // which is fine, and something we display as the one user receipt.
581+ main_receipts. extend ( unthreaded_receipts) ;
582+ main_receipts
591583 } else {
592584 // In all other cases, return what's requested, and only that (threaded
593585 // receipts).
594- read_receipts =
595- room_data_provider. load_event_receipts ( event_id, receipt_thread. clone ( ) ) . await
596- }
586+ room_data_provider. load_event_receipts ( event_id, receipt_thread. clone ( ) ) . await
587+ } ;
597588
598589 let own_user_id = room_data_provider. own_user_id ( ) ;
599590
600591 // Since they are explicit read receipts, we need to check if they are
601592 // superseded by implicit read receipts.
602- for ( user_id, receipt) in read_receipts {
593+ for ( user_id, receipt) in receipts {
603594 let full_receipt = FullReceipt {
604595 event_id,
605596 user_id : & user_id,
0 commit comments