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

167 lines
4.7 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';
import { ContactName } from './ContactName';
import { Button, ButtonVariant } from '../Button';
2024-03-12 16:29:31 +00:00
import type { MessageRequestActionsConfirmationProps } from './MessageRequestActionsConfirmation';
2020-05-27 21:37:06 +00:00
import {
MessageRequestActionsConfirmation,
MessageRequestState,
} from './MessageRequestActionsConfirmation';
import { Intl } from '../Intl';
import type { LocalizerType } from '../../types/Util';
2024-03-12 16:29:31 +00:00
import { strictAssert } from '../../util/assert';
2020-05-27 21:37:06 +00:00
export type Props = {
i18n: LocalizerType;
2024-03-12 16:29:31 +00:00
isHidden: boolean | null;
} & Omit<
MessageRequestActionsConfirmationProps,
'i18n' | 'state' | 'onChangeState'
>;
2020-05-27 21:37:06 +00:00
2022-11-18 00:45:19 +00:00
export function MessageRequestActions({
2024-03-12 16:29:31 +00:00
addedByName,
2022-12-06 19:03:09 +00:00
conversationId,
2020-05-27 21:37:06 +00:00
conversationType,
2024-03-12 16:29:31 +00:00
conversationName,
i18n,
2020-05-27 21:37:06 +00:00
isBlocked,
2024-03-12 16:29:31 +00:00
isHidden,
isReported,
acceptConversation,
blockAndReportSpam,
blockConversation,
reportSpam,
deleteConversation,
2022-11-18 00:45:19 +00:00
}: Props): JSX.Element {
2020-05-27 21:37:06 +00:00
const [mrState, setMrState] = React.useState(MessageRequestState.default);
2024-03-12 16:29:31 +00:00
const nameValue =
conversationType === 'direct' ? conversationName : addedByName;
2023-04-05 20:48:00 +00:00
let message: JSX.Element | undefined;
if (conversationType === 'direct') {
2024-03-12 16:29:31 +00:00
strictAssert(nameValue != null, 'nameValue is null');
const name = (
<strong
key="name"
className="module-message-request-actions__message__name"
>
<ContactName {...nameValue} preferFirstName />
</strong>
);
2023-04-05 20:48:00 +00:00
if (isBlocked) {
message = (
<Intl
i18n={i18n}
id="icu:MessageRequests--message-direct-blocked"
components={{ name }}
/>
);
} else if (isHidden) {
message = (
<Intl
i18n={i18n}
id="icu:MessageRequests--message-direct-hidden"
components={{ name }}
/>
);
} else {
message = (
<Intl
i18n={i18n}
id="icu:MessageRequests--message-direct"
components={{ name }}
/>
);
}
} else if (conversationType === 'group') {
if (isBlocked) {
message = (
<Intl i18n={i18n} id="icu:MessageRequests--message-group-blocked" />
);
} else {
message = <Intl i18n={i18n} id="icu:MessageRequests--message-group" />;
}
}
2020-05-27 21:37:06 +00:00
return (
<>
{mrState !== MessageRequestState.default ? (
<MessageRequestActionsConfirmation
2024-03-12 16:29:31 +00:00
addedByName={addedByName}
conversationId={conversationId}
conversationType={conversationType}
conversationName={conversationName}
i18n={i18n}
isBlocked={isBlocked}
isReported={isReported}
state={mrState}
2022-12-06 19:03:09 +00:00
acceptConversation={acceptConversation}
blockAndReportSpam={blockAndReportSpam}
blockConversation={blockConversation}
2024-03-12 16:29:31 +00:00
reportSpam={reportSpam}
2022-12-06 19:03:09 +00:00
deleteConversation={deleteConversation}
2020-05-27 21:37:06 +00:00
onChangeState={setMrState}
/>
) : null}
<div className="module-message-request-actions">
2023-04-05 20:48:00 +00:00
<p className="module-message-request-actions__message">{message}</p>
2020-05-27 21:37:06 +00:00
<div className="module-message-request-actions__buttons">
2024-03-12 16:29:31 +00:00
{!isBlocked && (
<Button
2020-05-27 21:37:06 +00:00
onClick={() => {
2024-03-12 16:29:31 +00:00
setMrState(MessageRequestState.blocking);
2020-05-27 21:37:06 +00:00
}}
2024-03-12 16:29:31 +00:00
variant={ButtonVariant.SecondaryDestructive}
2020-05-27 21:37:06 +00:00
>
2024-03-12 16:29:31 +00:00
{i18n('icu:MessageRequests--block')}
</Button>
2024-03-12 16:29:31 +00:00
)}
{(isReported || isBlocked) && (
<Button
2020-05-27 21:37:06 +00:00
onClick={() => {
2024-03-12 16:29:31 +00:00
setMrState(MessageRequestState.deleting);
2020-05-27 21:37:06 +00:00
}}
variant={ButtonVariant.SecondaryDestructive}
2020-05-27 21:37:06 +00:00
>
2024-03-12 16:29:31 +00:00
{i18n('icu:MessageRequests--delete')}
</Button>
)}
{!isReported && (
<Button
onClick={() => {
setMrState(MessageRequestState.reportingAndMaybeBlocking);
}}
variant={ButtonVariant.SecondaryDestructive}
>
{i18n('icu:MessageRequests--reportAndMaybeBlock')}
</Button>
)}
{isBlocked && (
<Button
onClick={() => {
setMrState(MessageRequestState.unblocking);
}}
variant={ButtonVariant.SecondaryAffirmative}
>
{i18n('icu:MessageRequests--unblock')}
</Button>
2020-05-27 21:37:06 +00:00
)}
{!isBlocked ? (
<Button
2022-12-06 19:03:09 +00:00
onClick={() => acceptConversation(conversationId)}
variant={ButtonVariant.SecondaryAffirmative}
2020-05-27 21:37:06 +00:00
>
2023-03-30 00:03:25 +00:00
{i18n('icu:MessageRequests--accept')}
</Button>
2020-05-27 21:37:06 +00:00
) : null}
</div>
</div>
</>
);
2022-11-18 00:45:19 +00:00
}