// Copyright 2020-2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only /* eslint-disable react/no-array-index-key */ import React from 'react'; import { createPortal } from 'react-dom'; import { Avatar } from './Avatar'; import { ContactName } from './conversation/ContactName'; import { InContactsIcon } from './InContactsIcon'; import { LocalizerType } from '../types/Util'; import { sortByTitle } from '../util/sortByTitle'; import { ConversationType } from '../state/ducks/conversations'; import { isInSystemContacts } from '../util/isInSystemContacts'; type ParticipantType = ConversationType & { hasRemoteAudio?: boolean; hasRemoteVideo?: boolean; presenting?: boolean; }; export type PropsType = { readonly i18n: LocalizerType; readonly onClose: () => void; readonly ourUuid: string; readonly participants: Array; }; export const CallingParticipantsList = React.memo( ({ i18n, onClose, ourUuid, participants }: PropsType) => { const [root, setRoot] = React.useState(null); const sortedParticipants = React.useMemo>( () => sortByTitle(participants), [participants] ); React.useEffect(() => { const div = document.createElement('div'); document.body.appendChild(div); setRoot(div); return () => { document.body.removeChild(div); setRoot(null); }; }, []); const handleCancel = React.useCallback( (e: React.MouseEvent) => { if (e.target === e.currentTarget) { onClose(); } }, [onClose] ); if (!root) { return null; } return createPortal(
{!participants.length && i18n('calling__in-this-call--zero')} {participants.length === 1 && i18n('calling__in-this-call--one')} {participants.length > 1 && i18n('calling__in-this-call--many', [ String(participants.length), ])}
    {sortedParticipants.map( (participant: ParticipantType, index: number) => (
  • {participant.uuid === ourUuid ? ( {i18n('you')} ) : ( <> {isInSystemContacts(participant) ? ( {' '} ) : null} )}
    {participant.hasRemoteAudio === false ? ( ) : null} {participant.hasRemoteVideo === false ? ( ) : null} {participant.presenting ? ( ) : null}
  • ) )}
, root ); } );