diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py index dc786f05da..029259e33c 100644 --- a/synapse/handlers/sync.py +++ b/synapse/handlers/sync.py @@ -2149,8 +2149,8 @@ class SyncHandler: sync_result_builder: profile_fields: The list of field IDs to filter for. """ - user_ids = await self.store.get_users_who_share_room_with_user(user_id) - user_ids = {u for u in user_ids if self._is_mine_id(u)} + # Currently, limited to only local profiles, so filter remote servers out + user_ids = await self.store.get_local_users_who_share_room_with_user(user_id) if not user_ids: return diff --git a/synapse/storage/databases/main/roommember.py b/synapse/storage/databases/main/roommember.py index 736f3e4c78..a645e4f3a5 100644 --- a/synapse/storage/databases/main/roommember.py +++ b/synapse/storage/databases/main/roommember.py @@ -982,6 +982,17 @@ class RoomMemberWorkerStore(EventsWorkerStore, CacheInvalidationWorkerStore): return user_who_share_room + async def get_local_users_who_share_room_with_user(self, user_id: str) -> set[str]: + """Returns the set of local users who share a room with `user_id`""" + room_ids = await self.get_rooms_for_user(user_id) + + user_who_share_room: set[str] = set() + for room_id in room_ids: + user_ids = await self.get_local_users_in_room(room_id) + user_who_share_room.update(user_ids) + + return user_who_share_room + @cached(cache_context=True, iterable=True) async def get_mutual_rooms_between_users( self, user_ids: frozenset[str], cache_context: _CacheContext