0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-11-17 23:42:33 +01:00

Added servlet for /rooms/$roomid/[invite|join|leave]

This commit is contained in:
Kegan Dougal 2014-08-26 12:54:43 +01:00
parent b01aeac842
commit 7d79021c42

View file

@ -366,6 +366,21 @@ class RoomTriggerBackfill(RestServlet):
defer.returnValue((200, res)) 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): def _parse_json(request):
try: try:
content = json.loads(request.content.read()) content = json.loads(request.content.read())
@ -377,6 +392,30 @@ def _parse_json(request):
raise SynapseError(400, "Content not JSON.", errcode=Codes.NOT_JSON) 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): def register_servlets(hs, http_server):
RoomStateEventRestServlet(hs).register(http_server) RoomStateEventRestServlet(hs).register(http_server)
MessageRestServlet(hs).register(http_server) MessageRestServlet(hs).register(http_server)
@ -386,3 +425,4 @@ def register_servlets(hs, http_server):
RoomMessageListRestServlet(hs).register(http_server) RoomMessageListRestServlet(hs).register(http_server)
JoinRoomAliasServlet(hs).register(http_server) JoinRoomAliasServlet(hs).register(http_server)
RoomTriggerBackfill(hs).register(http_server) RoomTriggerBackfill(hs).register(http_server)
RoomMembershipRestServlet(hs).register(http_server)