summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-09-09 14:12:24 +0100
committerMark Haines <mark.haines@matrix.org>2015-09-09 14:12:24 +0100
commit1d579df66475c342e0bf5fed338808bdbfd03c94 (patch)
tree989fae00cee39ffb9e6a75e3f29183cb0a873687 /synapse
parentAllow room initialSync for users that have left the room, returning a snapsho... (diff)
downloadsynapse-1d579df66475c342e0bf5fed338808bdbfd03c94.tar.xz
Allow rooms/{roomId}/state for a room that has been left
Diffstat (limited to 'synapse')
-rw-r--r--synapse/api/auth.py3
-rw-r--r--synapse/handlers/message.py18
2 files changed, 15 insertions, 6 deletions
diff --git a/synapse/api/auth.py b/synapse/api/auth.py
index 9b614a12bb..d8bb64a4af 100644
--- a/synapse/api/auth.py
+++ b/synapse/api/auth.py
@@ -160,8 +160,9 @@ class Auth(object):
                 event_type=EventTypes.Member,
                 state_key=user_id
             )
+        membership = member.membership if member else None
 
-        if not member:
+        if membership not in (Membership.JOIN, Membership.LEAVE):
             raise AuthError(403, "User %s not in room %s" % (
                 user_id, room_id
             ))
diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py
index fc9a234333..171e9d72ac 100644
--- a/synapse/handlers/message.py
+++ b/synapse/handlers/message.py
@@ -277,7 +277,9 @@ class MessageHandler(BaseHandler):
 
     @defer.inlineCallbacks
     def get_state_events(self, user_id, room_id):
-        """Retrieve all state events for a given room.
+        """Retrieve all state events for a given room. If the user is
+        joined to the room then return the current state. If the user has
+        left the room return the state events from when they left.
 
         Args:
             user_id(str): The user requesting state events.
@@ -285,13 +287,19 @@ class MessageHandler(BaseHandler):
         Returns:
             A list of dicts representing state events. [{}, {}, {}]
         """
-        yield self.auth.check_joined_room(room_id, user_id)
+        member_event = yield self.auth.check_user_was_in_room(room_id, user_id)
+
+        if member_event.membership == Membership.JOIN:
+            room_state = yield self.state_handler.get_current_state(room_id)
+        elif member_event.membership == Membership.LEAVE:
+            room_state = yield self.store.get_state_for_events(
+                room_id, [member_event.event_id], None
+            )
+            room_state = room_state[member_event.event_id]
 
-        # TODO: This is duplicating logic from snapshot_all_rooms
-        current_state = yield self.state_handler.get_current_state(room_id)
         now = self.clock.time_msec()
         defer.returnValue(
-            [serialize_event(c, now) for c in current_state.values()]
+            [serialize_event(c, now) for c in room_state.values()]
         )
 
     @defer.inlineCallbacks