summary refs log tree commit diff
path: root/synapse/api
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-09-09 13:25:22 +0100
committerMark Haines <mark.haines@matrix.org>2015-09-09 13:25:22 +0100
commit89ae0166ded093be2343409cfe42f475dea83139 (patch)
tree582d239fedd24eae7a451328c8fe1499e9dd654b /synapse/api
parentInclude rooms that a user has left in an initialSync. Include the state and m... (diff)
downloadsynapse-89ae0166ded093be2343409cfe42f475dea83139.tar.xz
Allow room initialSync for users that have left the room, returning a snapshot of how the room was when they left it
Diffstat (limited to 'synapse/api')
-rw-r--r--synapse/api/auth.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/synapse/api/auth.py b/synapse/api/auth.py
index 0c0d678562..9b614a12bb 100644
--- a/synapse/api/auth.py
+++ b/synapse/api/auth.py
@@ -104,6 +104,20 @@ class Auth(object):
 
     @defer.inlineCallbacks
     def check_joined_room(self, room_id, user_id, current_state=None):
+        """Check if the user is currently joined in the room
+        Args:
+            room_id(str): The room to check.
+            user_id(str): The user to check.
+            current_state(dict): Optional map of the current state of the room.
+                If provided then that map is used to check whether they are a
+                member of the room. Otherwise the current membership is
+                loaded from the database.
+        Raises:
+            AuthError if the user is not in the room.
+        Returns:
+            A deferred membership event for the user if the user is in
+            the room.
+        """
         if current_state:
             member = current_state.get(
                 (EventTypes.Member, user_id),
@@ -120,6 +134,41 @@ class Auth(object):
         defer.returnValue(member)
 
     @defer.inlineCallbacks
+    def check_user_was_in_room(self, room_id, user_id, current_state=None):
+        """Check if the user was in the room at some point.
+        Args:
+            room_id(str): The room to check.
+            user_id(str): The user to check.
+            current_state(dict): Optional map of the current state of the room.
+                If provided then that map is used to check whether they are a
+                member of the room. Otherwise the current membership is
+                loaded from the database.
+        Raises:
+            AuthError if the user was never in the room.
+        Returns:
+            A deferred membership event for the user if the user was in
+            the room.
+        """
+        if current_state:
+            member = current_state.get(
+                (EventTypes.Member, user_id),
+                None
+            )
+        else:
+            member = yield self.state.get_current_state(
+                room_id=room_id,
+                event_type=EventTypes.Member,
+                state_key=user_id
+            )
+
+        if not member:
+            raise AuthError(403, "User %s not in room %s" % (
+                user_id, room_id
+            ))
+
+        defer.returnValue(member)
+
+    @defer.inlineCallbacks
     def check_host_in_room(self, room_id, host):
         curr_state = yield self.state.get_current_state(room_id)