diff options
author | Mark Haines <mark.haines@matrix.org> | 2014-08-27 16:54:12 +0100 |
---|---|---|
committer | Mark Haines <mark.haines@matrix.org> | 2014-08-27 16:54:12 +0100 |
commit | 1d95e78759cc1307d15d6cc6388f52063e833355 (patch) | |
tree | 0307617989016019bfd1d41a15b22499d02091ef /synapse/rest | |
parent | add _get_room_member, fix datastore methods (diff) | |
parent | Added RestServlet for /rooms/$roomid/initialSync (diff) | |
download | synapse-1d95e78759cc1307d15d6cc6388f52063e833355.tar.xz |
Merge branch 'develop' into storage_transactions
Diffstat (limited to 'synapse/rest')
-rw-r--r-- | synapse/rest/__init__.py | 4 | ||||
-rw-r--r-- | synapse/rest/directory.py | 2 | ||||
-rw-r--r-- | synapse/rest/presence.py | 2 | ||||
-rw-r--r-- | synapse/rest/public.py | 33 | ||||
-rw-r--r-- | synapse/rest/room.py | 89 |
5 files changed, 75 insertions, 55 deletions
diff --git a/synapse/rest/__init__.py b/synapse/rest/__init__.py index 47896612ce..f33024e72a 100644 --- a/synapse/rest/__init__.py +++ b/synapse/rest/__init__.py @@ -15,8 +15,7 @@ from . import ( - room, events, register, login, profile, public, presence, initial_sync, - directory + room, events, register, login, profile, presence, initial_sync, directory ) @@ -40,7 +39,6 @@ class RestServletFactory(object): register.register_servlets(hs, client_resource) login.register_servlets(hs, client_resource) profile.register_servlets(hs, client_resource) - public.register_servlets(hs, client_resource) presence.register_servlets(hs, client_resource) initial_sync.register_servlets(hs, client_resource) directory.register_servlets(hs, client_resource) diff --git a/synapse/rest/directory.py b/synapse/rest/directory.py index be9a3f5f9f..dc347652a0 100644 --- a/synapse/rest/directory.py +++ b/synapse/rest/directory.py @@ -31,7 +31,7 @@ def register_servlets(hs, http_server): class ClientDirectoryServer(RestServlet): - PATTERN = client_path_pattern("/ds/room/(?P<room_alias>[^/]*)$") + PATTERN = client_path_pattern("/directory/room/(?P<room_alias>[^/]*)$") @defer.inlineCallbacks def on_GET(self, request, room_alias): diff --git a/synapse/rest/presence.py b/synapse/rest/presence.py index 6043848595..e013b20853 100644 --- a/synapse/rest/presence.py +++ b/synapse/rest/presence.py @@ -68,7 +68,7 @@ class PresenceStatusRestServlet(RestServlet): class PresenceListRestServlet(RestServlet): - PATTERN = client_path_pattern("/presence_list/(?P<user_id>[^/]*)") + PATTERN = client_path_pattern("/presence/list/(?P<user_id>[^/]*)") @defer.inlineCallbacks def on_GET(self, request, user_id): diff --git a/synapse/rest/public.py b/synapse/rest/public.py deleted file mode 100644 index 3430c8049f..0000000000 --- a/synapse/rest/public.py +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2014 matrix.org -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""This module contains REST servlets to do with public paths: /public""" -from twisted.internet import defer - -from base import RestServlet, client_path_pattern - - -class PublicRoomListRestServlet(RestServlet): - PATTERN = client_path_pattern("/public/rooms$") - - @defer.inlineCallbacks - def on_GET(self, request): - handler = self.handlers.room_list_handler - data = yield handler.get_public_room_list() - defer.returnValue((200, data)) - - -def register_servlets(hs, http_server): - PublicRoomListRestServlet(hs).register(http_server) diff --git a/synapse/rest/room.py b/synapse/rest/room.py index b8d5cb87fd..ebe4e24432 100644 --- a/synapse/rest/room.py +++ b/synapse/rest/room.py @@ -34,31 +34,28 @@ class RoomCreateRestServlet(RestServlet): # No PATTERN; we have custom dispatch rules here def register(self, http_server): - # /rooms OR /rooms/<roomid> - http_server.register_path("POST", - client_path_pattern("/rooms$"), - self.on_POST) - http_server.register_path("PUT", - client_path_pattern( - "/rooms/(?P<room_id>[^/]*)$"), - self.on_PUT) + PATTERN = "/createRoom" + register_txn_path(self, PATTERN, http_server) # define CORS for all of /rooms in RoomCreateRestServlet for simplicity http_server.register_path("OPTIONS", client_path_pattern("/rooms(?:/.*)?$"), self.on_OPTIONS) + # define CORS for /createRoom[/txnid] + http_server.register_path("OPTIONS", + client_path_pattern("/createRoom(?:/.*)?$"), + self.on_OPTIONS) @defer.inlineCallbacks - def on_PUT(self, request, room_id): - room_id = urllib.unquote(room_id) - auth_user = yield self.auth.get_user_by_req(request) + def on_PUT(self, request, txn_id): + try: + defer.returnValue(self.txns.get_client_transaction(request, txn_id)) + except KeyError: + pass - if not room_id: - raise SynapseError(400, "PUT must specify a room ID") + response = yield self.on_POST(request) - room_config = self.get_room_config(request) - info = yield self.make_room(room_config, auth_user, room_id) - room_config.update(info) - defer.returnValue((200, info)) + self.txns.store_client_transaction(request, txn_id, response) + defer.returnValue(response) @defer.inlineCallbacks def on_POST(self, request): @@ -268,6 +265,17 @@ class JoinRoomAliasServlet(RestServlet): # TODO: Needs unit testing +class PublicRoomListRestServlet(RestServlet): + PATTERN = client_path_pattern("/publicRooms$") + + @defer.inlineCallbacks + def on_GET(self, request): + handler = self.handlers.room_list_handler + data = yield handler.get_public_room_list() + defer.returnValue((200, data)) + + +# TODO: Needs unit testing class RoomMemberListRestServlet(RestServlet): PATTERN = client_path_pattern("/rooms/(?P<room_id>[^/]*)/members$") @@ -314,6 +322,50 @@ class RoomMessageListRestServlet(RestServlet): defer.returnValue((200, msgs)) +# TODO: Needs unit testing +class RoomStateRestServlet(RestServlet): + PATTERN = client_path_pattern("/rooms/(?P<room_id>[^/]*)/state$") + + @defer.inlineCallbacks + def on_GET(self, request, room_id): + user = yield self.auth.get_user_by_req(request) + # TODO: Get all the current state for this room and return in the same + # format as initial sync, that is: + # [ + # { state event }, { state event } + # ] + defer.returnValue((200, [])) + + +# TODO: Needs unit testing +class RoomInitialSyncRestServlet(RestServlet): + PATTERN = client_path_pattern("/rooms/(?P<room_id>[^/]*)/initialSync$") + + @defer.inlineCallbacks + def on_GET(self, request, room_id): + user = yield self.auth.get_user_by_req(request) + # TODO: Get all the initial sync data for this room and return in the + # same format as initial sync, that is: + # { + # membership: join, + # messages: [ + # chunk: [ msg events ], + # start: s_tok, + # end: e_tok + # ], + # room_id: foo, + # state: [ + # { state event } , { state event } + # ] + # } + # Probably worth keeping the keys room_id and membership for parity with + # /initialSync even though they must be joined to sync this and know the + # room ID, so clients can reuse the same code (room_id and membership + # are MANDATORY for /initialSync, so the code will expect it to be + # there) + defer.returnValue((200, {})) + + class RoomTriggerBackfill(RestServlet): PATTERN = client_path_pattern("/rooms/(?P<room_id>[^/]*)/backfill$") @@ -427,3 +479,6 @@ def register_servlets(hs, http_server): RoomTriggerBackfill(hs).register(http_server) RoomMembershipRestServlet(hs).register(http_server) RoomSendEventRestServlet(hs).register(http_server) + PublicRoomListRestServlet(hs).register(http_server) + RoomStateRestServlet(hs).register(http_server) + RoomInitialSyncRestServlet(hs).register(http_server) |