From 86d1eb85f9323f24f14284c8699f91d93cac2e9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ku=C3=9Fowski?= Date: Sun, 19 Oct 2025 13:09:20 +0200 Subject: [PATCH] fix: Correctly remove space child --- lib/src/room.dart | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/src/room.dart b/lib/src/room.dart index 76d72a40..6de83f77 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -2690,10 +2690,21 @@ class Room { ); } - /// Remove a child from this space by setting the `via` to an empty list. - Future removeSpaceChild(String roomId) => !isSpace - ? throw Exception('Room is not a space!') - : setSpaceChild(roomId, via: const []); + /// Remove a child from this space by removing the space child and optionally + /// space parent state events. + Future removeSpaceChild(String roomId) async { + if (!isSpace) throw Exception('Room is not a space!'); + + await client.setRoomStateWithKey(id, EventTypes.SpaceChild, roomId, {}); + + // Optionally remove the space parent state event in the former space child. + if (client + .getRoomById(roomId) + ?.canChangeStateEvent(EventTypes.SpaceParent) == + true) { + await client.setRoomStateWithKey(roomId, EventTypes.SpaceParent, id, {}); + } + } @override bool operator ==(Object other) => (other is Room && other.id == id);