2022-08-16 23:59:11 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2024-03-19 17:12:32 +00:00
|
|
|
import React, { memo, useCallback } from 'react';
|
2022-08-16 23:59:11 +00:00
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
import * as SingleServePromise from '../../services/singleServePromise';
|
2024-03-19 17:12:32 +00:00
|
|
|
import type { SafetyNumberProps } from '../../components/SafetyNumberChangeDialog';
|
2022-08-16 23:59:11 +00:00
|
|
|
import {
|
|
|
|
SafetyNumberChangeDialog,
|
|
|
|
SafetyNumberChangeSource,
|
|
|
|
} from '../../components/SafetyNumberChangeDialog';
|
|
|
|
import { SmartSafetyNumberViewer } from './SafetyNumberViewer';
|
2022-11-11 04:10:30 +00:00
|
|
|
import { getByDistributionListConversationsStoppingSend } from '../selectors/conversations-extra';
|
2022-08-16 23:59:11 +00:00
|
|
|
import { getIntl, getTheme } from '../selectors/user';
|
|
|
|
import { getPreferredBadgeSelector } from '../selectors/badges';
|
|
|
|
import { useConversationsActions } from '../ducks/conversations';
|
|
|
|
import { useGlobalModalActions } from '../ducks/globalModals';
|
2022-11-11 04:10:30 +00:00
|
|
|
import { useStoryDistributionListsActions } from '../ducks/storyDistributionLists';
|
2024-03-13 20:44:13 +00:00
|
|
|
import { getSafetyNumberChangedBlockingData } from '../selectors/globalModals';
|
2022-08-16 23:59:11 +00:00
|
|
|
|
2024-03-19 17:12:32 +00:00
|
|
|
function renderSafetyNumber({ contactID, onClose }: SafetyNumberProps) {
|
|
|
|
return <SmartSafetyNumberViewer contactID={contactID} onClose={onClose} />;
|
|
|
|
}
|
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
export const SmartSendAnywayDialog = memo(
|
|
|
|
function SmartSendAnywayDialog(): JSX.Element {
|
|
|
|
const { hideBlockingSafetyNumberChangeDialog } = useGlobalModalActions();
|
|
|
|
const { removeMembersFromDistributionList } =
|
|
|
|
useStoryDistributionListsActions();
|
|
|
|
const { cancelConversationVerification, verifyConversationsStoppingSend } =
|
|
|
|
useConversationsActions();
|
|
|
|
const getPreferredBadge = useSelector(getPreferredBadgeSelector);
|
|
|
|
const i18n = useSelector(getIntl);
|
|
|
|
const theme = useSelector(getTheme);
|
2022-08-16 23:59:11 +00:00
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
const contacts = useSelector(
|
|
|
|
getByDistributionListConversationsStoppingSend
|
|
|
|
);
|
2022-08-16 23:59:11 +00:00
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
const safetyNumberChangedBlockingData = useSelector(
|
|
|
|
getSafetyNumberChangedBlockingData
|
|
|
|
);
|
2022-08-16 23:59:11 +00:00
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
const explodedPromise = safetyNumberChangedBlockingData
|
|
|
|
? SingleServePromise.get<boolean>(
|
|
|
|
safetyNumberChangedBlockingData.promiseUuid
|
|
|
|
)
|
|
|
|
: undefined;
|
2022-08-16 23:59:11 +00:00
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
let confirmText: string | undefined = i18n(
|
|
|
|
'icu:safetyNumberChangeDialog__pending-messages'
|
|
|
|
);
|
|
|
|
if (
|
|
|
|
safetyNumberChangedBlockingData?.source ===
|
|
|
|
SafetyNumberChangeSource.InitiateCall
|
|
|
|
) {
|
|
|
|
confirmText = i18n('icu:callAnyway');
|
|
|
|
} else if (
|
|
|
|
safetyNumberChangedBlockingData?.source ===
|
|
|
|
SafetyNumberChangeSource.JoinCall
|
|
|
|
) {
|
|
|
|
confirmText = i18n('icu:joinAnyway');
|
|
|
|
} else {
|
|
|
|
confirmText = undefined;
|
|
|
|
}
|
2022-08-16 23:59:11 +00:00
|
|
|
|
2024-03-19 17:12:32 +00:00
|
|
|
const handleCancel = useCallback(() => {
|
|
|
|
cancelConversationVerification();
|
|
|
|
explodedPromise?.resolve(false);
|
|
|
|
hideBlockingSafetyNumberChangeDialog();
|
|
|
|
}, [
|
|
|
|
cancelConversationVerification,
|
|
|
|
explodedPromise,
|
|
|
|
hideBlockingSafetyNumberChangeDialog,
|
|
|
|
]);
|
|
|
|
|
|
|
|
const handleConfirm = useCallback(() => {
|
|
|
|
verifyConversationsStoppingSend();
|
|
|
|
explodedPromise?.resolve(true);
|
|
|
|
hideBlockingSafetyNumberChangeDialog();
|
|
|
|
}, [
|
|
|
|
verifyConversationsStoppingSend,
|
|
|
|
explodedPromise,
|
|
|
|
hideBlockingSafetyNumberChangeDialog,
|
|
|
|
]);
|
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
return (
|
|
|
|
<SafetyNumberChangeDialog
|
|
|
|
confirmText={confirmText}
|
|
|
|
contacts={contacts}
|
|
|
|
getPreferredBadge={getPreferredBadge}
|
|
|
|
i18n={i18n}
|
2024-03-19 17:12:32 +00:00
|
|
|
onCancel={handleCancel}
|
|
|
|
onConfirm={handleConfirm}
|
2024-03-13 20:44:13 +00:00
|
|
|
removeFromStory={removeMembersFromDistributionList}
|
2024-03-19 17:12:32 +00:00
|
|
|
renderSafetyNumber={renderSafetyNumber}
|
2024-03-13 20:44:13 +00:00
|
|
|
theme={theme}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|