2022-02-23 18:48:40 +00:00
|
|
|
// Copyright 2020-2022 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { ReactElement } from 'react';
|
|
|
|
import React, { useState } from 'react';
|
2021-08-26 20:51:55 +00:00
|
|
|
import { get } from 'lodash';
|
2020-09-09 02:25:05 +00:00
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { ReplacementValuesType } from '../../types/I18N';
|
|
|
|
import type { FullJSXType } from '../Intl';
|
|
|
|
import { Intl } from '../Intl';
|
|
|
|
import type { LocalizerType } from '../../types/Util';
|
2021-10-26 22:59:08 +00:00
|
|
|
import type { UUIDStringType } from '../../types/UUID';
|
2021-06-17 17:15:51 +00:00
|
|
|
import { GroupDescriptionText } from '../GroupDescriptionText';
|
2021-06-04 16:27:04 +00:00
|
|
|
import { Button, ButtonSize, ButtonVariant } from '../Button';
|
2021-09-07 19:55:03 +00:00
|
|
|
import { SystemMessage } from './SystemMessage';
|
2020-09-09 02:25:05 +00:00
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { GroupV2ChangeType, GroupV2ChangeDetailType } from '../../groups';
|
2020-09-09 02:25:05 +00:00
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { SmartContactRendererType } from '../../groupChange';
|
|
|
|
import { renderChange } from '../../groupChange';
|
2021-06-04 16:27:04 +00:00
|
|
|
import { Modal } from '../Modal';
|
2020-09-09 02:25:05 +00:00
|
|
|
|
|
|
|
export type PropsDataType = {
|
2021-06-04 16:27:04 +00:00
|
|
|
groupName?: string;
|
2022-02-23 18:48:40 +00:00
|
|
|
ourUuid?: UUIDStringType;
|
2020-09-09 02:25:05 +00:00
|
|
|
change: GroupV2ChangeType;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type PropsHousekeepingType = {
|
|
|
|
i18n: LocalizerType;
|
2021-12-16 17:44:54 +00:00
|
|
|
renderContact: SmartContactRendererType<FullJSXType>;
|
2020-09-09 02:25:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export type PropsType = PropsDataType & PropsHousekeepingType;
|
|
|
|
|
|
|
|
function renderStringToIntl(
|
|
|
|
id: string,
|
|
|
|
i18n: LocalizerType,
|
|
|
|
components?: Array<FullJSXType> | ReplacementValuesType<FullJSXType>
|
|
|
|
): FullJSXType {
|
|
|
|
return <Intl id={id} i18n={i18n} components={components} />;
|
|
|
|
}
|
|
|
|
|
2021-08-26 20:51:55 +00:00
|
|
|
type GroupIconType =
|
|
|
|
| 'group'
|
|
|
|
| 'group-access'
|
|
|
|
| 'group-add'
|
|
|
|
| 'group-approved'
|
|
|
|
| 'group-avatar'
|
|
|
|
| 'group-decline'
|
|
|
|
| 'group-edit'
|
|
|
|
| 'group-leave'
|
|
|
|
| 'group-remove';
|
|
|
|
|
|
|
|
const changeToIconMap = new Map<string, GroupIconType>([
|
|
|
|
['access-attributes', 'group-access'],
|
|
|
|
['access-invite-link', 'group-access'],
|
|
|
|
['access-members', 'group-access'],
|
|
|
|
['admin-approval-add-one', 'group-add'],
|
|
|
|
['admin-approval-remove-one', 'group-decline'],
|
|
|
|
['announcements-only', 'group-access'],
|
|
|
|
['avatar', 'group-avatar'],
|
|
|
|
['description', 'group-edit'],
|
|
|
|
['group-link-add', 'group-access'],
|
|
|
|
['group-link-remove', 'group-access'],
|
|
|
|
['group-link-reset', 'group-access'],
|
|
|
|
['member-add', 'group-add'],
|
|
|
|
['member-add-from-admin-approval', 'group-approved'],
|
|
|
|
['member-add-from-invite', 'group-add'],
|
|
|
|
['member-add-from-link', 'group-add'],
|
|
|
|
['member-privilege', 'group-access'],
|
|
|
|
['member-remove', 'group-remove'],
|
|
|
|
['pending-add-many', 'group-add'],
|
|
|
|
['pending-add-one', 'group-add'],
|
|
|
|
['pending-remove-many', 'group-decline'],
|
|
|
|
['pending-remove-one', 'group-decline'],
|
|
|
|
['title', 'group-edit'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
function getIcon(
|
|
|
|
detail: GroupV2ChangeDetailType,
|
2021-10-26 22:59:08 +00:00
|
|
|
fromId?: UUIDStringType
|
2021-08-26 20:51:55 +00:00
|
|
|
): GroupIconType {
|
|
|
|
const changeType = detail.type;
|
|
|
|
let possibleIcon = changeToIconMap.get(changeType);
|
2021-10-26 22:59:08 +00:00
|
|
|
const isSameId = fromId === get(detail, 'uuid', null);
|
2021-08-26 20:51:55 +00:00
|
|
|
if (isSameId) {
|
|
|
|
if (changeType === 'member-remove') {
|
|
|
|
possibleIcon = 'group-leave';
|
|
|
|
}
|
|
|
|
if (changeType === 'member-add-from-invite') {
|
|
|
|
possibleIcon = 'group-approved';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return possibleIcon || 'group';
|
|
|
|
}
|
2020-09-09 02:25:05 +00:00
|
|
|
|
2021-08-26 20:51:55 +00:00
|
|
|
function GroupV2Detail({
|
|
|
|
detail,
|
|
|
|
i18n,
|
|
|
|
fromId,
|
|
|
|
onButtonClick,
|
|
|
|
text,
|
|
|
|
}: {
|
|
|
|
detail: GroupV2ChangeDetailType;
|
|
|
|
i18n: LocalizerType;
|
2021-10-26 22:59:08 +00:00
|
|
|
fromId?: UUIDStringType;
|
2021-08-26 20:51:55 +00:00
|
|
|
onButtonClick: (x: string) => unknown;
|
|
|
|
text: FullJSXType;
|
|
|
|
}): JSX.Element {
|
|
|
|
const icon = getIcon(detail, fromId);
|
2021-06-04 16:27:04 +00:00
|
|
|
|
2021-08-26 20:51:55 +00:00
|
|
|
const newGroupDescription =
|
|
|
|
detail.type === 'description' && get(detail, 'description');
|
2021-06-04 16:27:04 +00:00
|
|
|
|
2020-09-09 02:25:05 +00:00
|
|
|
return (
|
2021-09-07 19:55:03 +00:00
|
|
|
<SystemMessage
|
|
|
|
icon={icon}
|
|
|
|
contents={text}
|
|
|
|
button={
|
|
|
|
newGroupDescription ? (
|
2021-06-04 16:27:04 +00:00
|
|
|
<Button
|
2021-08-26 20:51:55 +00:00
|
|
|
onClick={() => onButtonClick(newGroupDescription)}
|
2021-06-04 16:27:04 +00:00
|
|
|
size={ButtonSize.Small}
|
2021-08-26 20:51:55 +00:00
|
|
|
variant={ButtonVariant.SystemMessage}
|
2021-06-04 16:27:04 +00:00
|
|
|
>
|
|
|
|
{i18n('view')}
|
|
|
|
</Button>
|
2021-09-07 19:55:03 +00:00
|
|
|
) : undefined
|
|
|
|
}
|
|
|
|
/>
|
2021-08-26 20:51:55 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function GroupV2Change(props: PropsType): ReactElement {
|
2021-10-26 22:59:08 +00:00
|
|
|
const { change, groupName, i18n, ourUuid, renderContact } = props;
|
2021-08-26 20:51:55 +00:00
|
|
|
|
|
|
|
const [groupDescription, setGroupDescription] = useState<
|
|
|
|
string | undefined
|
|
|
|
>();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2021-12-16 17:44:54 +00:00
|
|
|
{renderChange<FullJSXType>(change, {
|
2021-08-26 20:51:55 +00:00
|
|
|
i18n,
|
2021-10-26 22:59:08 +00:00
|
|
|
ourUuid,
|
2021-08-26 20:51:55 +00:00
|
|
|
renderContact,
|
|
|
|
renderString: renderStringToIntl,
|
|
|
|
}).map((text: FullJSXType, index: number) => (
|
|
|
|
<GroupV2Detail
|
|
|
|
detail={change.details[index]}
|
|
|
|
fromId={change.from}
|
|
|
|
i18n={i18n}
|
|
|
|
// Difficult to find a unique key for this type
|
|
|
|
// eslint-disable-next-line react/no-array-index-key
|
|
|
|
key={index}
|
|
|
|
onButtonClick={nextGroupDescription =>
|
|
|
|
setGroupDescription(nextGroupDescription)
|
|
|
|
}
|
|
|
|
text={text}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
{groupDescription ? (
|
2021-06-04 16:27:04 +00:00
|
|
|
<Modal
|
|
|
|
hasXButton
|
|
|
|
i18n={i18n}
|
|
|
|
title={groupName}
|
2021-08-26 20:51:55 +00:00
|
|
|
onClose={() => setGroupDescription(undefined)}
|
2021-06-04 16:27:04 +00:00
|
|
|
>
|
2021-08-26 20:51:55 +00:00
|
|
|
<GroupDescriptionText text={groupDescription} />
|
2021-06-04 16:27:04 +00:00
|
|
|
</Modal>
|
|
|
|
) : null}
|
2021-08-26 20:51:55 +00:00
|
|
|
</>
|
2020-09-09 02:25:05 +00:00
|
|
|
);
|
|
|
|
}
|