43
43
44
44
class RoomBatchSendEventRestServlet (RestServlet ):
45
45
"""
46
- API endpoint which can insert a chunk of events historically back in time
46
+ API endpoint which can insert a batch of events historically back in time
47
47
next to the given `prev_event`.
48
48
49
- `chunk_id ` comes from `next_chunk_id `in the response of the batch send
50
- endpoint and is derived from the "insertion" events added to each chunk .
49
+ `batch_id ` comes from `next_batch_id `in the response of the batch send
50
+ endpoint and is derived from the "insertion" events added to each batch .
51
51
It's not required for the first batch send.
52
52
53
53
`state_events_at_start` is used to define the historical state events
54
54
needed to auth the events like join events. These events will float
55
55
outside of the normal DAG as outlier's and won't be visible in the chat
56
- history which also allows us to insert multiple chunks without having a bunch
57
- of `@mxid joined the room` noise between each chunk .
56
+ history which also allows us to insert multiple batches without having a bunch
57
+ of `@mxid joined the room` noise between each batch .
58
58
59
- `events` is chronological chunk/ list of events you want to insert.
60
- There is a reverse-chronological constraint on chunks so once you insert
59
+ `events` is chronological list of events you want to insert.
60
+ There is a reverse-chronological constraint on batches so once you insert
61
61
some messages, you can only insert older ones after that.
62
- tldr; Insert chunks from your most recent history -> oldest history.
62
+ tldr; Insert batches from your most recent history -> oldest history.
63
63
64
- POST /_matrix/client/unstable/org.matrix.msc2716/rooms/<roomID>/batch_send?prev_event_id=<eventID>&chunk_id=<chunkID >
64
+ POST /_matrix/client/unstable/org.matrix.msc2716/rooms/<roomID>/batch_send?prev_event_id=<eventID>&batch_id=<batchID >
65
65
{
66
66
"events": [ ... ],
67
67
"state_events_at_start": [ ... ]
@@ -129,7 +129,7 @@ def _create_insertion_event_dict(
129
129
self , sender : str , room_id : str , origin_server_ts : int
130
130
) -> JsonDict :
131
131
"""Creates an event dict for an "insertion" event with the proper fields
132
- and a random chunk ID.
132
+ and a random batch ID.
133
133
134
134
Args:
135
135
sender: The event author MXID
@@ -140,13 +140,13 @@ def _create_insertion_event_dict(
140
140
The new event dictionary to insert.
141
141
"""
142
142
143
- next_chunk_id = random_string (8 )
143
+ next_batch_id = random_string (8 )
144
144
insertion_event = {
145
145
"type" : EventTypes .MSC2716_INSERTION ,
146
146
"sender" : sender ,
147
147
"room_id" : room_id ,
148
148
"content" : {
149
- EventContentFields .MSC2716_NEXT_CHUNK_ID : next_chunk_id ,
149
+ EventContentFields .MSC2716_NEXT_BATCH_ID : next_batch_id ,
150
150
EventContentFields .MSC2716_HISTORICAL : True ,
151
151
},
152
152
"origin_server_ts" : origin_server_ts ,
@@ -191,7 +191,7 @@ async def on_POST(
191
191
prev_event_ids_from_query = parse_strings_from_args (
192
192
request .args , "prev_event_id"
193
193
)
194
- chunk_id_from_query = parse_string (request , "chunk_id " )
194
+ batch_id_from_query = parse_string (request , "batch_id " )
195
195
196
196
if prev_event_ids_from_query is None :
197
197
raise SynapseError (
@@ -291,27 +291,27 @@ async def on_POST(
291
291
prev_event_ids_from_query
292
292
)
293
293
294
- # Figure out which chunk to connect to. If they passed in
295
- # chunk_id_from_query let's use it. The chunk ID passed in comes
296
- # from the chunk_id in the "insertion" event from the previous chunk .
297
- last_event_in_chunk = events_to_create [- 1 ]
298
- chunk_id_to_connect_to = chunk_id_from_query
294
+ # Figure out which batch to connect to. If they passed in
295
+ # batch_id_from_query let's use it. The batch ID passed in comes
296
+ # from the batch_id in the "insertion" event from the previous batch .
297
+ last_event_in_batch = events_to_create [- 1 ]
298
+ batch_id_to_connect_to = batch_id_from_query
299
299
base_insertion_event = None
300
- if chunk_id_from_query :
300
+ if batch_id_from_query :
301
301
# All but the first base insertion event should point at a fake
302
302
# event, which causes the HS to ask for the state at the start of
303
- # the chunk later.
303
+ # the batch later.
304
304
prev_event_ids = [fake_prev_event_id ]
305
305
306
- # Verify the chunk_id_from_query corresponds to an actual insertion event
307
- # and have the chunk connected.
306
+ # Verify the batch_id_from_query corresponds to an actual insertion event
307
+ # and have the batch connected.
308
308
corresponding_insertion_event_id = (
309
- await self .store .get_insertion_event_by_chunk_id ( chunk_id_from_query )
309
+ await self .store .get_insertion_event_by_batch_id ( batch_id_from_query )
310
310
)
311
311
if corresponding_insertion_event_id is None :
312
312
raise SynapseError (
313
313
400 ,
314
- "No insertion event corresponds to the given ?chunk_id " ,
314
+ "No insertion event corresponds to the given ?batch_id " ,
315
315
errcode = Codes .INVALID_PARAM ,
316
316
)
317
317
pass
@@ -328,7 +328,7 @@ async def on_POST(
328
328
base_insertion_event_dict = self ._create_insertion_event_dict (
329
329
sender = requester .user .to_string (),
330
330
room_id = room_id ,
331
- origin_server_ts = last_event_in_chunk ["origin_server_ts" ],
331
+ origin_server_ts = last_event_in_batch ["origin_server_ts" ],
332
332
)
333
333
base_insertion_event_dict ["prev_events" ] = prev_event_ids .copy ()
334
334
@@ -347,38 +347,38 @@ async def on_POST(
347
347
depth = inherited_depth ,
348
348
)
349
349
350
- chunk_id_to_connect_to = base_insertion_event ["content" ][
351
- EventContentFields .MSC2716_NEXT_CHUNK_ID
350
+ batch_id_to_connect_to = base_insertion_event ["content" ][
351
+ EventContentFields .MSC2716_NEXT_BATCH_ID
352
352
]
353
353
354
- # Connect this current chunk to the insertion event from the previous chunk
355
- chunk_event = {
356
- "type" : EventTypes .MSC2716_CHUNK ,
354
+ # Connect this current batch to the insertion event from the previous batch
355
+ batch_event = {
356
+ "type" : EventTypes .MSC2716_BATCH ,
357
357
"sender" : requester .user .to_string (),
358
358
"room_id" : room_id ,
359
359
"content" : {
360
- EventContentFields .MSC2716_CHUNK_ID : chunk_id_to_connect_to ,
360
+ EventContentFields .MSC2716_BATCH_ID : batch_id_to_connect_to ,
361
361
EventContentFields .MSC2716_HISTORICAL : True ,
362
362
},
363
- # Since the chunk event is put at the end of the chunk ,
363
+ # Since the batch event is put at the end of the batch ,
364
364
# where the newest-in-time event is, copy the origin_server_ts from
365
365
# the last event we're inserting
366
- "origin_server_ts" : last_event_in_chunk ["origin_server_ts" ],
366
+ "origin_server_ts" : last_event_in_batch ["origin_server_ts" ],
367
367
}
368
- # Add the chunk event to the end of the chunk (newest-in-time)
369
- events_to_create .append (chunk_event )
368
+ # Add the batch event to the end of the batch (newest-in-time)
369
+ events_to_create .append (batch_event )
370
370
371
- # Add an "insertion" event to the start of each chunk (next to the oldest-in-time
372
- # event in the chunk ) so the next chunk can be connected to this one.
371
+ # Add an "insertion" event to the start of each batch (next to the oldest-in-time
372
+ # event in the batch ) so the next batch can be connected to this one.
373
373
insertion_event = self ._create_insertion_event_dict (
374
374
sender = requester .user .to_string (),
375
375
room_id = room_id ,
376
- # Since the insertion event is put at the start of the chunk ,
376
+ # Since the insertion event is put at the start of the batch ,
377
377
# where the oldest-in-time event is, copy the origin_server_ts from
378
378
# the first event we're inserting
379
379
origin_server_ts = events_to_create [0 ]["origin_server_ts" ],
380
380
)
381
- # Prepend the insertion event to the start of the chunk (oldest-in-time)
381
+ # Prepend the insertion event to the start of the batch (oldest-in-time)
382
382
events_to_create = [insertion_event ] + events_to_create
383
383
384
384
event_ids = []
@@ -439,17 +439,17 @@ async def on_POST(
439
439
)
440
440
441
441
insertion_event_id = event_ids [0 ]
442
- chunk_event_id = event_ids [- 1 ]
442
+ batch_event_id = event_ids [- 1 ]
443
443
historical_event_ids = event_ids [1 :- 1 ]
444
444
445
445
response_dict = {
446
446
"state_event_ids" : state_event_ids_at_start ,
447
447
"event_ids" : historical_event_ids ,
448
- "next_chunk_id " : insertion_event ["content" ][
449
- EventContentFields .MSC2716_NEXT_CHUNK_ID
448
+ "next_batch_id " : insertion_event ["content" ][
449
+ EventContentFields .MSC2716_NEXT_BATCH_ID
450
450
],
451
451
"insertion_event_id" : insertion_event_id ,
452
- "chunk_event_id " : chunk_event_id ,
452
+ "batch_event_id " : batch_event_id ,
453
453
}
454
454
if base_insertion_event is not None :
455
455
response_dict ["base_insertion_event_id" ] = base_insertion_event .event_id
0 commit comments