@@ -106,7 +106,7 @@ func TestBackfillingHistory(t *testing.T) {
106
106
backfillRes := backfillBatchHistoricalMessages (
107
107
t ,
108
108
as ,
109
- virtualUserID ,
109
+ [] string { virtualUserID } ,
110
110
roomID ,
111
111
eventIdBefore ,
112
112
timeAfterEventBefore .Add (timeBetweenMessages * 3 ),
@@ -123,7 +123,7 @@ func TestBackfillingHistory(t *testing.T) {
123
123
backfillRes2 := backfillBatchHistoricalMessages (
124
124
t ,
125
125
as ,
126
- virtualUserID ,
126
+ [] string { virtualUserID } ,
127
127
roomID ,
128
128
eventIdBefore ,
129
129
timeAfterEventBefore ,
@@ -184,6 +184,48 @@ func TestBackfillingHistory(t *testing.T) {
184
184
}
185
185
})
186
186
187
+ t .Run ("Backfilled historical events from multiple users in the same chunk" , func (t * testing.T ) {
188
+ t .Parallel ()
189
+
190
+ roomID := as .CreateRoom (t , struct {}{})
191
+ alice .JoinRoom (t , roomID , nil )
192
+
193
+ // Create the "live" event we are going to insert our backfilled events next to
194
+ eventIDsBefore := createMessagesInRoom (t , alice , roomID , 1 )
195
+ eventIdBefore := eventIDsBefore [0 ]
196
+ timeAfterEventBefore := time .Now ()
197
+
198
+ // Insert a backfilled event
199
+ virtualUserID2 := "@ricky:hs1"
200
+ virtualUserID3 := "@carol:hs1"
201
+ backfillRes := backfillBatchHistoricalMessages (
202
+ t ,
203
+ as ,
204
+ []string {virtualUserID , virtualUserID2 , virtualUserID3 },
205
+ roomID ,
206
+ eventIdBefore ,
207
+ timeAfterEventBefore ,
208
+ "" ,
209
+ 3 ,
210
+ // Status
211
+ 200 ,
212
+ )
213
+ historicalEventIDs := getEventsFromBatchSendResponse (t , backfillRes )
214
+
215
+ messagesRes := alice .MustDoFunc (t , "GET" , []string {"_matrix" , "client" , "r0" , "rooms" , roomID , "messages" }, client .WithContentType ("application/json" ), client .WithQueries (url.Values {
216
+ "dir" : []string {"b" },
217
+ "limit" : []string {"100" },
218
+ }))
219
+
220
+ must .MatchResponse (t , messagesRes , match.HTTPResponse {
221
+ JSON : []match.JSON {
222
+ match .JSONCheckOffAllowUnwanted ("chunk" , []interface {}{historicalEventIDs [0 ], historicalEventIDs [1 ], historicalEventIDs [2 ]}, func (r gjson.Result ) interface {} {
223
+ return r .Get ("event_id" ).Str
224
+ }, nil ),
225
+ },
226
+ })
227
+ })
228
+
187
229
t .Run ("Backfilled historical events with m.historical do not come down in an incremental sync" , func (t * testing.T ) {
188
230
t .Parallel ()
189
231
@@ -202,7 +244,7 @@ func TestBackfillingHistory(t *testing.T) {
202
244
backfillRes := backfillBatchHistoricalMessages (
203
245
t ,
204
246
as ,
205
- virtualUserID ,
247
+ [] string { virtualUserID } ,
206
248
roomID ,
207
249
eventIdBefore ,
208
250
timeAfterEventBefore ,
@@ -238,7 +280,7 @@ func TestBackfillingHistory(t *testing.T) {
238
280
backfillBatchHistoricalMessages (
239
281
t ,
240
282
as ,
241
- virtualUserID ,
283
+ [] string { virtualUserID } ,
242
284
roomID ,
243
285
"$some-non-existant-event-id" ,
244
286
time .Now (),
@@ -265,7 +307,7 @@ func TestBackfillingHistory(t *testing.T) {
265
307
backfillBatchHistoricalMessages (
266
308
t ,
267
309
alice ,
268
- virtualUserID ,
310
+ [] string { virtualUserID } ,
269
311
roomID ,
270
312
eventIdBefore ,
271
313
timeAfterEventBefore ,
@@ -302,7 +344,7 @@ func TestBackfillingHistory(t *testing.T) {
302
344
backfillRes := backfillBatchHistoricalMessages (
303
345
t ,
304
346
as ,
305
- virtualUserID ,
347
+ [] string { virtualUserID } ,
306
348
roomID ,
307
349
eventIdBefore ,
308
350
timeAfterEventBefore ,
@@ -360,7 +402,7 @@ func TestBackfillingHistory(t *testing.T) {
360
402
backfillRes := backfillBatchHistoricalMessages (
361
403
t ,
362
404
as ,
363
- virtualUserID ,
405
+ [] string { virtualUserID } ,
364
406
roomID ,
365
407
eventIdBefore ,
366
408
timeAfterEventBefore ,
@@ -416,7 +458,7 @@ func TestBackfillingHistory(t *testing.T) {
416
458
backfillRes := backfillBatchHistoricalMessages (
417
459
t ,
418
460
as ,
419
- virtualUserID ,
461
+ [] string { virtualUserID } ,
420
462
roomID ,
421
463
eventIdBefore ,
422
464
timeAfterEventBefore ,
@@ -521,7 +563,7 @@ var chunkCount int64 = 0
521
563
func backfillBatchHistoricalMessages (
522
564
t * testing.T ,
523
565
c * client.CSAPI ,
524
- virtualUserID string ,
566
+ virtualUserIDs [] string ,
525
567
roomID string ,
526
568
insertAfterEventId string ,
527
569
insertTime time.Time ,
@@ -536,6 +578,8 @@ func backfillBatchHistoricalMessages(
536
578
537
579
evs := make ([]map [string ]interface {}, count )
538
580
for i := 0 ; i < len (evs ); i ++ {
581
+ virtualUserID := virtualUserIDs [i % len (virtualUserIDs )]
582
+
539
583
newEvent := map [string ]interface {}{
540
584
"type" : "m.room.message" ,
541
585
"sender" : virtualUserID ,
@@ -550,19 +594,23 @@ func backfillBatchHistoricalMessages(
550
594
evs [i ] = newEvent
551
595
}
552
596
553
- joinEvent := map [string ]interface {}{
554
- "type" : "m.room.member" ,
555
- "sender" : virtualUserID ,
556
- "origin_server_ts" : insertOriginServerTs ,
557
- "content" : map [string ]interface {}{
558
- "membership" : "join" ,
559
- },
560
- "state_key" : virtualUserID ,
597
+ state_evs := make ([]map [string ]interface {}, len (virtualUserIDs ))
598
+ for i , virtualUserID := range virtualUserIDs {
599
+ joinEvent := map [string ]interface {}{
600
+ "type" : "m.room.member" ,
601
+ "sender" : virtualUserID ,
602
+ "origin_server_ts" : insertOriginServerTs ,
603
+ "content" : map [string ]interface {}{
604
+ "membership" : "join" ,
605
+ },
606
+ "state_key" : virtualUserID ,
607
+ }
608
+
609
+ state_evs [i ] = joinEvent
561
610
}
562
611
563
612
query := make (url.Values , 2 )
564
613
query .Add ("prev_event" , insertAfterEventId )
565
- query .Add ("user_id" , virtualUserID )
566
614
// If provided, connect the chunk to the last insertion point
567
615
if chunkID != "" {
568
616
query .Add ("chunk_id" , chunkID )
@@ -574,7 +622,7 @@ func backfillBatchHistoricalMessages(
574
622
[]string {"_matrix" , "client" , "unstable" , "org.matrix.msc2716" , "rooms" , roomID , "batch_send" },
575
623
client .WithJSONBody (t , map [string ]interface {}{
576
624
"events" : evs ,
577
- "state_events_at_start" : [] map [ string ] interface {}{ joinEvent } ,
625
+ "state_events_at_start" : state_evs ,
578
626
}),
579
627
client .WithContentType ("application/json" ),
580
628
client .WithQueries (query ),
0 commit comments