summary refs log tree commit diff
diff options
context:
space:
mode:
authorSean Quah <seanq@element.io>2021-11-18 20:01:36 +0000
committerSean Quah <seanq@element.io>2021-11-18 20:01:36 +0000
commit856656a8eeb59afc0e682f2f2f8a526e55a692e0 (patch)
treedc9a2325d3921af4103931b79f75ec11bb1f51c6
parentRevert "Convert strings in `synapse.api.constants` to enums or `Final`" (diff)
downloadsynapse-856656a8eeb59afc0e682f2f2f8a526e55a692e0.tar.xz
Leave rooms in a deterministic order
-rw-r--r--synapse/rest/admin/space.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/synapse/rest/admin/space.py b/synapse/rest/admin/space.py
index eab174d90d..c85aec2cc5 100644
--- a/synapse/rest/admin/space.py
+++ b/synapse/rest/admin/space.py
@@ -88,13 +88,15 @@ class RemoveSpaceMemberRestServlet(ResolveRoomIdMixin, RestServlet):
             descendants,
             inaccessible_room_ids,
         ) = await self._space_hierarchy_handler.get_space_descendants(space_id)
-        space_room_ids = {room_id for room_id, _ in descendants}
 
         # Determine which rooms to leave by checking join rules
-        rooms_to_check = space_room_ids.intersection(user_room_ids)
-        rooms_to_leave = set()
+        rooms_to_leave: List[str] = []
         state_filter = StateFilter.from_types([(EventTypes.JoinRules, "")])
-        for room_id in rooms_to_check:
+        for room_id, _via in descendants:
+            if room_id not in user_room_ids:
+                # The user is not in this room. There is nothing to do here.
+                continue
+
             current_state_ids = await self._store.get_filtered_current_state_ids(
                 room_id, state_filter
             )
@@ -108,12 +110,10 @@ class RemoveSpaceMemberRestServlet(ResolveRoomIdMixin, RestServlet):
                 # If it turns out that the room is actually public, then we've not
                 # actually prevented the user from joining it.
                 join_rules = None
-            if join_rules != JoinRules.PUBLIC:
-                rooms_to_leave.add(room_id)
 
-        # Always leave the space, even if it is public
-        if space_id in user_room_ids:
-            rooms_to_leave.add(space_id)
+            # Leave the room if it is not public, or it is the root space.
+            if join_rules != JoinRules.PUBLIC or room_id == space_id:
+                rooms_to_leave.append(room_id)
 
         # Now start leaving rooms
         failures: Dict[str, List[str]] = {