Implemented /rooms/$roomid/state API.

This commit is contained in:
Kegan Dougal 2014-09-23 15:35:58 +01:00
parent e9c88ae4f4
commit 0c4ae63ad5
2 changed files with 23 additions and 6 deletions

View File

@ -232,6 +232,22 @@ class MessageHandler(BaseHandler):
# store message in db # store message in db
yield self._on_new_room_event(event, snapshot) yield self._on_new_room_event(event, snapshot)
@defer.inlineCallbacks
def get_state_events(self, user_id, room_id):
"""Retrieve all state events for a given room.
Args:
user_id(str): The user requesting state events.
room_id(str): The room ID to get all state events from.
Returns:
A list of dicts representing state events. [{}, {}, {}]
"""
yield self.auth.check_joined_room(room_id, user_id)
# TODO: This is duplicating logic from snapshot_all_rooms
current_state = yield self.store.get_current_state(room_id)
defer.returnValue([self.hs.serialize_event(c) for c in current_state])
@defer.inlineCallbacks @defer.inlineCallbacks
def snapshot_all_rooms(self, user_id=None, pagin_config=None, def snapshot_all_rooms(self, user_id=None, pagin_config=None,
feedback=False): feedback=False):

View File

@ -329,12 +329,13 @@ class RoomStateRestServlet(RestServlet):
@defer.inlineCallbacks @defer.inlineCallbacks
def on_GET(self, request, room_id): def on_GET(self, request, room_id):
user = yield self.auth.get_user_by_req(request) user = yield self.auth.get_user_by_req(request)
# TODO: Get all the current state for this room and return in the same handler = self.handlers.message_handler
# format as initial sync, that is: # Get all the current state for this room
# [ events = yield handler.get_state_events(
# { state event }, { state event } room_id=urllib.unquote(room_id),
# ] user_id=user.to_string(),
defer.returnValue((200, [])) )
defer.returnValue((200, events))
# TODO: Needs unit testing # TODO: Needs unit testing