signal-desktop/ts/state/smart/CallLinkDetails.tsx

95 lines
3.3 KiB
TypeScript
Raw Normal View History

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';
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 { strictAssert } from '../../util/assert';
2024-07-30 18:39:24 +00:00
import type { CallLinkRestrictions } from '../../types/CallLink';
import { isAnybodyInGroupCall } from '../ducks/callingHelpers';
2024-05-22 16:24:27 +00:00
export type SmartCallLinkDetailsProps = Readonly<{
roomId: string;
callHistoryGroup: CallHistoryGroup;
onClose: () => void;
2024-05-22 16:24:27 +00:00
}>;
export const SmartCallLinkDetails = memo(function SmartCallLinkDetails({
roomId,
callHistoryGroup,
onClose,
2024-05-22 16:24:27 +00:00
}: SmartCallLinkDetailsProps) {
const i18n = useSelector(getIntl);
const callLinkSelector = useSelector(getCallLinkSelector);
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);
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]
);
const adhocCallSelector = useSelector(getAdhocCallSelector);
const adhocCall = adhocCallSelector(roomId);
const hasActiveCall = isAnybodyInGroupCall(adhocCall?.peekInfo);
const activeCall = useSelector(getActiveCallState);
const isInAnotherCall = Boolean(
activeCall && callLink && activeCall.conversationId !== callLink.roomId
);
const isInCall = Boolean(
activeCall && callLink && activeCall.conversationId === callLink.roomId
);
2024-05-22 16:24:27 +00:00
return (
<CallLinkDetails
callHistoryGroup={callHistoryGroup}
callLink={callLink}
isAnybodyInCall={hasActiveCall}
isInCall={isInCall}
isInAnotherCall={isInAnotherCall}
2024-05-22 16:24:27 +00:00
i18n={i18n}
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
/>
);
});