blob: 5f76add34f604de1eff07e4b4142c39e9afaa738 [file] [log] [blame]
simon26e79f72022-10-05 22:16:08 -04001/*
2 * Copyright (C) 2022 Savoir-faire Linux Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation; either version 3 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
13 *
14 * You should have received a copy of the GNU Affero General Public
15 * License along with this program. If not, see
16 * <https://www.gnu.org/licenses/>.
17 */
idillonae655dd2022-10-14 18:11:02 -040018import { Divider, Stack, Typography } from '@mui/material';
idillon07d31cc2022-12-06 22:40:14 -050019import { useContext } from 'react';
simon07b4eb02022-09-29 17:50:26 -040020
simone35acc22022-12-02 16:51:12 -050021import { CallManagerContext } from '../contexts/CallManagerProvider';
simon5c677962022-12-02 16:51:54 -050022import { useCallContext } from '../contexts/CallProvider';
simon09fe4822022-11-30 23:36:25 -050023import { useConversationContext } from '../contexts/ConversationProvider';
simone35acc22022-12-02 16:51:12 -050024import CallInterface from '../pages/CallInterface';
idillon6847e252022-11-04 11:50:08 -040025import ChatInterface from '../pages/ChatInterface';
idillonae655dd2022-10-14 18:11:02 -040026import { AddParticipantButton, ShowOptionsMenuButton, StartAudioCallButton, StartVideoCallButton } from './Button';
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040027
simonf929a362022-11-18 16:53:45 -050028const ConversationView = () => {
simone35acc22022-12-02 16:51:12 -050029 const { conversationId } = useConversationContext();
simon5c677962022-12-02 16:51:54 -050030 const callContext = useCallContext(true);
simone35acc22022-12-02 16:51:12 -050031 const { callData } = useContext(CallManagerContext);
32
idilloncf42c652023-01-31 18:56:17 -050033 if (callContext && callData?.conversationId === conversationId) {
simone35acc22022-12-02 16:51:12 -050034 return <CallInterface />;
35 }
36
idillonbef18a52022-09-01 01:51:40 -040037 return (
simon9f814a32022-11-22 21:40:53 -050038 <Stack flexGrow={1} height="100%">
simonf9d78f22022-11-25 15:47:15 -050039 <ConversationHeader />
idillonae655dd2022-10-14 18:11:02 -040040 <Divider
41 sx={{
42 borderTop: '1px solid #E5E5E5',
43 }}
44 />
simonf9d78f22022-11-25 15:47:15 -050045 <ChatInterface />
idillonbef18a52022-09-01 01:51:40 -040046 </Stack>
simond47ef9e2022-09-28 22:24:28 -040047 );
48};
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040049
simonf9d78f22022-11-25 15:47:15 -050050const ConversationHeader = () => {
idillon07d31cc2022-12-06 22:40:14 -050051 const { conversationId, conversationDisplayName } = useConversationContext();
simone35acc22022-12-02 16:51:12 -050052 const { startCall } = useContext(CallManagerContext);
idillonae655dd2022-10-14 18:11:02 -040053
54 return (
idillon6847e252022-11-04 11:50:08 -040055 <Stack direction="row" padding="16px" overflow="hidden">
idillonae655dd2022-10-14 18:11:02 -040056 <Stack flex={1} justifyContent="center" whiteSpace="nowrap" overflow="hidden">
57 <Typography variant="h3" textOverflow="ellipsis">
idillon07d31cc2022-12-06 22:40:14 -050058 {conversationDisplayName}
idillonae655dd2022-10-14 18:11:02 -040059 </Typography>
60 </Stack>
61 <Stack direction="row" spacing="20px">
simone35acc22022-12-02 16:51:12 -050062 <StartAudioCallButton onClick={() => startCall({ conversationId, role: 'caller' })} />
63 <StartVideoCallButton onClick={() => startCall({ conversationId, role: 'caller', withVideoOn: true })} />
idillonae655dd2022-10-14 18:11:02 -040064 <AddParticipantButton />
65 <ShowOptionsMenuButton />
66 </Stack>
67 </Stack>
68 );
69};
70
simond47ef9e2022-09-28 22:24:28 -040071export default ConversationView;