summary refs log tree commit diff
path: root/synapse/storage/roommember.py
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2014-08-26 14:59:54 +0100
committerKegan Dougal <kegan@matrix.org>2014-08-26 14:59:54 +0100
commit27979028b2d7bb248c7e70d09ab0f79b708f8e5a (patch)
treed7943508bd16f2c4e2d81590ad1edcc1ff1d4d5c /synapse/storage/roommember.py
parentwebclient: Updated to use /rooms/$roomid/[invite|join|leave] (diff)
parentAdd the ability to turn on the twisted manhole telnet service. (diff)
downloadsynapse-27979028b2d7bb248c7e70d09ab0f79b708f8e5a.tar.xz
Merge branch 'develop' of github.com:matrix-org/synapse into client_server_url_rename
Diffstat (limited to 'synapse/storage/roommember.py')
-rw-r--r--synapse/storage/roommember.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/synapse/storage/roommember.py b/synapse/storage/roommember.py
index a9a09e1425..86519b60c6 100644
--- a/synapse/storage/roommember.py
+++ b/synapse/storage/roommember.py
@@ -150,3 +150,24 @@ class RoomMemberStore(SQLBaseStore):
 
         results = [self._parse_event_from_row(r) for r in rows]
         defer.returnValue(results)
+
+    @defer.inlineCallbacks
+    def do_users_share_a_room(self, user_list):
+        """ Checks whether a list of users share a room.
+        """
+        user_list_clause = " OR ".join(["m.user_id = ?"] * len(user_list))
+        sql = (
+            "SELECT m.room_id FROM room_memberships as m "
+            "INNER JOIN current_state_events as c "
+            "ON m.event_id = c.event_id "
+            "WHERE m.membership = 'join' "
+            "AND (%(clause)s) "
+            "GROUP BY m.room_id HAVING COUNT(m.room_id) = ?"
+        ) % {"clause": user_list_clause}
+
+        args = user_list
+        args.append(len(user_list))
+
+        rows = yield self._execute(None, sql, *args)
+
+        defer.returnValue(len(rows) > 0)