@@ -1319,6 +1319,84 @@ async fn test_initial_read_receipts_are_correctly_populated() {
13191319 assert_eq ! ( rr[ * BOB ] . thread, receipt_thread) ;
13201320}
13211321
1322+ #[ async_test]
1323+ async fn test_initial_read_receipts_compatibility_mode ( ) {
1324+ // If there are initial read receipts in the store, that are using the
1325+ // "unthreaded" kind of receipt, then they're used as "main" receipts as
1326+ // well.
1327+
1328+ let server = MatrixMockServer :: new ( ) . await ;
1329+ let client = client_with_threading_support ( & server) . await ;
1330+ client. event_cache ( ) . subscribe ( ) . unwrap ( ) ;
1331+
1332+ let room_id = room_id ! ( "!a:b.c" ) ;
1333+
1334+ // Start with a room that has an event with some initial read receipts.
1335+ //
1336+ // It is sync'd *before* the timeline is created, so the timeline will have to
1337+ // load the receipts from the store.
1338+ let f = EventFactory :: new ( ) ;
1339+ let room = server
1340+ . sync_room (
1341+ & client,
1342+ JoinedRoomBuilder :: new ( room_id)
1343+ . add_timeline_event (
1344+ f. text_msg ( "hello in main timeline" ) . sender ( * BOB ) . event_id ( event_id ! ( "$0" ) ) ,
1345+ )
1346+ . add_timeline_event (
1347+ f. text_msg ( "hello back in main timeline" )
1348+ . sender ( * ALICE )
1349+ . event_id ( event_id ! ( "$1" ) ) ,
1350+ )
1351+ . add_receipt (
1352+ f. read_receipts ( )
1353+ . add ( event_id ! ( "$1" ) , * BOB , ReceiptType :: Read , ReceiptThread :: Unthreaded )
1354+ . into_event ( ) ,
1355+ ) ,
1356+ )
1357+ . await ;
1358+
1359+ // Create a main timeline.
1360+ let timeline = room
1361+ . timeline_builder ( )
1362+ . with_focus ( TimelineFocus :: Live { hide_threaded_events : true } )
1363+ . build ( )
1364+ . await
1365+ . unwrap ( ) ;
1366+
1367+ let ( mut initial_items, mut stream) = timeline. subscribe ( ) . await ;
1368+
1369+ // Wait for the initial items.
1370+ if initial_items. is_empty ( ) {
1371+ assert_let_timeout ! ( Some ( timeline_updates) = stream. next( ) ) ;
1372+ for up in timeline_updates {
1373+ up. apply ( & mut initial_items) ;
1374+ }
1375+ }
1376+
1377+ // After stabilizing the timeline, we should see the initial read receipts
1378+ // set as intended.
1379+ assert_eq ! ( initial_items. len( ) , 3 ) ;
1380+
1381+ assert ! ( initial_items[ 0 ] . is_date_divider( ) ) ;
1382+
1383+ {
1384+ let ev = initial_items[ 1 ] . as_event ( ) . unwrap ( ) ;
1385+ assert_eq ! ( ev. event_id( ) , Some ( event_id!( "$0" ) ) ) ;
1386+ let rr = ev. read_receipts ( ) ;
1387+ assert ! ( rr. is_empty( ) ) ;
1388+ }
1389+
1390+ {
1391+ let ev = initial_items[ 2 ] . as_event ( ) . unwrap ( ) ;
1392+ assert_eq ! ( ev. event_id( ) , Some ( event_id!( "$1" ) ) ) ;
1393+ let rr = ev. read_receipts ( ) ;
1394+ assert_eq ! ( rr. len( ) , 2 ) ;
1395+ assert ! ( rr. get( * ALICE ) . is_some( ) ) ;
1396+ assert ! ( rr. get( * BOB ) . is_some( ) ) ;
1397+ }
1398+ }
1399+
13221400#[ async_test]
13231401async fn test_send_read_receipts ( ) {
13241402 // Threaded read receipts can be sent from a thread timeline. Trying to send a
0 commit comments