From 70796e2d0b712a721ee3e548ddeb848fcf6ac424 Mon Sep 17 00:00:00 2001 From: IceDBorn Date: Sat, 25 Mar 2023 03:36:08 +0200 Subject: [PATCH] Move voice channel switching logic to navigation --- src/app/organisms/navigation/Drawer.jsx | 14 ++-- src/app/organisms/navigation/Home.jsx | 66 +++++++++++-------- src/app/organisms/navigation/Navigation.jsx | 4 +- .../organisms/navigation/RoomsCategory.jsx | 23 ++++++- src/app/organisms/room/JitsiRoom.jsx | 31 +++++---- src/app/templates/client/Client.jsx | 10 ++- 6 files changed, 93 insertions(+), 55 deletions(-) diff --git a/src/app/organisms/navigation/Drawer.jsx b/src/app/organisms/navigation/Drawer.jsx index fb75ee5b..9063f195 100644 --- a/src/app/organisms/navigation/Drawer.jsx +++ b/src/app/organisms/navigation/Drawer.jsx @@ -36,7 +36,7 @@ function useSystemState() { return [systemState]; } -function Drawer() { +function Drawer({jitsiCallId}) { const [systemState] = useSystemState(); const [selectedTab] = useSelectedTab(); const [spaceId] = useSelectedSpace(); @@ -72,16 +72,16 @@ function Drawer() {
- { - selectedTab !== cons.tabs.DIRECTS - ? - : - } + {selectedTab !== cons.tabs.DIRECTS ? ( + + ) : ( + + )}
- { systemState !== null && ( + {systemState !== null && (
{systemState.status}
diff --git a/src/app/organisms/navigation/Home.jsx b/src/app/organisms/navigation/Home.jsx index 6bfa6c0d..a97b2b14 100644 --- a/src/app/organisms/navigation/Home.jsx +++ b/src/app/organisms/navigation/Home.jsx @@ -12,7 +12,7 @@ import RoomsCategory from './RoomsCategory'; import { useCategorizedSpaces } from '../../hooks/useCategorizedSpaces'; const drawerPostie = new Postie(); -function Home({ spaceId }) { +function Home({ spaceId, jitsiCallId }) { const mx = initMatrix.matrixClient; const { roomList, notifications, accountData } = initMatrix; const { spaces, rooms, directs } = roomList; @@ -68,37 +68,51 @@ function Home({ spaceId }) { return ( <> - { !isCategorized && spaceIds.length !== 0 && ( - + {!isCategorized && spaceIds.length !== 0 && ( + )} - { roomIds.length !== 0 && ( - + {roomIds.length !== 0 && ( + )} - { directIds.length !== 0 && ( - + {directIds.length !== 0 && ( + )} - { isCategorized && [...categories.keys()].sort(roomIdByAtoZ).map((catId) => { - const rms = []; - const dms = []; - categories.get(catId).forEach((id) => { - if (directs.has(id)) dms.push(id); - else rms.push(id); - }); - rms.sort(roomIdByAtoZ); - dms.sort(roomIdByActivity); - return ( - - ); - })} + {isCategorized && + [...categories.keys()].sort(roomIdByAtoZ).map((catId) => { + const rms = []; + const dms = []; + categories.get(catId).forEach((id) => { + if (directs.has(id)) dms.push(id); + else rms.push(id); + }); + rms.sort(roomIdByAtoZ); + dms.sort(roomIdByActivity); + return ( + + ); + })} ); } diff --git a/src/app/organisms/navigation/Navigation.jsx b/src/app/organisms/navigation/Navigation.jsx index 24bd1bd2..15c2d1ce 100644 --- a/src/app/organisms/navigation/Navigation.jsx +++ b/src/app/organisms/navigation/Navigation.jsx @@ -4,11 +4,11 @@ import './Navigation.scss'; import SideBar from './SideBar'; import Drawer from './Drawer'; -function Navigation() { +function Navigation({jitsiCallId}) { return (
- +
); } diff --git a/src/app/organisms/navigation/RoomsCategory.jsx b/src/app/organisms/navigation/RoomsCategory.jsx index b5666512..8d51569e 100644 --- a/src/app/organisms/navigation/RoomsCategory.jsx +++ b/src/app/organisms/navigation/RoomsCategory.jsx @@ -19,10 +19,11 @@ import ChevronBottomIC from '../../../../public/res/ic/outlined/chevron-bottom.s import ChevronRightIC from '../../../../public/res/ic/outlined/chevron-right.svg'; function RoomsCategory({ - spaceId, name, hideHeader, roomIds, drawerPostie, + spaceId, name, hideHeader, roomIds, drawerPostie, jitsiCallId }) { const { spaces, directs } = initMatrix.roomList; const [isOpen, setIsOpen] = useState(true); + const TOPIC_JITSI_CALL = 'd38dd491fefa1cfffc27f9c57f2bdb4a' const openSpaceOptions = (e) => { e.preventDefault(); @@ -45,6 +46,7 @@ function RoomsCategory({ const renderSelector = (roomId) => { const isSpace = spaces.has(roomId); const isDM = directs.has(roomId); + const mx = initMatrix.matrixClient return ( (isSpace ? selectSpace(roomId) : selectRoom(roomId))} + onClick={() => { + if (isSpace) { + selectSpace(roomId); + return; + } + + if ( + mx.getRoom(roomId).currentState.getStateEvents('m.room.topic')[0]?.getContent() + .topic === TOPIC_JITSI_CALL + ) { + if (jitsiCallId !== roomId && !confirm(`Do you want to join ${mx.getRoom(roomId).name}?`)) { + return; + } + } + + selectRoom(roomId); + }} /> ); }; @@ -87,6 +105,7 @@ RoomsCategory.propTypes = { hideHeader: PropTypes.bool, roomIds: PropTypes.arrayOf(PropTypes.string).isRequired, drawerPostie: PropTypes.shape({}).isRequired, + jitsiCallId: PropTypes.string }; export default RoomsCategory; diff --git a/src/app/organisms/room/JitsiRoom.jsx b/src/app/organisms/room/JitsiRoom.jsx index e7296aeb..ccad4a28 100644 --- a/src/app/organisms/room/JitsiRoom.jsx +++ b/src/app/organisms/room/JitsiRoom.jsx @@ -15,8 +15,7 @@ import { useSelectedSpace } from '../../hooks/useSelectedSpace'; const TOPIC_JITSI_CALL = 'd38dd491fefa1cfffc27f9c57f2bdb4a' -function JitsiRoom({ isJitsiRoom, setIsJitsiRoom }) { - const [jitsiCallId, setJitsiCallId] = useState(null); +function JitsiRoom({ isJitsiRoom, setIsJitsiRoom, jitsiCallId, setJitsiCallId }) { const [roomInfo, setRoomInfo] = useState({ roomTimeline: null, eventId: null, @@ -37,21 +36,21 @@ function JitsiRoom({ isJitsiRoom, setIsJitsiRoom }) { ?.getContent().topic; if (mx.getRoom(rId) && topic === TOPIC_JITSI_CALL && jitsiCallId !== rId) { - if (confirm('Do you want to join this call?')) { - setJitsiCallId(rId); - setRoomName(roomTimeline.roomName); - setRoomInfo({ - roomTimeline, - eventId: eId ?? null, - }); - setCounter(counter + 1); - } else if (!jitsiCallId) { - setRoomInfo({ - roomTimeline: null, - eventId: null, - }); - } + setJitsiCallId(rId); + setRoomName(roomTimeline.roomName); + setRoomInfo({ + roomTimeline, + eventId: eId ?? null, + }); + setCounter(counter + 1); } + else if (!jitsiCallId) { + setRoomInfo({ + roomTimeline: null, + eventId: null, + }); + } + setIsJitsiRoom(topic === TOPIC_JITSI_CALL); }; diff --git a/src/app/templates/client/Client.jsx b/src/app/templates/client/Client.jsx index 497c2cfa..ac588aa9 100644 --- a/src/app/templates/client/Client.jsx +++ b/src/app/templates/client/Client.jsx @@ -28,6 +28,7 @@ function Client() { const [loadingMsg, setLoadingMsg] = useState('Heating up'); const [dragCounter, setDragCounter] = useState(0); const [isJitsiRoom, setIsJitsiRoom] = useState(false); + const [jitsiCallId, setJitsiCallId] = useState(null); const classNameHidden = 'client__item-hidden'; const navWrapperRef = useRef(null); @@ -174,10 +175,15 @@ function Client() { onDrop={handleDrop} >
- +
- +