summary refs log tree commit diff
path: root/synapse/rest
diff options
context:
space:
mode:
authorEric Eastwood <erice@element.io>2021-09-21 15:06:28 -0500
committerGitHub <noreply@github.com>2021-09-21 15:06:28 -0500
commit51e2db35983953b13e536331ec2f6ad4cae7e0f1 (patch)
tree823c37f186796e8cb2b5beada4fb351477481770 /synapse/rest
parentAdd type hints for event streams. (#10856) (diff)
downloadsynapse-51e2db35983953b13e536331ec2f6ad4cae7e0f1.tar.xz
Rename MSC2716 things from `chunk` to `batch` to match `/batch_send` endpoint (#10838)
See https://github.com/matrix-org/matrix-doc/pull/2716#discussion_r684574497

Dropping support for older MSC2716 room versions so we don't have to worry about
supporting both chunk and batch events.
Diffstat (limited to 'synapse/rest')
-rw-r--r--synapse/rest/client/room_batch.py86
1 files changed, 43 insertions, 43 deletions
diff --git a/synapse/rest/client/room_batch.py b/synapse/rest/client/room_batch.py
index f73ccc7f65..bf14ec384e 100644
--- a/synapse/rest/client/room_batch.py
+++ b/synapse/rest/client/room_batch.py
@@ -43,25 +43,25 @@ logger = logging.getLogger(__name__)
 
 class RoomBatchSendEventRestServlet(RestServlet):
     """
-    API endpoint which can insert a chunk of events historically back in time
+    API endpoint which can insert a batch of events historically back in time
     next to the given `prev_event`.
 
-    `chunk_id` comes from `next_chunk_id `in the response of the batch send
-    endpoint and is derived from the "insertion" events added to each chunk.
+    `batch_id` comes from `next_batch_id `in the response of the batch send
+    endpoint and is derived from the "insertion" events added to each batch.
     It's not required for the first batch send.
 
     `state_events_at_start` is used to define the historical state events
     needed to auth the events like join events. These events will float
     outside of the normal DAG as outlier's and won't be visible in the chat
-    history which also allows us to insert multiple chunks without having a bunch
-    of `@mxid joined the room` noise between each chunk.
+    history which also allows us to insert multiple batches without having a bunch
+    of `@mxid joined the room` noise between each batch.
 
-    `events` is chronological chunk/list of events you want to insert.
-    There is a reverse-chronological constraint on chunks so once you insert
+    `events` is chronological list of events you want to insert.
+    There is a reverse-chronological constraint on batches so once you insert
     some messages, you can only insert older ones after that.
-    tldr; Insert chunks from your most recent history -> oldest history.
+    tldr; Insert batches from your most recent history -> oldest history.
 
-    POST /_matrix/client/unstable/org.matrix.msc2716/rooms/<roomID>/batch_send?prev_event_id=<eventID>&chunk_id=<chunkID>
+    POST /_matrix/client/unstable/org.matrix.msc2716/rooms/<roomID>/batch_send?prev_event_id=<eventID>&batch_id=<batchID>
     {
         "events": [ ... ],
         "state_events_at_start": [ ... ]
@@ -129,7 +129,7 @@ class RoomBatchSendEventRestServlet(RestServlet):
         self, sender: str, room_id: str, origin_server_ts: int
     ) -> JsonDict:
         """Creates an event dict for an "insertion" event with the proper fields
-        and a random chunk ID.
+        and a random batch ID.
 
         Args:
             sender: The event author MXID
@@ -140,13 +140,13 @@ class RoomBatchSendEventRestServlet(RestServlet):
             The new event dictionary to insert.
         """
 
-        next_chunk_id = random_string(8)
+        next_batch_id = random_string(8)
         insertion_event = {
             "type": EventTypes.MSC2716_INSERTION,
             "sender": sender,
             "room_id": room_id,
             "content": {
-                EventContentFields.MSC2716_NEXT_CHUNK_ID: next_chunk_id,
+                EventContentFields.MSC2716_NEXT_BATCH_ID: next_batch_id,
                 EventContentFields.MSC2716_HISTORICAL: True,
             },
             "origin_server_ts": origin_server_ts,
@@ -191,7 +191,7 @@ class RoomBatchSendEventRestServlet(RestServlet):
         prev_event_ids_from_query = parse_strings_from_args(
             request.args, "prev_event_id"
         )
-        chunk_id_from_query = parse_string(request, "chunk_id")
+        batch_id_from_query = parse_string(request, "batch_id")
 
         if prev_event_ids_from_query is None:
             raise SynapseError(
@@ -291,27 +291,27 @@ class RoomBatchSendEventRestServlet(RestServlet):
             prev_event_ids_from_query
         )
 
-        # Figure out which chunk to connect to. If they passed in
-        # chunk_id_from_query let's use it. The chunk ID passed in comes
-        # from the chunk_id in the "insertion" event from the previous chunk.
-        last_event_in_chunk = events_to_create[-1]
-        chunk_id_to_connect_to = chunk_id_from_query
+        # Figure out which batch to connect to. If they passed in
+        # batch_id_from_query let's use it. The batch ID passed in comes
+        # from the batch_id in the "insertion" event from the previous batch.
+        last_event_in_batch = events_to_create[-1]
+        batch_id_to_connect_to = batch_id_from_query
         base_insertion_event = None
-        if chunk_id_from_query:
+        if batch_id_from_query:
             #  All but the first base insertion event should point at a fake
             #  event, which causes the HS to ask for the state at the start of
-            #  the chunk later.
+            #  the batch later.
             prev_event_ids = [fake_prev_event_id]
 
-            # Verify the chunk_id_from_query corresponds to an actual insertion event
-            # and have the chunk connected.
+            # Verify the batch_id_from_query corresponds to an actual insertion event
+            # and have the batch connected.
             corresponding_insertion_event_id = (
-                await self.store.get_insertion_event_by_chunk_id(chunk_id_from_query)
+                await self.store.get_insertion_event_by_batch_id(batch_id_from_query)
             )
             if corresponding_insertion_event_id is None:
                 raise SynapseError(
                     400,
-                    "No insertion event corresponds to the given ?chunk_id",
+                    "No insertion event corresponds to the given ?batch_id",
                     errcode=Codes.INVALID_PARAM,
                 )
             pass
@@ -328,7 +328,7 @@ class RoomBatchSendEventRestServlet(RestServlet):
             base_insertion_event_dict = self._create_insertion_event_dict(
                 sender=requester.user.to_string(),
                 room_id=room_id,
-                origin_server_ts=last_event_in_chunk["origin_server_ts"],
+                origin_server_ts=last_event_in_batch["origin_server_ts"],
             )
             base_insertion_event_dict["prev_events"] = prev_event_ids.copy()
 
@@ -347,38 +347,38 @@ class RoomBatchSendEventRestServlet(RestServlet):
                 depth=inherited_depth,
             )
 
-            chunk_id_to_connect_to = base_insertion_event["content"][
-                EventContentFields.MSC2716_NEXT_CHUNK_ID
+            batch_id_to_connect_to = base_insertion_event["content"][
+                EventContentFields.MSC2716_NEXT_BATCH_ID
             ]
 
-        # Connect this current chunk to the insertion event from the previous chunk
-        chunk_event = {
-            "type": EventTypes.MSC2716_CHUNK,
+        # Connect this current batch to the insertion event from the previous batch
+        batch_event = {
+            "type": EventTypes.MSC2716_BATCH,
             "sender": requester.user.to_string(),
             "room_id": room_id,
             "content": {
-                EventContentFields.MSC2716_CHUNK_ID: chunk_id_to_connect_to,
+                EventContentFields.MSC2716_BATCH_ID: batch_id_to_connect_to,
                 EventContentFields.MSC2716_HISTORICAL: True,
             },
-            # Since the chunk event is put at the end of the chunk,
+            # Since the batch event is put at the end of the batch,
             # where the newest-in-time event is, copy the origin_server_ts from
             # the last event we're inserting
-            "origin_server_ts": last_event_in_chunk["origin_server_ts"],
+            "origin_server_ts": last_event_in_batch["origin_server_ts"],
         }
-        # Add the chunk event to the end of the chunk (newest-in-time)
-        events_to_create.append(chunk_event)
+        # Add the batch event to the end of the batch (newest-in-time)
+        events_to_create.append(batch_event)
 
-        # Add an "insertion" event to the start of each chunk (next to the oldest-in-time
-        # event in the chunk) so the next chunk can be connected to this one.
+        # Add an "insertion" event to the start of each batch (next to the oldest-in-time
+        # event in the batch) so the next batch can be connected to this one.
         insertion_event = self._create_insertion_event_dict(
             sender=requester.user.to_string(),
             room_id=room_id,
-            # Since the insertion event is put at the start of the chunk,
+            # Since the insertion event is put at the start of the batch,
             # where the oldest-in-time event is, copy the origin_server_ts from
             # the first event we're inserting
             origin_server_ts=events_to_create[0]["origin_server_ts"],
         )
-        # Prepend the insertion event to the start of the chunk (oldest-in-time)
+        # Prepend the insertion event to the start of the batch (oldest-in-time)
         events_to_create = [insertion_event] + events_to_create
 
         event_ids = []
@@ -439,17 +439,17 @@ class RoomBatchSendEventRestServlet(RestServlet):
             )
 
         insertion_event_id = event_ids[0]
-        chunk_event_id = event_ids[-1]
+        batch_event_id = event_ids[-1]
         historical_event_ids = event_ids[1:-1]
 
         response_dict = {
             "state_event_ids": state_event_ids_at_start,
             "event_ids": historical_event_ids,
-            "next_chunk_id": insertion_event["content"][
-                EventContentFields.MSC2716_NEXT_CHUNK_ID
+            "next_batch_id": insertion_event["content"][
+                EventContentFields.MSC2716_NEXT_BATCH_ID
             ],
             "insertion_event_id": insertion_event_id,
-            "chunk_event_id": chunk_event_id,
+            "batch_event_id": batch_event_id,
         }
         if base_insertion_event is not None:
             response_dict["base_insertion_event_id"] = base_insertion_event.event_id