summary refs log tree commit diff
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2014-08-26 12:54:43 +0100
committerKegan Dougal <kegan@matrix.org>2014-08-26 12:54:43 +0100
commit7d79021c428594d5b5b95197f7fc259605c2ae7b (patch)
treea062415b1a89a783c1cef52afdca6bd32facc210
parentURL renaming: Room state keys now use the format /rooms/$roomid/state/$event_... (diff)
downloadsynapse-7d79021c428594d5b5b95197f7fc259605c2ae7b.tar.xz
Added servlet for /rooms/$roomid/[invite|join|leave]
Diffstat (limited to '')
-rw-r--r--synapse/rest/room.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/synapse/rest/room.py b/synapse/rest/room.py
index 2d681bd893..118208ddcf 100644
--- a/synapse/rest/room.py
+++ b/synapse/rest/room.py
@@ -366,6 +366,21 @@ class RoomTriggerBackfill(RestServlet):
         defer.returnValue((200, res))
 
 
+class RoomMembershipRestServlet(RestServlet):
+
+    def register(self, http_server):
+        # /rooms/$roomid/[invite|join|leave]
+        PATTERN = ("/rooms/(?P<room_id>[^/]*)/" +
+            "(?P<membership_action>join|invite|leave)")
+        register_txn_path(self, PATTERN, http_server)
+
+    def on_POST(self, request, room_id, membership_action):
+        return (200, "Not implemented")
+
+    def on_PUT(self, request, room_id, membership_action, txn_id):
+        return (200, "Not implemented")
+
+
 def _parse_json(request):
     try:
         content = json.loads(request.content.read())
@@ -377,6 +392,30 @@ def _parse_json(request):
         raise SynapseError(400, "Content not JSON.", errcode=Codes.NOT_JSON)
 
 
+def register_txn_path(servlet, regex_string, http_server):
+    """Registers a transaction-based path.
+
+    This registers two paths:
+        PUT regex_string/$txnid
+        POST regex_string
+
+    Args:
+        regex_string (str): The regex string to register. Must NOT have a
+        trailing $ as this string will be appended to.
+        http_server : The http_server to register paths with.
+    """
+    http_server.register_path(
+        "POST",
+        client_path_pattern(regex_string + "$"),
+        servlet.on_POST
+    )
+    http_server.register_path(
+        "PUT",
+        client_path_pattern(regex_string + "/(?P<txn_id>[^/]*)$"),
+        servlet.on_PUT
+    )
+
+
 def register_servlets(hs, http_server):
     RoomStateEventRestServlet(hs).register(http_server)
     MessageRestServlet(hs).register(http_server)
@@ -386,3 +425,4 @@ def register_servlets(hs, http_server):
     RoomMessageListRestServlet(hs).register(http_server)
     JoinRoomAliasServlet(hs).register(http_server)
     RoomTriggerBackfill(hs).register(http_server)
+    RoomMembershipRestServlet(hs).register(http_server)