2024-05-22 16:24:27 +00:00
|
|
|
// Copyright 2024 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
import React, { memo, useCallback } from 'react';
|
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
import type { CallHistoryGroup } from '../../types/CallDisposition';
|
|
|
|
import { getIntl } from '../selectors/user';
|
|
|
|
import { CallLinkDetails } from '../../components/CallLinkDetails';
|
2024-09-09 22:09:57 +00:00
|
|
|
import {
|
|
|
|
getActiveCallState,
|
|
|
|
getAdhocCallSelector,
|
|
|
|
getCallLinkSelector,
|
|
|
|
} from '../selectors/calling';
|
2024-05-22 16:24:27 +00:00
|
|
|
import { useGlobalModalActions } from '../ducks/globalModals';
|
|
|
|
import { useCallingActions } from '../ducks/calling';
|
|
|
|
import * as log from '../../logging/log';
|
|
|
|
import { strictAssert } from '../../util/assert';
|
2024-07-30 18:39:24 +00:00
|
|
|
import type { CallLinkRestrictions } from '../../types/CallLink';
|
2024-09-09 22:09:57 +00:00
|
|
|
import { isAnybodyInGroupCall } from '../ducks/callingHelpers';
|
2024-05-22 16:24:27 +00:00
|
|
|
|
|
|
|
export type SmartCallLinkDetailsProps = Readonly<{
|
|
|
|
roomId: string;
|
|
|
|
callHistoryGroup: CallHistoryGroup;
|
2024-08-06 19:29:13 +00:00
|
|
|
onClose: () => void;
|
2024-05-22 16:24:27 +00:00
|
|
|
}>;
|
|
|
|
|
|
|
|
export const SmartCallLinkDetails = memo(function SmartCallLinkDetails({
|
|
|
|
roomId,
|
|
|
|
callHistoryGroup,
|
2024-08-06 19:29:13 +00:00
|
|
|
onClose,
|
2024-05-22 16:24:27 +00:00
|
|
|
}: SmartCallLinkDetailsProps) {
|
|
|
|
const i18n = useSelector(getIntl);
|
|
|
|
const callLinkSelector = useSelector(getCallLinkSelector);
|
2024-08-06 19:29:13 +00:00
|
|
|
|
|
|
|
const { deleteCallLink, startCallLinkLobby, updateCallLinkRestrictions } =
|
2024-07-30 18:39:24 +00:00
|
|
|
useCallingActions();
|
|
|
|
const { toggleCallLinkAddNameModal, showShareCallLinkViaSignal } =
|
|
|
|
useGlobalModalActions();
|
2024-05-22 16:24:27 +00:00
|
|
|
|
|
|
|
const callLink = callLinkSelector(roomId);
|
|
|
|
|
2024-08-06 19:29:13 +00:00
|
|
|
const handleDeleteCallLink = useCallback(() => {
|
|
|
|
strictAssert(callLink != null, 'callLink not found');
|
|
|
|
deleteCallLink(callLink.roomId);
|
|
|
|
onClose();
|
|
|
|
}, [callLink, deleteCallLink, onClose]);
|
|
|
|
|
2024-07-30 18:39:24 +00:00
|
|
|
const handleOpenCallLinkAddNameModal = useCallback(() => {
|
|
|
|
toggleCallLinkAddNameModal(roomId);
|
|
|
|
}, [roomId, toggleCallLinkAddNameModal]);
|
|
|
|
|
2024-05-22 16:24:27 +00:00
|
|
|
const handleShareCallLinkViaSignal = useCallback(() => {
|
|
|
|
strictAssert(callLink != null, 'callLink not found');
|
2024-06-10 15:23:43 +00:00
|
|
|
showShareCallLinkViaSignal(callLink, i18n);
|
|
|
|
}, [callLink, i18n, showShareCallLinkViaSignal]);
|
2024-05-22 16:24:27 +00:00
|
|
|
|
|
|
|
const handleStartCallLinkLobby = useCallback(() => {
|
|
|
|
strictAssert(callLink != null, 'callLink not found');
|
|
|
|
startCallLinkLobby({ rootKey: callLink.rootKey });
|
|
|
|
}, [callLink, startCallLinkLobby]);
|
|
|
|
|
2024-07-30 18:39:24 +00:00
|
|
|
const handleUpdateCallLinkRestrictions = useCallback(
|
|
|
|
(newRestrictions: CallLinkRestrictions) => {
|
|
|
|
updateCallLinkRestrictions(roomId, newRestrictions);
|
|
|
|
},
|
|
|
|
[roomId, updateCallLinkRestrictions]
|
|
|
|
);
|
|
|
|
|
2024-09-09 22:09:57 +00:00
|
|
|
const adhocCallSelector = useSelector(getAdhocCallSelector);
|
|
|
|
const adhocCall = adhocCallSelector(roomId);
|
|
|
|
const hasActiveCall = isAnybodyInGroupCall(adhocCall?.peekInfo);
|
|
|
|
|
2024-08-26 20:48:41 +00:00
|
|
|
const activeCall = useSelector(getActiveCallState);
|
2024-09-09 22:09:57 +00:00
|
|
|
const isInAnotherCall = Boolean(
|
|
|
|
activeCall && callLink && activeCall.conversationId !== callLink.roomId
|
|
|
|
);
|
|
|
|
const isInCall = Boolean(
|
|
|
|
activeCall && callLink && activeCall.conversationId === callLink.roomId
|
2024-08-26 20:48:41 +00:00
|
|
|
);
|
|
|
|
|
2024-05-22 16:24:27 +00:00
|
|
|
if (callLink == null) {
|
|
|
|
log.error(`SmartCallLinkDetails: callLink not found for room ${roomId}`);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<CallLinkDetails
|
|
|
|
callHistoryGroup={callHistoryGroup}
|
|
|
|
callLink={callLink}
|
2024-09-09 22:09:57 +00:00
|
|
|
isAnybodyInCall={hasActiveCall}
|
|
|
|
isInCall={isInCall}
|
|
|
|
isInAnotherCall={isInAnotherCall}
|
2024-05-22 16:24:27 +00:00
|
|
|
i18n={i18n}
|
2024-08-06 19:29:13 +00:00
|
|
|
onDeleteCallLink={handleDeleteCallLink}
|
2024-07-30 18:39:24 +00:00
|
|
|
onOpenCallLinkAddNameModal={handleOpenCallLinkAddNameModal}
|
2024-05-22 16:24:27 +00:00
|
|
|
onStartCallLinkLobby={handleStartCallLinkLobby}
|
|
|
|
onShareCallLinkViaSignal={handleShareCallLinkViaSignal}
|
2024-07-30 18:39:24 +00:00
|
|
|
onUpdateCallLinkRestrictions={handleUpdateCallLinkRestrictions}
|
2024-05-22 16:24:27 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|