simon | 26e79f7 | 2022-10-05 22:16:08 -0400 | [diff] [blame] | 1 | /* |
| 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 | */ |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 18 | import { Divider, Stack, Typography } from '@mui/material'; |
simon | f9d78f2 | 2022-11-25 15:47:15 -0500 | [diff] [blame] | 19 | import { ConversationMember } from 'jami-web-common'; |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 20 | import { useContext, useMemo } from 'react'; |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 21 | import { useTranslation } from 'react-i18next'; |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 22 | |
simon | 5da8ca6 | 2022-11-09 15:21:25 -0500 | [diff] [blame] | 23 | import { useAuthContext } from '../contexts/AuthProvider'; |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 24 | import { ConversationContext } from '../contexts/ConversationProvider'; |
simon | ff1cb35 | 2022-11-24 15:15:26 -0500 | [diff] [blame] | 25 | import { useStartCall } from '../hooks/useStartCall'; |
idillon | 6847e25 | 2022-11-04 11:50:08 -0400 | [diff] [blame] | 26 | import ChatInterface from '../pages/ChatInterface'; |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 27 | import { translateEnumeration, TranslateEnumerationOptions } from '../utils/translations'; |
| 28 | import { AddParticipantButton, ShowOptionsMenuButton, StartAudioCallButton, StartVideoCallButton } from './Button'; |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 29 | |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 30 | const ConversationView = () => { |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 31 | return ( |
simon | 9f814a3 | 2022-11-22 21:40:53 -0500 | [diff] [blame] | 32 | <Stack flexGrow={1} height="100%"> |
simon | f9d78f2 | 2022-11-25 15:47:15 -0500 | [diff] [blame] | 33 | <ConversationHeader /> |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 34 | <Divider |
| 35 | sx={{ |
| 36 | borderTop: '1px solid #E5E5E5', |
| 37 | }} |
| 38 | /> |
simon | f9d78f2 | 2022-11-25 15:47:15 -0500 | [diff] [blame] | 39 | <ChatInterface /> |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 40 | </Stack> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 41 | ); |
| 42 | }; |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 43 | |
simon | f9d78f2 | 2022-11-25 15:47:15 -0500 | [diff] [blame] | 44 | const ConversationHeader = () => { |
| 45 | const { account } = useAuthContext(); |
| 46 | const { conversation } = useContext(ConversationContext); |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 47 | const { t } = useTranslation(); |
simon | ff1cb35 | 2022-11-24 15:15:26 -0500 | [diff] [blame] | 48 | const { conversationId } = useContext(ConversationContext); |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 49 | |
simon | f9d78f2 | 2022-11-25 15:47:15 -0500 | [diff] [blame] | 50 | const members = conversation.getMembers(); |
| 51 | const adminTitle = conversation.infos.title as string; |
| 52 | |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 53 | const title = useMemo(() => { |
| 54 | if (adminTitle) { |
| 55 | return adminTitle; |
| 56 | } |
| 57 | |
| 58 | const options: TranslateEnumerationOptions<ConversationMember> = { |
| 59 | elementPartialKey: 'member', |
| 60 | getElementValue: (member) => getMemberName(member), |
| 61 | translaters: [ |
| 62 | () => |
| 63 | // The user is chatting with themself |
| 64 | t('conversation_title_one', { member0: account?.getDisplayName() }), |
| 65 | (interpolations) => t('conversation_title_one', interpolations), |
| 66 | (interpolations) => t('conversation_title_two', interpolations), |
| 67 | (interpolations) => t('conversation_title_three', interpolations), |
| 68 | (interpolations) => t('conversation_title_four', interpolations), |
| 69 | (interpolations) => t('conversation_title_more', interpolations), |
| 70 | ], |
| 71 | }; |
| 72 | |
| 73 | return translateEnumeration<ConversationMember>(members, options); |
| 74 | }, [account, members, adminTitle, t]); |
| 75 | |
simon | ff1cb35 | 2022-11-24 15:15:26 -0500 | [diff] [blame] | 76 | const startCall = useStartCall(); |
| 77 | |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 78 | return ( |
idillon | 6847e25 | 2022-11-04 11:50:08 -0400 | [diff] [blame] | 79 | <Stack direction="row" padding="16px" overflow="hidden"> |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 80 | <Stack flex={1} justifyContent="center" whiteSpace="nowrap" overflow="hidden"> |
| 81 | <Typography variant="h3" textOverflow="ellipsis"> |
| 82 | {title} |
| 83 | </Typography> |
| 84 | </Stack> |
| 85 | <Stack direction="row" spacing="20px"> |
simon | ff1cb35 | 2022-11-24 15:15:26 -0500 | [diff] [blame] | 86 | <StartAudioCallButton onClick={() => startCall(conversationId)} /> |
| 87 | <StartVideoCallButton |
| 88 | onClick={() => |
| 89 | startCall(conversationId, { |
| 90 | isVideoOn: true, |
| 91 | }) |
| 92 | } |
| 93 | /> |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 94 | <AddParticipantButton /> |
| 95 | <ShowOptionsMenuButton /> |
| 96 | </Stack> |
| 97 | </Stack> |
| 98 | ); |
| 99 | }; |
| 100 | |
| 101 | const getMemberName = (member: ConversationMember) => { |
| 102 | const contact = member.contact; |
| 103 | return contact.getDisplayName(); |
| 104 | }; |
| 105 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 106 | export default ConversationView; |