summary refs log tree commit diff
path: root/synapse/storage/roommember.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2017-02-02 15:23:45 +0000
committerErik Johnston <erik@matrix.org>2017-02-02 15:23:45 +0000
commit99fa03e8b55eee0d69f654ba61c3f31f9f6afde1 (patch)
tree5eccc1feae37e9ba87085718a6340e1d0147ad2f /synapse/storage/roommember.py
parentsets aren't JSON serializable (diff)
parentMerge pull request #1876 from matrix-org/erikj/shared_member_store (diff)
downloadsynapse-99fa03e8b55eee0d69f654ba61c3f31f9f6afde1.tar.xz
Merge branch 'develop' of github.com:matrix-org/synapse into erikj/device_list_fixes
Diffstat (limited to 'synapse/storage/roommember.py')
-rw-r--r--synapse/storage/roommember.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/synapse/storage/roommember.py b/synapse/storage/roommember.py
index ee800d074f..249217e114 100644
--- a/synapse/storage/roommember.py
+++ b/synapse/storage/roommember.py
@@ -280,6 +280,23 @@ class RoomMemberStore(SQLBaseStore):
             user_id, membership_list=[Membership.JOIN],
         )
 
+    @cachedInlineCallbacks(max_entries=50000, cache_context=True, iterable=True)
+    def get_users_who_share_room_with_user(self, user_id, cache_context):
+        """Returns the set of users who share a room with `user_id`
+        """
+        rooms = yield self.get_rooms_for_user(
+            user_id, on_invalidate=cache_context.invalidate,
+        )
+
+        user_who_share_room = set()
+        for room in rooms:
+            user_ids = yield self.get_users_in_room(
+                room.room_id, on_invalidate=cache_context.invalidate,
+            )
+            user_who_share_room.update(user_ids)
+
+        defer.returnValue(user_who_share_room)
+
     def forget(self, user_id, room_id):
         """Indicate that user_id wishes to discard history for room_id."""
         def f(txn):