Files
cinny/src/client/event/roomList.js
T

39 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-01-26 17:03:26 +05:30
import cons from '../state/cons';
import navigation from '../state/navigation';
2022-02-27 21:10:54 +05:30
import { selectTab, selectSpace, selectRoom } from '../action/navigation';
2022-01-26 17:03:26 +05:30
function initRoomListListener(roomList) {
2022-02-27 21:10:54 +05:30
const listenRoomLeave = (roomId) => {
2022-08-20 20:51:37 +05:30
const parents = roomList.roomIdToParents.get(roomId);
if (parents) {
[...parents].forEach((pId) => {
const data = navigation.spaceToRoom.get(pId);
if (data?.roomId === roomId) {
navigation.spaceToRoom.delete(pId);
}
});
}
2022-02-27 21:10:54 +05:30
if (navigation.selectedRoomId === roomId) {
selectRoom(null);
}
if (navigation.selectedSpacePath.includes(roomId)) {
const idIndex = navigation.selectedSpacePath.indexOf(roomId);
if (idIndex === 0) selectTab(cons.tabs.HOME);
else selectSpace(navigation.selectedSpacePath[idIndex - 1]);
}
2022-08-20 20:51:37 +05:30
navigation.removeRecentRoom(roomId);
2022-02-27 21:10:54 +05:30
};
2022-01-26 17:03:26 +05:30
roomList.on(cons.events.roomList.ROOM_LEAVED, listenRoomLeave);
2022-02-27 21:10:54 +05:30
return () => {
roomList.removeListener(cons.events.roomList.ROOM_LEAVED, listenRoomLeave);
};
2022-01-26 17:03:26 +05:30
}
2022-02-27 21:10:54 +05:30
// eslint-disable-next-line import/prefer-default-export
export { initRoomListListener };