@@ -342,7 +342,7 @@ func TestBackfillingHistory(t *testing.T) {
342342 // TODO: Try adding avatar and displayName and see if historical messages get this info
343343 })
344344
345- t .Run ("Historical messages are visible when joining on federated server" , func (t * testing.T ) {
345+ t .Run ("Historical messages are visible when joining on federated server - auto-generated base insertion event " , func (t * testing.T ) {
346346 t .Skip ("Skipping until federation is implemented" )
347347 t .Parallel ()
348348
@@ -393,6 +393,75 @@ func TestBackfillingHistory(t *testing.T) {
393393 })
394394 })
395395
396+ t .Run ("Historical messages are visible when joining on federated server - pre-made insertion event" , func (t * testing.T ) {
397+ t .Skip ("Skipping until federation is implemented" )
398+ t .Parallel ()
399+
400+ roomID := as .CreateRoom (t , map [string ]interface {}{
401+ "preset" : "public_chat" ,
402+ "name" : "the hangout spot" ,
403+ })
404+ alice .JoinRoom (t , roomID , nil )
405+
406+ eventIDsBefore := createMessagesInRoom (t , alice , roomID , 1 )
407+ eventIdBefore := eventIDsBefore [0 ]
408+ timeAfterEventBefore := time .Now ()
409+
410+ // Create insertion event in the normal DAG
411+ chunkId := "mynextchunkid123"
412+ insertionEvent := b.Event {
413+ Type : insertionEventType ,
414+ Content : map [string ]interface {}{
415+ nextChunkIDContentField : chunkId ,
416+ historicalContentField : true ,
417+ },
418+ }
419+ // We can't use as.SendEventSynced(...) because application services can't use the /sync API
420+ insertionSendRes := as .MustDoFunc (t , "PUT" , []string {"_matrix" , "client" , "r0" , "rooms" , roomID , "send" , insertionEvent .Type , "txn-m123" }, client .WithJSONBody (t , insertionEvent .Content ))
421+ insertionSendBody := client .ParseJSON (t , insertionSendRes )
422+ insertionEventID := client .GetJSONFieldStr (t , insertionSendBody , "event_id" )
423+ // Make sure the insertion event has reached the homeserver
424+ alice .SyncUntilTimelineHas (t , roomID , func (ev gjson.Result ) bool {
425+ return ev .Get ("event_id" ).Str == insertionEventID
426+ })
427+
428+ // eventIDsAfter
429+ createMessagesInRoom (t , alice , roomID , 3 )
430+
431+ batchSendRes := batchSendHistoricalMessages (
432+ t ,
433+ as ,
434+ []string {virtualUserID },
435+ roomID ,
436+ eventIdBefore ,
437+ timeAfterEventBefore ,
438+ chunkId ,
439+ 2 ,
440+ // Status
441+ 200 ,
442+ )
443+ batchSendResBody := client .ParseJSON (t , batchSendRes )
444+ historicalEventIDs := getEventsFromBatchSendResponseBody (t , batchSendResBody )
445+
446+ // Join the room from a remote homeserver after the backfilled messages were sent
447+ remoteCharlie .JoinRoom (t , roomID , []string {"hs1" })
448+
449+ // TODO: I think we need to update this to be similar to
450+ // SyncUntilTimelineHas but going back in time because this can be flakey
451+ messagesRes := remoteCharlie .MustDoFunc (t , "GET" , []string {"_matrix" , "client" , "r0" , "rooms" , roomID , "messages" }, client .WithContentType ("application/json" ), client .WithQueries (url.Values {
452+ "dir" : []string {"b" },
453+ "limit" : []string {"100" },
454+ }))
455+
456+ must .MatchResponse (t , messagesRes , match.HTTPResponse {
457+ JSON : []match.JSON {
458+ match .JSONCheckOffAllowUnwanted ("chunk" , makeInterfaceSlice (historicalEventIDs ), func (r gjson.Result ) interface {} {
459+ return r .Get ("event_id" ).Str
460+ }, nil ),
461+ },
462+ })
463+ })
464+
396465 t .Run ("Historical messages are visible when already joined on federated server" , func (t * testing.T ) {
397466 t .Skip ("Skipping until federation is implemented" )
398467 t .Parallel ()
0 commit comments