summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Robertson <davidr@element.io>2021-10-08 16:02:33 +0100
committerDavid Robertson <davidr@element.io>2021-10-08 17:18:00 +0100
commitcf0f93860c6c8a06fb4dbe4e863160f3d3797506 (patch)
treec2a3c5181d6da638d804598785799ce4926da1f9
parentif -> elif number 1 (diff)
downloadsynapse-cf0f93860c6c8a06fb4dbe4e863160f3d3797506.tar.xz
Group together the now_false cases
Justification:

- the only way to hit the final else branch is if `change is
  MatchChange.now_false`
- if `not is_in_room`, then the `state_key` will be
  one of the `user_id in user_ids` and so we'll call
  `self._handle_remove_user` with the `state_key` and return early
- therefore the call to `_handle_remove_user` in the final else branch
  was only hit if `is_in_room`, and so it can be moved to first `else`
  branch.

Having made this change we now have three mutually exclusive
cases (now_false, now_true, no_change). Therefore I can change if->elif
for the no_change branch.
-rw-r--r--synapse/handlers/user_directory.py6
1 files changed, 2 insertions, 4 deletions
diff --git a/synapse/handlers/user_directory.py b/synapse/handlers/user_directory.py
index e0b81becbc..d62d256f29 100644
--- a/synapse/handlers/user_directory.py
+++ b/synapse/handlers/user_directory.py
@@ -321,8 +321,8 @@ class UserDirectoryHandler(StateDeltasHandler):
                 return
             else:
                 logger.debug("Server is still in room: %r", room_id)
-
-        if change is MatchChange.no_change:
+                await self._handle_remove_user(room_id, state_key)
+        elif change is MatchChange.no_change:
             # Handle any profile changes for remote users.
             # (For local users we are not forced to scan membership
             # events; instead the rest of the application calls
@@ -342,8 +342,6 @@ class UserDirectoryHandler(StateDeltasHandler):
                     state_key, event_id
                 )
             await self._track_user_joined_room(room_id, state_key)
-        else:  # The user left
-            await self._handle_remove_user(room_id, state_key)
 
     async def _upsert_directory_entry_for_remote_user(
         self, user_id: str, event_id: str