summary refs log tree commit diff
diff options
context:
space:
mode:
authorPatrick Cloke <patrickc@matrix.org>2023-07-11 15:34:59 -0400
committerPatrick Cloke <patrickc@matrix.org>2023-07-17 11:05:44 -0400
commitae26625694aa753c2627b80f88c0e44158b58069 (patch)
treeafa04e4e7aaa2d1da15aaf1937767e29d254fc80
parentImplement new send_{join,leave,knock} endpoints. (diff)
downloadsynapse-ae26625694aa753c2627b80f88c0e44158b58069.tar.xz
Implement new invite endpoint.
-rw-r--r--synapse/federation/federation_client.py16
-rw-r--r--synapse/federation/transport/client.py9
-rw-r--r--synapse/federation/transport/server/federation.py35
3 files changed, 60 insertions, 0 deletions
diff --git a/synapse/federation/federation_client.py b/synapse/federation/federation_client.py
index 35faf48431..b473a5c31b 100644
--- a/synapse/federation/federation_client.py
+++ b/synapse/federation/federation_client.py
@@ -1332,6 +1332,22 @@ class FederationClient(FederationBase):
         time_now = self._clock.time_msec()
 
         try:
+            return await self.transport_layer.send_invite_unstable(
+                destination=destination,
+                txn_id=pdu.event_id,
+                content={
+                    "event": pdu.get_pdu_json(time_now),
+                    "room_version": room_version.identifier,
+                    "invite_room_state": pdu.unsigned.get("invite_room_state", []),
+                },
+            )
+        except HttpResponseException as e:
+            # If an error is received that is due to an unrecognised endpoint,
+            # fallback to the v2.
+            if not is_unknown_endpoint(e):
+                raise
+
+        try:
             return await self.transport_layer.send_invite_v2(
                 destination=destination,
                 room_id=pdu.room_id,
diff --git a/synapse/federation/transport/client.py b/synapse/federation/transport/client.py
index 527d89d996..24a8cfec3e 100644
--- a/synapse/federation/transport/client.py
+++ b/synapse/federation/transport/client.py
@@ -564,6 +564,15 @@ class TransportLayerClient:
             destination=destination, path=path, data=content, ignore_backoff=True
         )
 
+    async def send_invite_unstable(
+        self, destination: str, txn_id: str, content: JsonDict
+    ) -> JsonDict:
+        path = f"/_matrix/federation/unstable/org.matrix.i-d.ralston-mimi-linearized-matrix.02/invite/{txn_id}"
+
+        return await self.client.post_json(
+            destination=destination, path=path, data=content, ignore_backoff=True
+        )
+
     async def get_public_rooms(
         self,
         remote_server: str,
diff --git a/synapse/federation/transport/server/federation.py b/synapse/federation/transport/server/federation.py
index ee201c5c30..7ecde60f70 100644
--- a/synapse/federation/transport/server/federation.py
+++ b/synapse/federation/transport/server/federation.py
@@ -651,6 +651,40 @@ class FederationV2InviteServlet(BaseFederationServerServlet):
         return 200, result
 
 
+class FederationUnstableInviteServlet(BaseFederationServerServlet):
+    PREFIX = FEDERATION_UNSTABLE_PREFIX + "/org.matrix.i-d.ralston-mimi-linearized-matrix.02"
+    PATH = "/invite/(?P<txn_id>[^/]*)"
+    CATEGORY = "Federation requests"
+
+    async def on_POST(
+        self,
+        origin: str,
+        content: JsonDict,
+        query: Dict[bytes, List[bytes]],
+        txn_id: str,
+    ) -> Tuple[int, JsonDict]:
+        # TODO Use the txn_id for idempotency.
+
+        room_version = content["room_version"]
+        event = content["event"]
+        invite_room_state = content.get("invite_room_state", [])
+
+        # Synapse expects invite_room_state to be in unsigned, as it is in v1
+        # API
+
+        event.setdefault("unsigned", {})["invite_room_state"] = invite_room_state
+
+        result = await self.handler.on_invite_request(
+            origin, event, room_version_id=room_version
+        )
+
+        # We only store invite_room_state for internal use, so remove it before
+        # returning the event to the remote homeserver.
+        result["event"].get("unsigned", {}).pop("invite_room_state", None)
+
+        return 200, result
+
+
 class FederationThirdPartyInviteExchangeServlet(BaseFederationServerServlet):
     PATH = "/exchange_third_party_invite/(?P<room_id>[^/]*)"
     CATEGORY = "Federation requests"
@@ -952,6 +986,7 @@ FEDERATION_SERVLET_CLASSES: Tuple[Type[BaseFederationServlet], ...] = (
     # TODO(LM) Linearized Matrix additions.
     FederationUnstableEventServlet,
     FederationUnstableBackfillServlet,
+    FederationUnstableInviteServlet,
     FederationUnstableSendJoinServlet,
     FederationUnstableSendLeaveServlet,
     FederationUnstableSendKnockServlet,