@@ -306,6 +306,47 @@ func TestImportHistoricalMessages(t *testing.T) {
306
306
}
307
307
})
308
308
309
+ t .Run ("Non-member state events are allowed in state_events_at_start" , func (t * testing.T ) {
310
+ t .Parallel ()
311
+
312
+ roomID := as .CreateRoom (t , createPublicRoomOpts )
313
+ alice .JoinRoom (t , roomID , nil )
314
+
315
+ // Create the "live" event we are going to insert our historical events next to
316
+ eventIDsBefore := createMessagesInRoom (t , alice , roomID , 1 , "eventIDsBefore" )
317
+ eventIdBefore := eventIDsBefore [0 ]
318
+ timeAfterEventBefore := time .Now ()
319
+
320
+ stateEventsAtStart := createJoinStateEventsForBatchSendRequest ([]string {virtualUserID }, timeAfterEventBefore )
321
+ // Add the non-member state
322
+ stateEventsAtStart = append (stateEventsAtStart , map [string ]interface {}{
323
+ "type" : "org.matrix.msc2716.foobarbaz" ,
324
+ "sender" : as .UserID ,
325
+ "origin_server_ts" : uint64 (timeAfterEventBefore .UnixNano () / int64 (time .Millisecond )),
326
+ "content" : map [string ]interface {}{
327
+ "foo" : "bar" ,
328
+ },
329
+ "state_key" : "" ,
330
+ })
331
+
332
+ batchSendRes := batchSendHistoricalMessages (
333
+ t ,
334
+ as ,
335
+ roomID ,
336
+ eventIdBefore ,
337
+ "" ,
338
+ stateEventsAtStart ,
339
+ createMessageEventsForBatchSendRequest ([]string {virtualUserID }, timeAfterEventBefore , 1 ),
340
+ // Status
341
+ 200 ,
342
+ )
343
+ validateBatchSendRes (
344
+ t , as , roomID , batchSendRes ,
345
+ // Validate that the non-member state resolves
346
+ true ,
347
+ )
348
+ })
349
+
309
350
t .Run ("Unrecognised prev_event ID will throw an error" , func (t * testing.T ) {
310
351
t .Parallel ()
311
352
@@ -1342,37 +1383,30 @@ func validateBatchSendRes(t *testing.T, c *client.CSAPI, roomID string, batchSen
1342
1383
expectedEventIDOrder = append (expectedEventIDOrder , reversed (historicalEventIDs )... )
1343
1384
expectedEventIDOrder = append (expectedEventIDOrder , insertionEventID )
1344
1385
1386
+ // Make sure the historical events appear in scrollback without jumping back
1387
+ // in time specifically.
1388
+ fullMessagesRes := c .MustDoFunc (t , "GET" , []string {"_matrix" , "client" , "r0" , "rooms" , roomID , "messages" }, client .WithContentType ("application/json" ), client .WithQueries (url.Values {
1389
+ "dir" : []string {"b" },
1390
+ "limit" : []string {"100" },
1391
+ }))
1392
+ must .MatchResponse (t , fullMessagesRes , match.HTTPResponse {
1393
+ JSON : []match.JSON {
1394
+ matcherJSONEventIDArrayInOrder ("chunk" ,
1395
+ expectedEventIDOrder ,
1396
+ historicalEventFilter ,
1397
+ ),
1398
+ },
1399
+ })
1400
+
1401
+ // Validate state after we paginate `/messages` to avoid any potential 404 if
1402
+ // the server hasn't backfilled here yet
1345
1403
if validateState {
1346
- // Get a pagination token for the newest-in-time event in the historical batch itself
1347
1404
contextRes := c .MustDoFunc (t , "GET" , []string {"_matrix" , "client" , "r0" , "rooms" , roomID , "context" , expectedEventIDOrder [0 ]}, client .WithContentType ("application/json" ), client .WithQueries (url.Values {
1348
1405
"limit" : []string {"0" },
1349
1406
}))
1350
- contextResBody := client .ParseJSON (t , contextRes )
1351
- batchStartPaginationToken := client .GetJSONFieldStr (t , contextResBody , "end" )
1352
-
1353
- // Fetch a chunk of `/messages` which only contains the historical batch. We
1354
- // want to do this because `/messages` only returns the state for the first
1355
- // message in the `chunk` and we want to be able assert that the historical
1356
- // state is able to be resolved.
1357
- messagesRes := c .MustDoFunc (t , "GET" , []string {"_matrix" , "client" , "r0" , "rooms" , roomID , "messages" }, client .WithContentType ("application/json" ), client .WithQueries (url.Values {
1358
- // Go backwards (newest -> oldest) (same direction as if you were using scrollback)
1359
- "dir" : []string {"b" },
1360
- // From the newest-in-time event in the historical batch
1361
- "from" : []string {batchStartPaginationToken },
1362
- // We are aiming to scrollback to the oldest-in-time event from the
1363
- // historical batch
1364
- "limit" : []string {fmt .Sprintf ("%d" , len (expectedEventIDOrder ))},
1365
- // We add these options to the filter so we get member events in the state field
1366
- "filter" : []string {"{\" lazy_load_members\" :true,\" include_redundant_members\" :true}" },
1367
- }))
1368
1407
1369
- must .MatchResponse (t , messagesRes , match.HTTPResponse {
1408
+ must .MatchResponse (t , contextRes , match.HTTPResponse {
1370
1409
JSON : []match.JSON {
1371
- // Double-check that we're in the right place of scrollback
1372
- matcherJSONEventIDArrayInOrder ("chunk" ,
1373
- expectedEventIDOrder ,
1374
- historicalEventFilter ,
1375
- ),
1376
1410
// Make sure the historical m.room.member join state event resolves
1377
1411
// for the given chunk of messages in scrollback. The member event
1378
1412
// will include the displayname and avatar.
@@ -1382,21 +1416,6 @@ func validateBatchSendRes(t *testing.T, c *client.CSAPI, roomID string, batchSen
1382
1416
},
1383
1417
})
1384
1418
}
1385
-
1386
- // Make sure the historical events appear in scrollback without jumping back
1387
- // in time specifically.
1388
- fullMessagesRes := c .MustDoFunc (t , "GET" , []string {"_matrix" , "client" , "r0" , "rooms" , roomID , "messages" }, client .WithContentType ("application/json" ), client .WithQueries (url.Values {
1389
- "dir" : []string {"b" },
1390
- "limit" : []string {"100" },
1391
- }))
1392
- must .MatchResponse (t , fullMessagesRes , match.HTTPResponse {
1393
- JSON : []match.JSON {
1394
- matcherJSONEventIDArrayInOrder ("chunk" ,
1395
- expectedEventIDOrder ,
1396
- historicalEventFilter ,
1397
- ),
1398
- },
1399
- })
1400
1419
}
1401
1420
1402
1421
// matcherJSONEventIDArrayInOrder loops through `jsonArrayKey` in the response
0 commit comments