Fix roomlist not updating when adding space cycle

Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
Ajay Bura 2022-03-14 17:29:40 +05:30
parent af833daee4
commit 5e9b45ad5f

View file

@ -111,20 +111,21 @@ class RoomList extends EventEmitter {
addToSpaces(roomId) { addToSpaces(roomId) {
this.spaces.add(roomId); this.spaces.add(roomId);
const allParentSpaces = this.getParentSpaces(roomId);
const allParentSpaces = this.getAllParentSpaces(roomId);
const spaceChildren = this.getSpaceChildren(roomId); const spaceChildren = this.getSpaceChildren(roomId);
spaceChildren?.forEach((childRoomId) => { spaceChildren?.forEach((childId) => {
if (allParentSpaces.has(childRoomId)) return; if (allParentSpaces.has(childId)) return;
this.addToRoomIdToParents(childRoomId, roomId); this.addToRoomIdToParents(childId, roomId);
}); });
} }
deleteFromSpaces(roomId) { deleteFromSpaces(roomId) {
this.spaces.delete(roomId); this.spaces.delete(roomId);
const spaceChildren = this.getSpaceChildren(roomId); const spaceChildren = this.getSpaceChildren(roomId);
spaceChildren?.forEach((childRoomId) => { spaceChildren?.forEach((childId) => {
this.removeFromRoomIdToParents(childRoomId, roomId); this.removeFromRoomIdToParents(childId, roomId);
}); });
} }
@ -264,12 +265,17 @@ class RoomList extends EventEmitter {
this.matrixClient.on('RoomState.events', (mEvent, state) => { this.matrixClient.on('RoomState.events', (mEvent, state) => {
if (mEvent.getType() === 'm.space.child') { if (mEvent.getType() === 'm.space.child') {
const { event } = mEvent; const roomId = mEvent.event.room_id;
const childId = mEvent.event.state_key;
if (isMEventSpaceChild(mEvent)) { if (isMEventSpaceChild(mEvent)) {
const allParentSpaces = this.getParentSpaces(event.room_id); const allParentSpaces = this.getAllParentSpaces(roomId);
if (allParentSpaces.has(event.state_key)) return; // only add if it doesn't make a cycle
this.addToRoomIdToParents(event.state_key, event.room_id); if (!allParentSpaces.has(childId)) {
} else this.removeFromRoomIdToParents(event.state_key, event.room_id); this.addToRoomIdToParents(childId, roomId);
}
} else {
this.removeFromRoomIdToParents(childId, roomId);
}
this.emit(cons.events.roomList.ROOMLIST_UPDATED); this.emit(cons.events.roomList.ROOMLIST_UPDATED);
return; return;
} }