signal-desktop/ts/components/conversation/MessageRequestActionsConfirmation.tsx

287 lines
8.6 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2020 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
2020-05-27 21:37:06 +00:00
import * as React from 'react';
2024-03-12 16:29:31 +00:00
import type { ContactNameData } from './ContactName';
import { ContactName } from './ContactName';
import { ConfirmationDialog } from '../ConfirmationDialog';
2020-05-27 21:37:06 +00:00
import { Intl } from '../Intl';
import type { LocalizerType } from '../../types/Util';
2020-05-27 21:37:06 +00:00
export enum MessageRequestState {
blocking,
deleting,
unblocking,
2024-03-12 16:29:31 +00:00
reportingAndMaybeBlocking,
acceptedOptions,
2020-05-27 21:37:06 +00:00
default,
}
2024-03-12 16:29:31 +00:00
export type MessageRequestActionsConfirmationBaseProps = {
addedByName: ContactNameData | null;
2022-12-06 19:03:09 +00:00
conversationId: string;
2020-05-27 21:37:06 +00:00
conversationType: 'group' | 'direct';
2024-03-12 16:29:31 +00:00
conversationName: ContactNameData;
isBlocked: boolean;
isReported: boolean;
acceptConversation(conversationId: string): void;
blockAndReportSpam(conversationId: string): void;
blockConversation(conversationId: string): void;
reportSpam(conversationId: string): void;
deleteConversation(conversationId: string): void;
};
export type MessageRequestActionsConfirmationProps =
MessageRequestActionsConfirmationBaseProps & {
i18n: LocalizerType;
state: MessageRequestState;
onChangeState(state: MessageRequestState): void;
};
2020-05-27 21:37:06 +00:00
2022-11-18 00:45:19 +00:00
export function MessageRequestActionsConfirmation({
2024-03-12 16:29:31 +00:00
addedByName,
conversationId,
conversationType,
conversationName,
i18n,
isBlocked,
state,
2022-12-06 19:03:09 +00:00
acceptConversation,
blockAndReportSpam,
blockConversation,
2024-03-12 16:29:31 +00:00
reportSpam,
2022-12-06 19:03:09 +00:00
deleteConversation,
onChangeState,
2024-03-12 16:29:31 +00:00
}: MessageRequestActionsConfirmationProps): JSX.Element | null {
2020-05-27 21:37:06 +00:00
if (state === MessageRequestState.blocking) {
return (
<ConfirmationDialog
2024-03-12 16:29:31 +00:00
key="messageRequestActionsConfirmation.blocking"
2022-09-27 20:24:21 +00:00
dialogName="messageRequestActionsConfirmation.blocking"
2024-03-12 16:29:31 +00:00
moduleClassName="MessageRequestActionsConfirmation"
2020-05-27 21:37:06 +00:00
i18n={i18n}
onClose={() => {
onChangeState(MessageRequestState.default);
}}
title={
conversationType === 'direct' ? (
<Intl
i18n={i18n}
2023-03-30 00:03:25 +00:00
id="icu:MessageRequests--block-direct-confirm-title"
components={{
2024-03-12 16:29:31 +00:00
title: (
<ContactName
key="name"
{...conversationName}
preferFirstName
/>
),
}}
/>
) : (
<Intl
i18n={i18n}
2023-03-30 00:03:25 +00:00
id="icu:MessageRequests--block-group-confirm-title"
components={{
2024-03-12 16:29:31 +00:00
title: (
<ContactName
key="name"
{...conversationName}
preferFirstName
/>
),
}}
/>
)
2020-05-27 21:37:06 +00:00
}
actions={[
{
2023-03-30 00:03:25 +00:00
text: i18n('icu:MessageRequests--block'),
2022-12-06 19:03:09 +00:00
action: () => blockConversation(conversationId),
2020-05-27 21:37:06 +00:00
style: 'negative',
},
]}
>
{conversationType === 'direct'
2023-03-30 00:03:25 +00:00
? i18n('icu:MessageRequests--block-direct-confirm-body')
: i18n('icu:MessageRequests--block-group-confirm-body')}
</ConfirmationDialog>
2020-05-27 21:37:06 +00:00
);
}
2024-03-12 16:29:31 +00:00
if (state === MessageRequestState.reportingAndMaybeBlocking) {
return (
<ConfirmationDialog
key="messageRequestActionsConfirmation.reportingAndMaybeBlocking"
dialogName="messageRequestActionsConfirmation.reportingAndMaybeBlocking"
moduleClassName="MessageRequestActionsConfirmation"
i18n={i18n}
onClose={() => {
onChangeState(MessageRequestState.default);
}}
title={i18n('icu:MessageRequests--ReportAndMaybeBlockModal-title')}
actions={[
...(!isBlocked
? ([
{
text: i18n(
'icu:MessageRequests--ReportAndMaybeBlockModal-reportAndBlock'
),
action: () => blockAndReportSpam(conversationId),
style: 'negative',
},
] as const)
: []),
{
text: i18n('icu:MessageRequests--ReportAndMaybeBlockModal-report'),
action: () => reportSpam(conversationId),
style: 'negative',
},
]}
>
{/* eslint-disable-next-line no-nested-ternary */}
{conversationType === 'direct' ? (
i18n('icu:MessageRequests--ReportAndMaybeBlockModal-body--direct')
) : addedByName == null ? (
i18n(
'icu:MessageRequests--ReportAndMaybeBlockModal-body--group--unknown-contact'
)
) : (
<Intl
i18n={i18n}
id="icu:MessageRequests--ReportAndMaybeBlockModal-body--group"
components={{
name: <ContactName key="name" {...addedByName} preferFirstName />,
}}
/>
)}
</ConfirmationDialog>
);
}
2020-05-27 21:37:06 +00:00
if (state === MessageRequestState.unblocking) {
return (
<ConfirmationDialog
2024-03-12 16:29:31 +00:00
key="messageRequestActionsConfirmation.unblocking"
2022-09-27 20:24:21 +00:00
dialogName="messageRequestActionsConfirmation.unblocking"
2024-03-12 16:29:31 +00:00
moduleClassName="MessageRequestActionsConfirmation"
2020-05-27 21:37:06 +00:00
i18n={i18n}
onClose={() => {
onChangeState(MessageRequestState.default);
}}
title={
<Intl
i18n={i18n}
2023-03-30 00:03:25 +00:00
id="icu:MessageRequests--unblock-direct-confirm-title"
2022-11-09 03:40:23 +00:00
components={{
2024-03-12 16:29:31 +00:00
name: (
<ContactName key="name" {...conversationName} preferFirstName />
),
2022-11-09 03:40:23 +00:00
}}
2020-05-27 21:37:06 +00:00
/>
}
actions={[
{
2023-03-30 00:03:25 +00:00
text: i18n('icu:MessageRequests--unblock'),
2022-12-06 19:03:09 +00:00
action: () => acceptConversation(conversationId),
2020-05-27 21:37:06 +00:00
style: 'affirmative',
},
]}
>
{conversationType === 'direct'
2023-03-30 00:03:25 +00:00
? i18n('icu:MessageRequests--unblock-direct-confirm-body')
: i18n('icu:MessageRequests--unblock-group-confirm-body')}
</ConfirmationDialog>
2020-05-27 21:37:06 +00:00
);
}
if (state === MessageRequestState.deleting) {
return (
<ConfirmationDialog
2024-03-12 16:29:31 +00:00
key="messageRequestActionsConfirmation.deleting"
2022-09-27 20:24:21 +00:00
dialogName="messageRequestActionsConfirmation.deleting"
2024-03-12 16:29:31 +00:00
moduleClassName="MessageRequestActionsConfirmation"
2020-05-27 21:37:06 +00:00
i18n={i18n}
onClose={() => {
onChangeState(MessageRequestState.default);
}}
title={
conversationType === 'direct' ? (
<Intl
i18n={i18n}
2023-03-30 00:03:25 +00:00
id="icu:MessageRequests--delete-direct-confirm-title"
/>
) : (
<Intl
i18n={i18n}
2023-03-30 00:03:25 +00:00
id="icu:MessageRequests--delete-group-confirm-title"
components={{
2024-03-12 16:29:31 +00:00
title: (
<ContactName
key="name"
{...conversationName}
preferFirstName
/>
),
}}
/>
)
2020-05-27 21:37:06 +00:00
}
actions={[
{
text:
conversationType === 'direct'
2023-03-30 00:03:25 +00:00
? i18n('icu:MessageRequests--delete-direct')
: i18n('icu:MessageRequests--delete-group'),
2022-12-06 19:03:09 +00:00
action: () => deleteConversation(conversationId),
2020-05-27 21:37:06 +00:00
style: 'negative',
},
]}
>
{conversationType === 'direct'
2023-03-30 00:03:25 +00:00
? i18n('icu:MessageRequests--delete-direct-confirm-body')
: i18n('icu:MessageRequests--delete-group-confirm-body')}
</ConfirmationDialog>
2020-05-27 21:37:06 +00:00
);
}
2024-03-12 16:29:31 +00:00
if (state === MessageRequestState.acceptedOptions) {
return (
<ConfirmationDialog
key="messageRequestActionsConfirmation.acceptedOptions"
dialogName="messageRequestActionsConfirmation.acceptedOptions"
moduleClassName="MessageRequestActionsConfirmation"
i18n={i18n}
onClose={() => {
onChangeState(MessageRequestState.default);
}}
actions={[
{
text: i18n('icu:MessageRequests--reportAndMaybeBlock'),
action: () =>
onChangeState(MessageRequestState.reportingAndMaybeBlocking),
style: 'negative',
},
{
text: i18n('icu:MessageRequests--block'),
action: () => onChangeState(MessageRequestState.blocking),
style: 'negative',
},
]}
>
<Intl
i18n={i18n}
id="icu:MessageRequests--AcceptedOptionsModal--body"
components={{
name: (
<ContactName key="name" {...conversationName} preferFirstName />
),
}}
/>
</ConfirmationDialog>
);
}
2020-05-27 21:37:06 +00:00
return null;
2022-11-18 00:45:19 +00:00
}