summary refs log tree commit diff
path: root/synapse/handlers/user_directory.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2017-05-31 15:11:36 +0100
committerErik Johnston <erik@matrix.org>2017-05-31 15:11:36 +0100
commit350622a107c356da630eba09b63ed4b6de94b198 (patch)
treebfb6628b2b4271461a2a93c23ceaa1e45322defd /synapse/handlers/user_directory.py
parentAdd comments (diff)
downloadsynapse-350622a107c356da630eba09b63ed4b6de94b198.tar.xz
Handle the server leaving a public room
Diffstat (limited to 'synapse/handlers/user_directory.py')
-rw-r--r--synapse/handlers/user_directory.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/synapse/handlers/user_directory.py b/synapse/handlers/user_directory.py
index 88b79e3325..4e491a43e6 100644
--- a/synapse/handlers/user_directory.py
+++ b/synapse/handlers/user_directory.py
@@ -132,7 +132,9 @@ class UserDirectoyHandler(object):
     def _handle_intial_room(self, room_id):
         """Called when we initially fill out user_directory one room at a time
         """
-        # TODO: Check we're still joined to room
+        is_in_room = yield self.store.get_is_host_in_room(room_id, self.server_name)
+        if not is_in_room:
+            return
 
         is_public = yield self.store.is_room_world_readable_or_publicly_joinable(room_id)
         if not is_public:
@@ -229,7 +231,22 @@ class UserDirectoyHandler(object):
                 if change is None:
                     continue
 
-                if change:
+                if not change:
+                    # Need to check if the server left the room entirely, if so
+                    # we might need to remove all the users in that room
+                    is_in_room = yield self.store.get_is_host_in_room(
+                        room_id, self.server_name,
+                    )
+                    if not is_in_room:
+                        # Fetch all the users that we marked as being in user
+                        # directory due to being in the room and then check if
+                        # need to remove those users or not
+                        user_ids = yield self.store.get_users_in_dir_due_to_room(room_id)
+                        for user_id in user_ids:
+                            yield self._handle_remove_user(room_id, user_id)
+                        return
+
+                if change:  # The user joined
                     event = yield self.store.get_event(event_id)
                     profile = ProfileInfo(
                         avatar_url=event.content.get("avatar_url"),
@@ -237,7 +254,7 @@ class UserDirectoyHandler(object):
                     )
 
                     yield self._handle_new_user(room_id, state_key, profile)
-                else:
+                else:  # The user left
                     yield self._handle_remove_user(room_id, state_key)
 
     @defer.inlineCallbacks