Skip to content

Commit 86d1eb8

Browse files
committed
fix: Correctly remove space child
1 parent 2a81bcf commit 86d1eb8

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

lib/src/room.dart

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2690,10 +2690,21 @@ class Room {
26902690
);
26912691
}
26922692

2693-
/// Remove a child from this space by setting the `via` to an empty list.
2694-
Future<void> removeSpaceChild(String roomId) => !isSpace
2695-
? throw Exception('Room is not a space!')
2696-
: setSpaceChild(roomId, via: const []);
2693+
/// Remove a child from this space by removing the space child and optionally
2694+
/// space parent state events.
2695+
Future<void> removeSpaceChild(String roomId) async {
2696+
if (!isSpace) throw Exception('Room is not a space!');
2697+
2698+
await client.setRoomStateWithKey(id, EventTypes.SpaceChild, roomId, {});
2699+
2700+
// Optionally remove the space parent state event in the former space child.
2701+
if (client
2702+
.getRoomById(roomId)
2703+
?.canChangeStateEvent(EventTypes.SpaceParent) ==
2704+
true) {
2705+
await client.setRoomStateWithKey(roomId, EventTypes.SpaceParent, id, {});
2706+
}
2707+
}
26972708

26982709
@override
26992710
bool operator ==(Object other) => (other is Room && other.id == id);

0 commit comments

Comments
 (0)