summary refs log tree commit diff
path: root/synapse/handlers/user_directory.py
diff options
context:
space:
mode:
authorDavid Robertson <davidr@element.io>2021-10-18 14:20:04 +0100
committerGitHub <noreply@github.com>2021-10-18 13:20:04 +0000
commit37b845dabc687b1e0d4bc84bf5933db10db641d5 (patch)
treedd2d870094c8c6c063d7e6a8e9babb46d206c5ce /synapse/handlers/user_directory.py
parentCorrectly exclude users when making a room public or private (#11075) (diff)
downloadsynapse-37b845dabc687b1e0d4bc84bf5933db10db641d5.tar.xz
Don't remove local users from dir when the leave their last room (#11103)
Diffstat (limited to 'synapse/handlers/user_directory.py')
-rw-r--r--synapse/handlers/user_directory.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/synapse/handlers/user_directory.py b/synapse/handlers/user_directory.py
index 99f23ed967..991fee7e58 100644
--- a/synapse/handlers/user_directory.py
+++ b/synapse/handlers/user_directory.py
@@ -415,16 +415,19 @@ class UserDirectoryHandler(StateDeltasHandler):
             room_id: The room ID that user left or stopped being public that
             user_id
         """
-        logger.debug("Removing user %r", user_id)
+        logger.debug("Removing user %r from room %r", user_id, room_id)
 
         # Remove user from sharing tables
         await self.store.remove_user_who_share_room(user_id, room_id)
 
-        # Are they still in any rooms? If not, remove them entirely.
-        rooms_user_is_in = await self.store.get_user_dir_rooms_user_is_in(user_id)
+        # Additionally, if they're a remote user and we're no longer joined
+        # to any rooms they're in, remove them from the user directory.
+        if not self.is_mine_id(user_id):
+            rooms_user_is_in = await self.store.get_user_dir_rooms_user_is_in(user_id)
 
-        if len(rooms_user_is_in) == 0:
-            await self.store.remove_from_user_dir(user_id)
+            if len(rooms_user_is_in) == 0:
+                logger.debug("Removing user %r from directory", user_id)
+                await self.store.remove_from_user_dir(user_id)
 
     async def _handle_possible_remote_profile_change(
         self,