@@ -485,6 +485,48 @@ func TestImportHistoricalMessages(t *testing.T) {
485485 })
486486 })
487487
488+ t .Run ("Should be able to send a batch without any state_events_at_start - user already joined in the current room state" , func (t * testing.T ) {
489+ t .Parallel ()
490+
491+ roomID := as .CreateRoom (t , createPublicRoomOpts )
492+ alice .JoinRoom (t , roomID , nil )
493+
494+ // Create the "live" event we are going to import our historical events next to
495+ eventIDsBefore := createMessagesInRoom (t , alice , roomID , 1 )
496+ eventIdBefore := eventIDsBefore [0 ]
497+ timeAfterEventBefore := time .Now ()
498+
499+ // Import a historical event
500+ batchSendRes := batchSendHistoricalMessages (
501+ t ,
502+ as ,
503+ roomID ,
504+ eventIdBefore ,
505+ "" ,
506+ // The key thing we're testing here is that we can still batch send
507+ // messages when no `state_events_at_start` are given
508+ make ([]map [string ]interface {}, 0 ),
509+ createMessageEventsForBatchSendRequest ([]string {alice .UserID }, timeAfterEventBefore , 3 ),
510+ // Status
511+ 200 ,
512+ )
513+ batchSendResBody := client .ParseJSON (t , batchSendRes )
514+ historicalEventIDs := client .GetJSONFieldStringArray (t , batchSendResBody , "event_ids" )
515+
516+ messagesRes := alice .MustDoFunc (t , "GET" , []string {"_matrix" , "client" , "r0" , "rooms" , roomID , "messages" }, client .WithContentType ("application/json" ), client .WithQueries (url.Values {
517+ "dir" : []string {"b" },
518+ "limit" : []string {"100" },
519+ }))
520+
521+ must .MatchResponse (t , messagesRes , match.HTTPResponse {
522+ JSON : []match.JSON {
523+ match .JSONCheckOffAllowUnwanted ("chunk" , makeInterfaceSlice (historicalEventIDs ), func (r gjson.Result ) interface {} {
524+ return r .Get ("event_id" ).Str
525+ }, nil ),
526+ },
527+ })
528+ })
529+
488530 t .Run ("TODO: Test if historical avatar/display name set back in time are picked up on historical messages" , func (t * testing.T ) {
489531 t .Skip ("Skipping until implemented" )
490532 // TODO: Try adding avatar and displayName and see if historical messages get this info
0 commit comments