15
15
import logging
16
16
import re
17
17
from typing import TYPE_CHECKING , Awaitable , List , Tuple
18
+ from http import HTTPStatus
18
19
19
20
from twisted .web .server import Request
20
21
@@ -179,7 +180,7 @@ async def on_POST(
179
180
180
181
if not requester .app_service :
181
182
raise AuthError (
182
- 403 ,
183
+ HTTPStatus . FORBIDDEN ,
183
184
"Only application services can use the /batchsend endpoint" ,
184
185
)
185
186
@@ -192,7 +193,7 @@ async def on_POST(
192
193
193
194
if prev_events_from_query is None :
194
195
raise SynapseError (
195
- 400 ,
196
+ HTTPStatus . BAD_REQUEST ,
196
197
"prev_event query parameter is required when inserting historical messages back in time" ,
197
198
errcode = Codes .MISSING_PARAM ,
198
199
)
@@ -213,7 +214,7 @@ async def on_POST(
213
214
prev_state_ids = list (prev_state_map .values ())
214
215
auth_event_ids = prev_state_ids
215
216
216
- state_events_at_start = []
217
+ state_event_ids_at_start = []
217
218
for state_event in body ["state_events_at_start" ]:
218
219
assert_params_in_dict (
219
220
state_event , ["type" , "origin_server_ts" , "content" , "sender" ]
@@ -279,7 +280,7 @@ async def on_POST(
279
280
)
280
281
event_id = event .event_id
281
282
282
- state_events_at_start .append (event_id )
283
+ state_event_ids_at_start .append (event_id )
283
284
auth_event_ids .append (event_id )
284
285
285
286
events_to_create = body ["events" ]
@@ -424,20 +425,26 @@ async def on_POST(
424
425
context = context ,
425
426
)
426
427
427
- # Add the base_insertion_event to the bottom of the list we return
428
- if base_insertion_event is not None :
429
- event_ids . append ( base_insertion_event . event_id )
428
+ insertion_event_id = event_ids . pop ( 0 )
429
+ chunk_event_id = event_ids . pop ( len ( event_ids ) - 1 )
430
+ historical_event_ids = event_ids
430
431
431
- return 200 , {
432
- "state_events " : state_events_at_start ,
433
- "events " : event_ids ,
432
+ response_dict = {
433
+ "state_event_ids " : state_event_ids_at_start ,
434
+ "event_ids " : historical_event_ids ,
434
435
"next_chunk_id" : insertion_event ["content" ][
435
436
EventContentFields .MSC2716_NEXT_CHUNK_ID
436
437
],
438
+ "insertion_event_id" : insertion_event_id ,
439
+ "chunk_event_id" : chunk_event_id ,
437
440
}
441
+ if base_insertion_event is not None :
442
+ response_dict ["base_insertion_event_id" ] = base_insertion_event .event_id
443
+
444
+ return HTTPStatus .OK , response_dict
438
445
439
446
def on_GET (self , request : Request , room_id : str ) -> Tuple [int , str ]:
440
- return 501 , "Not implemented"
447
+ return HTTPStatus . NOT_IMPLEMENTED , "Not implemented"
441
448
442
449
def on_PUT (
443
450
self , request : SynapseRequest , room_id : str
0 commit comments