diff options
author | Erik Johnston <erik@matrix.org> | 2014-08-26 13:38:26 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2014-08-26 13:38:26 +0100 |
commit | a664ec20e0f0940824d7f935e935dd96fda8dd25 (patch) | |
tree | 4db45725fa57bb27ee8d3d5fa27765e424b649e7 | |
parent | Merge branch 'client_server_url_rename' into develop (diff) | |
download | synapse-a664ec20e0f0940824d7f935e935dd96fda8dd25.tar.xz |
Add a do_users_share_a_room method and use that in the presence handler.
Diffstat (limited to '')
-rw-r--r-- | synapse/handlers/presence.py | 9 | ||||
-rw-r--r-- | synapse/storage/roommember.py | 21 |
2 files changed, 25 insertions, 5 deletions
diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py index c88cc18788..471dc86163 100644 --- a/synapse/handlers/presence.py +++ b/synapse/handlers/presence.py @@ -159,12 +159,11 @@ class PresenceHandler(BaseHandler): if allowed_by_subscription: defer.returnValue(True) - rm_handler = self.homeserver.get_handlers().room_member_handler - for room_id in (yield rm_handler.get_rooms_for_user(observer_user)): - if observed_user in (yield rm_handler.get_room_members(room_id)): - defer.returnValue(True) + share_room = yield self.store.do_users_share_a_room( + [observer_user, observed_user] + ) - defer.returnValue(False) + defer.returnValue(share_room) @defer.inlineCallbacks def get_state(self, target_user, auth_user): 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) |