// Copyright 2024 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import React, { useState } from 'react'; import classNames from 'classnames'; import type { CallHistoryGroup } from '../types/CallDisposition'; import type { LocalizerType } from '../types/I18N'; import { CallHistoryGroupPanelSection } from './conversation/conversation-details/CallHistoryGroupPanelSection'; import { PanelSection } from './conversation/conversation-details/PanelSection'; import { ConversationDetailsIcon, IconType, } from './conversation/conversation-details/ConversationDetailsIcon'; import { PanelRow } from './conversation/conversation-details/PanelRow'; import type { CallLinkRestrictions, CallLinkType } from '../types/CallLink'; import { linkCallRoute } from '../util/signalRoutes'; import { drop } from '../util/drop'; import { Avatar, AvatarSize } from './Avatar'; import { Button, ButtonSize, ButtonVariant } from './Button'; import { copyCallLink } from '../util/copyLinksWithToast'; import { getColorForCallLink } from '../util/getColorForCallLink'; import { isCallLinkAdmin } from '../types/CallLink'; import { CallLinkRestrictionsSelect } from './CallLinkRestrictionsSelect'; import { ConfirmationDialog } from './ConfirmationDialog'; import { InAnotherCallTooltip } from './conversation/InAnotherCallTooltip'; import { offsetDistanceModifier } from '../util/popperUtil'; import { Tooltip, TooltipPlacement } from './Tooltip'; function toUrlWithoutProtocol(url: URL): string { return `${url.hostname}${url.pathname}${url.search}${url.hash}`; } export type CallLinkDetailsProps = Readonly<{ callHistoryGroup: CallHistoryGroup; callLink: CallLinkType | undefined; isAnybodyInCall: boolean; isCallActiveOnServer: boolean; isInCall: boolean; isInAnotherCall: boolean; i18n: LocalizerType; onDeleteCallLink: () => void; onOpenCallLinkAddNameModal: () => void; onStartCallLinkLobby: () => void; onShareCallLinkViaSignal: () => void; onUpdateCallLinkRestrictions: (restrictions: CallLinkRestrictions) => void; }>; export function CallLinkDetails({ callHistoryGroup, callLink, i18n, isAnybodyInCall, isCallActiveOnServer, isInCall, isInAnotherCall, onDeleteCallLink, onOpenCallLinkAddNameModal, onStartCallLinkLobby, onShareCallLinkViaSignal, onUpdateCallLinkRestrictions, }: CallLinkDetailsProps): JSX.Element { const [isDeleteCallLinkModalOpen, setIsDeleteCallLinkModalOpen] = useState(false); if (!callLink) { return renderMissingCallLink({ callHistoryGroup, i18n }); } const webUrl = linkCallRoute.toWebUrl({ key: callLink.rootKey, }); const joinButton = ( ); const callLinkRestrictionsSelect = ( ); return (

{callLink.name === '' ? i18n('icu:calling__call-link-default-title') : callLink.name}

{toUrlWithoutProtocol(webUrl)}

{isInAnotherCall ? ( {joinButton} ) : ( joinButton )}
{isCallLinkAdmin(callLink) && ( } label={ callLink.name === '' ? i18n('icu:CallLinkDetails__AddCallNameLabel') : i18n('icu:CallLinkDetails__EditCallNameLabel') } onClick={onOpenCallLinkAddNameModal} /> } label={i18n('icu:CallLinkDetails__ApproveAllMembersLabel')} right={ isCallActiveOnServer ? ( {callLinkRestrictionsSelect} ) : ( callLinkRestrictionsSelect ) } /> )} } label={i18n('icu:CallLinkDetails__CopyLink')} onClick={() => { drop(copyCallLink(webUrl.toString())); }} /> } label={i18n('icu:CallLinkDetails__ShareLinkViaSignal')} onClick={onShareCallLinkViaSignal} /> {isCallLinkAdmin(callLink) && ( } label={ isCallActiveOnServer ? ( {i18n('icu:CallLinkDetails__DeleteLink')} ) : ( i18n('icu:CallLinkDetails__DeleteLink') ) } onClick={() => { setIsDeleteCallLinkModalOpen(true); }} /> )} {isDeleteCallLinkModalOpen && ( { setIsDeleteCallLinkModalOpen(false); }} > {i18n('icu:CallLinkDetails__DeleteLinkModal__Body')} )}
); } function renderMissingCallLink({ callHistoryGroup, i18n, }: Pick): JSX.Element { return (

{i18n('icu:calling__call-link-default-title')}

); }