2021-04-05 17:44:13 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
2021-01-29 21:19:24 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { ReactNode } from 'react';
|
|
|
|
import React, { useState } from 'react';
|
2021-04-05 17:44:13 +00:00
|
|
|
import classNames from 'classnames';
|
2021-01-29 21:19:24 +00:00
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { LocalizerType } from '../../../types/Util';
|
2021-04-27 19:29:59 +00:00
|
|
|
import { ConfirmationDialog } from '../../ConfirmationDialog';
|
2021-04-05 17:44:13 +00:00
|
|
|
import { Tooltip, TooltipPlacement } from '../../Tooltip';
|
2021-01-29 21:19:24 +00:00
|
|
|
|
|
|
|
import { PanelRow } from './PanelRow';
|
|
|
|
import { PanelSection } from './PanelSection';
|
2021-10-20 23:46:41 +00:00
|
|
|
import { ConversationDetailsIcon, IconType } from './ConversationDetailsIcon';
|
2021-01-29 21:19:24 +00:00
|
|
|
|
|
|
|
export type Props = {
|
2021-04-05 17:44:13 +00:00
|
|
|
cannotLeaveBecauseYouAreLastAdmin: boolean;
|
2021-01-29 21:19:24 +00:00
|
|
|
conversationTitle: string;
|
2021-10-20 23:46:41 +00:00
|
|
|
i18n: LocalizerType;
|
|
|
|
isBlocked: boolean;
|
|
|
|
isGroup: boolean;
|
2021-09-01 21:08:33 +00:00
|
|
|
left: boolean;
|
2021-04-28 20:27:16 +00:00
|
|
|
onBlock: () => void;
|
|
|
|
onLeave: () => void;
|
2021-10-20 23:46:41 +00:00
|
|
|
onUnblock: () => void;
|
2021-01-29 21:19:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const ConversationDetailsActions: React.ComponentType<Props> = ({
|
2021-04-05 17:44:13 +00:00
|
|
|
cannotLeaveBecauseYouAreLastAdmin,
|
2021-01-29 21:19:24 +00:00
|
|
|
conversationTitle,
|
2021-10-20 23:46:41 +00:00
|
|
|
i18n,
|
|
|
|
isBlocked,
|
|
|
|
isGroup,
|
2021-09-01 21:08:33 +00:00
|
|
|
left,
|
2021-04-28 20:27:16 +00:00
|
|
|
onBlock,
|
|
|
|
onLeave,
|
2021-10-20 23:46:41 +00:00
|
|
|
onUnblock,
|
2021-01-29 21:19:24 +00:00
|
|
|
}) => {
|
2021-10-20 23:46:41 +00:00
|
|
|
const [confirmLeave, gLeave] = useState<boolean>(false);
|
|
|
|
const [confirmGroupBlock, gGroupBlock] = useState<boolean>(false);
|
2022-06-14 17:09:32 +00:00
|
|
|
const [confirmGroupUnblock, gGroupUnblock] = useState<boolean>(false);
|
2021-10-20 23:46:41 +00:00
|
|
|
const [confirmDirectBlock, gDirectBlock] = useState<boolean>(false);
|
|
|
|
const [confirmDirectUnblock, gDirectUnblock] = useState<boolean>(false);
|
2021-01-29 21:19:24 +00:00
|
|
|
|
2021-09-01 21:08:33 +00:00
|
|
|
let leaveGroupNode: ReactNode;
|
2021-10-20 23:46:41 +00:00
|
|
|
if (isGroup && !left) {
|
2021-04-05 17:44:13 +00:00
|
|
|
leaveGroupNode = (
|
2021-09-01 21:08:33 +00:00
|
|
|
<PanelRow
|
|
|
|
disabled={cannotLeaveBecauseYouAreLastAdmin}
|
2021-10-20 23:46:41 +00:00
|
|
|
onClick={() => gLeave(true)}
|
2021-09-01 21:08:33 +00:00
|
|
|
icon={
|
|
|
|
<ConversationDetailsIcon
|
|
|
|
ariaLabel={i18n('ConversationDetailsActions--leave-group')}
|
|
|
|
disabled={cannotLeaveBecauseYouAreLastAdmin}
|
2021-10-20 23:46:41 +00:00
|
|
|
icon={IconType.leave}
|
2021-09-01 21:08:33 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
label={
|
|
|
|
<div
|
|
|
|
className={classNames(
|
2021-10-20 23:46:41 +00:00
|
|
|
'ConversationDetails__leave-group',
|
2021-09-01 21:08:33 +00:00
|
|
|
cannotLeaveBecauseYouAreLastAdmin &&
|
2021-10-20 23:46:41 +00:00
|
|
|
'ConversationDetails__leave-group--disabled'
|
2021-09-01 21:08:33 +00:00
|
|
|
)}
|
|
|
|
>
|
|
|
|
{i18n('ConversationDetailsActions--leave-group')}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
/>
|
2021-04-05 17:44:13 +00:00
|
|
|
);
|
2021-09-01 21:08:33 +00:00
|
|
|
if (cannotLeaveBecauseYouAreLastAdmin) {
|
|
|
|
leaveGroupNode = (
|
|
|
|
<Tooltip
|
|
|
|
content={i18n(
|
|
|
|
'ConversationDetailsActions--leave-group-must-choose-new-admin'
|
|
|
|
)}
|
|
|
|
direction={TooltipPlacement.Top}
|
|
|
|
>
|
|
|
|
{leaveGroupNode}
|
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
}
|
2021-04-05 17:44:13 +00:00
|
|
|
}
|
|
|
|
|
2021-10-20 23:46:41 +00:00
|
|
|
let blockNode: ReactNode;
|
2022-06-14 17:09:32 +00:00
|
|
|
if (isGroup && !isBlocked) {
|
2021-10-20 23:46:41 +00:00
|
|
|
blockNode = (
|
|
|
|
<PanelRow
|
|
|
|
disabled={cannotLeaveBecauseYouAreLastAdmin}
|
|
|
|
onClick={() => gGroupBlock(true)}
|
|
|
|
icon={
|
|
|
|
<ConversationDetailsIcon
|
|
|
|
ariaLabel={i18n('ConversationDetailsActions--block-group')}
|
|
|
|
icon={IconType.block}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
label={
|
|
|
|
<div className="ConversationDetails__block-group">
|
|
|
|
{i18n('ConversationDetailsActions--block-group')}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
2022-06-14 17:09:32 +00:00
|
|
|
} else if (isGroup && isBlocked) {
|
|
|
|
blockNode = (
|
|
|
|
<PanelRow
|
|
|
|
onClick={() => gGroupUnblock(true)}
|
|
|
|
icon={
|
|
|
|
<ConversationDetailsIcon
|
|
|
|
ariaLabel={i18n('ConversationDetailsActions--unblock-group')}
|
|
|
|
icon={IconType.unblock}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
label={
|
|
|
|
<div className="ConversationDetails__unblock-group">
|
|
|
|
{i18n('ConversationDetailsActions--unblock-group')}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
2021-10-20 23:46:41 +00:00
|
|
|
} else {
|
|
|
|
const label = isBlocked
|
|
|
|
? i18n('MessageRequests--unblock')
|
|
|
|
: i18n('MessageRequests--block');
|
|
|
|
blockNode = (
|
|
|
|
<PanelRow
|
|
|
|
onClick={() => (isBlocked ? gDirectUnblock(true) : gDirectBlock(true))}
|
|
|
|
icon={
|
2022-06-14 17:09:32 +00:00
|
|
|
<ConversationDetailsIcon
|
|
|
|
ariaLabel={label}
|
|
|
|
icon={isBlocked ? IconType.unblock : IconType.block}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
label={
|
|
|
|
<div
|
|
|
|
className={
|
|
|
|
isBlocked
|
|
|
|
? 'ConversationDetails__unblock-group'
|
|
|
|
: 'ConversationDetails__block-group'
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{label}
|
|
|
|
</div>
|
2021-10-20 23:46:41 +00:00
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-09-10 18:18:37 +00:00
|
|
|
if (cannotLeaveBecauseYouAreLastAdmin) {
|
2021-10-20 23:46:41 +00:00
|
|
|
blockNode = (
|
2021-09-10 18:18:37 +00:00
|
|
|
<Tooltip
|
|
|
|
content={i18n(
|
|
|
|
'ConversationDetailsActions--leave-group-must-choose-new-admin'
|
|
|
|
)}
|
|
|
|
direction={TooltipPlacement.Top}
|
|
|
|
>
|
2021-10-20 23:46:41 +00:00
|
|
|
{blockNode}
|
2021-09-10 18:18:37 +00:00
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-01-29 21:19:24 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<PanelSection>
|
2021-04-05 17:44:13 +00:00
|
|
|
{leaveGroupNode}
|
2021-10-20 23:46:41 +00:00
|
|
|
{blockNode}
|
2021-01-29 21:19:24 +00:00
|
|
|
</PanelSection>
|
2021-10-20 23:46:41 +00:00
|
|
|
{confirmLeave && (
|
2021-04-27 19:29:59 +00:00
|
|
|
<ConfirmationDialog
|
2021-01-29 21:19:24 +00:00
|
|
|
actions={[
|
|
|
|
{
|
|
|
|
text: i18n(
|
|
|
|
'ConversationDetailsActions--leave-group-modal-confirm'
|
|
|
|
),
|
2021-04-28 20:27:16 +00:00
|
|
|
action: onLeave,
|
2021-01-29 21:19:24 +00:00
|
|
|
style: 'affirmative',
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
i18n={i18n}
|
2021-10-20 23:46:41 +00:00
|
|
|
onClose={() => gLeave(false)}
|
2021-01-29 21:19:24 +00:00
|
|
|
title={i18n('ConversationDetailsActions--leave-group-modal-title')}
|
|
|
|
>
|
|
|
|
{i18n('ConversationDetailsActions--leave-group-modal-content')}
|
2021-04-27 19:29:59 +00:00
|
|
|
</ConfirmationDialog>
|
2021-01-29 21:19:24 +00:00
|
|
|
)}
|
|
|
|
|
2021-10-20 23:46:41 +00:00
|
|
|
{confirmGroupBlock && (
|
2021-04-27 19:29:59 +00:00
|
|
|
<ConfirmationDialog
|
2021-01-29 21:19:24 +00:00
|
|
|
actions={[
|
|
|
|
{
|
|
|
|
text: i18n(
|
|
|
|
'ConversationDetailsActions--block-group-modal-confirm'
|
|
|
|
),
|
2021-04-28 20:27:16 +00:00
|
|
|
action: onBlock,
|
2021-01-29 21:19:24 +00:00
|
|
|
style: 'affirmative',
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
i18n={i18n}
|
2021-10-20 23:46:41 +00:00
|
|
|
onClose={() => gGroupBlock(false)}
|
2021-01-29 21:19:24 +00:00
|
|
|
title={i18n('ConversationDetailsActions--block-group-modal-title', [
|
|
|
|
conversationTitle,
|
|
|
|
])}
|
|
|
|
>
|
|
|
|
{i18n('ConversationDetailsActions--block-group-modal-content')}
|
2021-04-27 19:29:59 +00:00
|
|
|
</ConfirmationDialog>
|
2021-01-29 21:19:24 +00:00
|
|
|
)}
|
2022-06-14 17:09:32 +00:00
|
|
|
{confirmGroupUnblock && (
|
|
|
|
<ConfirmationDialog
|
|
|
|
actions={[
|
|
|
|
{
|
|
|
|
text: i18n(
|
|
|
|
'ConversationDetailsActions--unblock-group-modal-confirm'
|
|
|
|
),
|
|
|
|
action: onUnblock,
|
|
|
|
style: 'affirmative',
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
i18n={i18n}
|
|
|
|
onClose={() => gGroupUnblock(false)}
|
|
|
|
title={i18n('ConversationDetailsActions--unblock-group-modal-title', [
|
|
|
|
conversationTitle,
|
|
|
|
])}
|
|
|
|
>
|
|
|
|
{i18n('ConversationDetailsActions--unblock-group-modal-content')}
|
|
|
|
</ConfirmationDialog>
|
|
|
|
)}
|
2021-10-20 23:46:41 +00:00
|
|
|
|
|
|
|
{confirmDirectBlock && (
|
|
|
|
<ConfirmationDialog
|
|
|
|
actions={[
|
|
|
|
{
|
|
|
|
text: i18n('MessageRequests--block'),
|
|
|
|
action: onBlock,
|
|
|
|
style: 'affirmative',
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
i18n={i18n}
|
|
|
|
onClose={() => gDirectBlock(false)}
|
|
|
|
title={i18n('MessageRequests--block-direct-confirm-title', [
|
|
|
|
conversationTitle,
|
|
|
|
])}
|
|
|
|
>
|
|
|
|
{i18n('MessageRequests--block-direct-confirm-body')}
|
|
|
|
</ConfirmationDialog>
|
|
|
|
)}
|
|
|
|
{confirmDirectUnblock && (
|
|
|
|
<ConfirmationDialog
|
|
|
|
actions={[
|
|
|
|
{
|
|
|
|
text: i18n('MessageRequests--unblock'),
|
|
|
|
action: onUnblock,
|
|
|
|
style: 'affirmative',
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
i18n={i18n}
|
|
|
|
onClose={() => gDirectUnblock(false)}
|
|
|
|
title={i18n('MessageRequests--unblock-direct-confirm-title', [
|
|
|
|
conversationTitle,
|
|
|
|
])}
|
|
|
|
>
|
|
|
|
{i18n('MessageRequests--unblock-direct-confirm-body')}
|
|
|
|
</ConfirmationDialog>
|
|
|
|
)}
|
2021-01-29 21:19:24 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|