@@ -15,6 +15,7 @@ import (
15
15
"testing"
16
16
"time"
17
17
18
+ "github.com/sirupsen/logrus"
18
19
"github.com/tidwall/gjson"
19
20
20
21
"github.com/matrix-org/complement/internal/b"
@@ -457,6 +458,82 @@ func TestBackfillingHistory(t *testing.T) {
457
458
// TODO: Try adding avatar and displayName and see if historical messages get this info
458
459
})
459
460
461
+ t .Run ("should resolve member state events for historical events" , func (t * testing.T ) {
462
+ t .Parallel ()
463
+
464
+ roomID := as .CreateRoom (t , createPublicRoomOpts )
465
+ alice .JoinRoom (t , roomID , nil )
466
+
467
+ // Create the "live" event we are going to insert our backfilled events next to
468
+ eventIDsBefore := createMessagesInRoom (t , alice , roomID , 1 )
469
+ eventIdBefore := eventIDsBefore [0 ]
470
+ timeAfterEventBefore := time .Now ()
471
+
472
+ // eventIDsAfter
473
+ createMessagesInRoom (t , alice , roomID , 2 )
474
+
475
+ // Insert a backfilled event
476
+ batchSendRes := batchSendHistoricalMessages (
477
+ t ,
478
+ as ,
479
+ roomID ,
480
+ eventIdBefore ,
481
+ "" ,
482
+ createJoinStateEventsForBackfillRequest ([]string {virtualUserID }, timeAfterEventBefore ),
483
+ createMessageEventsForBackfillRequest ([]string {virtualUserID }, timeAfterEventBefore , 3 ),
484
+ // Status
485
+ 200 ,
486
+ )
487
+ batchSendResBody0 := client .ParseJSON (t , batchSendRes )
488
+ historicalEventIDs0 := client .GetJSONFieldStringArray (t , batchSendResBody0 , "event_ids" )
489
+ nextBatchID0 := client .GetJSONFieldStr (t , batchSendResBody0 , "next_batch_id" )
490
+
491
+ contextRes0 := alice .MustDoFunc (t , "GET" , []string {"_matrix" , "client" , "r0" , "rooms" , roomID , "context" , historicalEventIDs0 [1 ]}, client .WithContentType ("application/json" ))
492
+ contextResBody0 := client .ParseJSON (t , contextRes0 )
493
+ stateJsonResult0 := gjson .GetBytes (contextResBody0 , "state" )
494
+ stateFromContext0 := stateJsonResult0 .Array ()
495
+
496
+ logrus .WithFields (logrus.Fields {
497
+ "stateFromContext" : stateFromContext0 ,
498
+ "len" : len (stateFromContext0 ),
499
+ }).Error ("gaweegegegwegawagewg 0" )
500
+
501
+ if len (stateFromContext0 ) == 0 {
502
+ t .Fatalf ("Expected some state events in the context response for historical event in first batch but saw %d: %s" , len (stateFromContext0 ), stateFromContext0 )
503
+ }
504
+
505
+ // Insert another older batch of backfilled history from the same user.
506
+ // Make sure the meta data and joins still work on the subsequent batch
507
+ insertTime1 := timeAfterEventBefore
508
+ batchSendRes1 := batchSendHistoricalMessages (
509
+ t ,
510
+ as ,
511
+ roomID ,
512
+ eventIdBefore ,
513
+ nextBatchID0 ,
514
+ createJoinStateEventsForBackfillRequest ([]string {virtualUserID }, insertTime1 ),
515
+ createMessageEventsForBackfillRequest ([]string {virtualUserID }, insertTime1 , 3 ),
516
+ // Status
517
+ 200 ,
518
+ )
519
+ batchSendResBody1 := client .ParseJSON (t , batchSendRes1 )
520
+ historicalEventIDs1 := client .GetJSONFieldStringArray (t , batchSendResBody1 , "event_ids" )
521
+
522
+ contextRes1 := alice .MustDoFunc (t , "GET" , []string {"_matrix" , "client" , "r0" , "rooms" , roomID , "context" , historicalEventIDs1 [1 ]}, client .WithContentType ("application/json" ))
523
+ contextResBody1 := client .ParseJSON (t , contextRes1 )
524
+ stateJsonResult1 := gjson .GetBytes (contextResBody1 , "state" )
525
+ stateFromContext1 := stateJsonResult1 .Array ()
526
+
527
+ logrus .WithFields (logrus.Fields {
528
+ "stateFromContext" : stateFromContext1 ,
529
+ "len" : len (stateFromContext1 ),
530
+ }).Error ("gaweegegegwegawagewg 1" )
531
+
532
+ if len (stateFromContext1 ) == 0 {
533
+ t .Fatalf ("Expected some state events in the context response for historical event in second batch but saw %d: %s" , len (stateFromContext1 ), stateFromContext1 )
534
+ }
535
+ })
536
+
460
537
t .Run ("TODO: What happens when you point multiple batches at the same insertion event?" , func (t * testing.T ) {
461
538
t .Skip ("Skipping until implemented" )
462
539
})
0 commit comments