2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2019 Signal Messenger, LLC
|
2020-11-20 17:30:45 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import * as React from 'react';
|
2021-11-20 15:41:21 +00:00
|
|
|
import type { LocalizerType, ThemeType } from '../types/Util';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { ConversationType } from '../state/ducks/conversations';
|
2021-11-20 15:41:21 +00:00
|
|
|
import type { PreferredBadgeSelectorType } from '../state/selectors/badges';
|
2021-03-03 20:09:58 +00:00
|
|
|
import { GroupDialog } from './GroupDialog';
|
2020-12-03 17:24:44 +00:00
|
|
|
import { sortByTitle } from '../util/sortByTitle';
|
2023-04-03 20:16:27 +00:00
|
|
|
import { missingCaseError } from '../util/missingCaseError';
|
2020-11-20 17:30:45 +00:00
|
|
|
|
|
|
|
export type DataPropsType = {
|
2022-12-08 06:41:37 +00:00
|
|
|
conversationId: string;
|
2020-12-01 23:45:39 +00:00
|
|
|
readonly areWeInvited: boolean;
|
2020-11-20 17:30:45 +00:00
|
|
|
readonly droppedMembers: Array<ConversationType>;
|
|
|
|
readonly hasMigrated: boolean;
|
|
|
|
readonly invitedMembers: Array<ConversationType>;
|
2021-11-20 15:41:21 +00:00
|
|
|
readonly getPreferredBadge: PreferredBadgeSelectorType;
|
2020-11-20 17:30:45 +00:00
|
|
|
readonly i18n: LocalizerType;
|
2021-11-20 15:41:21 +00:00
|
|
|
readonly theme: ThemeType;
|
2020-11-20 17:30:45 +00:00
|
|
|
};
|
|
|
|
|
2022-12-08 06:41:37 +00:00
|
|
|
type ActionsPropsType =
|
|
|
|
| {
|
|
|
|
initiateMigrationToGroupV2: (conversationId: string) => unknown;
|
|
|
|
closeGV2MigrationDialog: () => unknown;
|
|
|
|
}
|
|
|
|
| {
|
|
|
|
readonly migrate: () => unknown;
|
|
|
|
readonly onClose: () => unknown;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type PropsType = DataPropsType & ActionsPropsType;
|
2020-11-20 17:30:45 +00:00
|
|
|
|
2021-11-11 22:43:05 +00:00
|
|
|
export const GroupV1MigrationDialog: React.FunctionComponent<PropsType> =
|
2022-11-18 00:45:19 +00:00
|
|
|
React.memo(function GroupV1MigrationDialogInner(props: PropsType) {
|
2021-03-03 20:09:58 +00:00
|
|
|
const {
|
|
|
|
areWeInvited,
|
2022-12-08 06:41:37 +00:00
|
|
|
conversationId,
|
2021-03-03 20:09:58 +00:00
|
|
|
droppedMembers,
|
2021-11-20 15:41:21 +00:00
|
|
|
getPreferredBadge,
|
2021-03-03 20:09:58 +00:00
|
|
|
hasMigrated,
|
|
|
|
i18n,
|
|
|
|
invitedMembers,
|
2021-11-20 15:41:21 +00:00
|
|
|
theme,
|
2021-03-03 20:09:58 +00:00
|
|
|
} = props;
|
2020-11-20 17:30:45 +00:00
|
|
|
|
2022-12-08 06:41:37 +00:00
|
|
|
let migrateHandler;
|
|
|
|
if ('migrate' in props) {
|
|
|
|
migrateHandler = props.migrate;
|
|
|
|
} else if ('initiateMigrationToGroupV2' in props) {
|
|
|
|
migrateHandler = () => props.initiateMigrationToGroupV2(conversationId);
|
|
|
|
} else {
|
|
|
|
throw new Error(
|
|
|
|
'GroupV1MigrationDialog: No conversationId or migration function'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
let closeHandler;
|
|
|
|
if ('onClose' in props) {
|
|
|
|
closeHandler = props.onClose;
|
|
|
|
} else if ('closeGV2MigrationDialog' in props) {
|
|
|
|
closeHandler = props.closeGV2MigrationDialog;
|
|
|
|
} else {
|
|
|
|
throw new Error('GroupV1MigrationDialog: No close function provided');
|
|
|
|
}
|
|
|
|
|
2021-03-03 20:09:58 +00:00
|
|
|
const title = hasMigrated
|
2023-03-30 00:03:25 +00:00
|
|
|
? i18n('icu:GroupV1--Migration--info--title')
|
|
|
|
: i18n('icu:GroupV1--Migration--migrate--title');
|
2021-03-03 20:09:58 +00:00
|
|
|
const keepHistory = hasMigrated
|
2023-03-30 00:03:25 +00:00
|
|
|
? i18n('icu:GroupV1--Migration--info--keep-history')
|
|
|
|
: i18n('icu:GroupV1--Migration--migrate--keep-history');
|
2020-11-20 17:30:45 +00:00
|
|
|
|
2021-03-03 20:09:58 +00:00
|
|
|
let primaryButtonText: string;
|
|
|
|
let onClickPrimaryButton: () => void;
|
|
|
|
let secondaryButtonProps:
|
|
|
|
| undefined
|
|
|
|
| {
|
|
|
|
secondaryButtonText: string;
|
|
|
|
onClickSecondaryButton: () => void;
|
|
|
|
};
|
|
|
|
if (hasMigrated) {
|
2023-03-30 00:03:25 +00:00
|
|
|
primaryButtonText = i18n('icu:Confirmation--confirm');
|
2022-12-08 06:41:37 +00:00
|
|
|
onClickPrimaryButton = closeHandler;
|
2021-03-03 20:09:58 +00:00
|
|
|
} else {
|
2023-03-30 00:03:25 +00:00
|
|
|
primaryButtonText = i18n('icu:GroupV1--Migration--migrate');
|
2022-12-08 06:41:37 +00:00
|
|
|
onClickPrimaryButton = migrateHandler;
|
2021-03-03 20:09:58 +00:00
|
|
|
secondaryButtonProps = {
|
2023-03-30 00:03:25 +00:00
|
|
|
secondaryButtonText: i18n('icu:cancel'),
|
2022-12-08 06:41:37 +00:00
|
|
|
onClickSecondaryButton: closeHandler,
|
2021-03-03 20:09:58 +00:00
|
|
|
};
|
|
|
|
}
|
2020-11-20 17:30:45 +00:00
|
|
|
|
2021-03-03 20:09:58 +00:00
|
|
|
return (
|
|
|
|
<GroupDialog
|
|
|
|
i18n={i18n}
|
|
|
|
onClickPrimaryButton={onClickPrimaryButton}
|
2022-12-08 06:41:37 +00:00
|
|
|
onClose={closeHandler}
|
2021-03-03 20:09:58 +00:00
|
|
|
primaryButtonText={primaryButtonText}
|
|
|
|
title={title}
|
|
|
|
{...secondaryButtonProps}
|
|
|
|
>
|
|
|
|
<GroupDialog.Paragraph>
|
2023-03-30 00:03:25 +00:00
|
|
|
{i18n('icu:GroupV1--Migration--info--summary')}
|
2021-03-03 20:09:58 +00:00
|
|
|
</GroupDialog.Paragraph>
|
|
|
|
<GroupDialog.Paragraph>{keepHistory}</GroupDialog.Paragraph>
|
2020-12-01 23:45:39 +00:00
|
|
|
{areWeInvited ? (
|
2021-03-03 20:09:58 +00:00
|
|
|
<GroupDialog.Paragraph>
|
2023-03-30 00:03:25 +00:00
|
|
|
{i18n('icu:GroupV1--Migration--info--invited--you')}
|
2021-03-03 20:09:58 +00:00
|
|
|
</GroupDialog.Paragraph>
|
2020-12-01 23:45:39 +00:00
|
|
|
) : (
|
|
|
|
<>
|
2021-11-20 15:41:21 +00:00
|
|
|
{renderMembers({
|
|
|
|
getPreferredBadge,
|
|
|
|
i18n,
|
|
|
|
members: invitedMembers,
|
2023-03-29 17:15:54 +00:00
|
|
|
hasMigrated,
|
|
|
|
kind: 'invited',
|
2021-11-20 15:41:21 +00:00
|
|
|
theme,
|
|
|
|
})}
|
|
|
|
{renderMembers({
|
|
|
|
getPreferredBadge,
|
|
|
|
i18n,
|
|
|
|
members: droppedMembers,
|
2023-03-29 17:15:54 +00:00
|
|
|
hasMigrated,
|
|
|
|
kind: 'dropped',
|
2021-11-20 15:41:21 +00:00
|
|
|
theme,
|
|
|
|
})}
|
2020-12-01 23:45:39 +00:00
|
|
|
</>
|
2020-11-20 17:30:45 +00:00
|
|
|
)}
|
2021-03-03 20:09:58 +00:00
|
|
|
</GroupDialog>
|
2020-11-20 17:30:45 +00:00
|
|
|
);
|
2021-11-11 22:43:05 +00:00
|
|
|
});
|
2020-11-20 17:30:45 +00:00
|
|
|
|
2021-11-20 15:41:21 +00:00
|
|
|
function renderMembers({
|
|
|
|
getPreferredBadge,
|
|
|
|
i18n,
|
|
|
|
members,
|
2023-03-29 17:15:54 +00:00
|
|
|
hasMigrated,
|
|
|
|
kind,
|
2021-11-20 15:41:21 +00:00
|
|
|
theme,
|
|
|
|
}: Readonly<{
|
|
|
|
getPreferredBadge: PreferredBadgeSelectorType;
|
|
|
|
i18n: LocalizerType;
|
|
|
|
members: Array<ConversationType>;
|
2023-03-29 17:15:54 +00:00
|
|
|
hasMigrated: boolean;
|
|
|
|
kind: 'invited' | 'dropped';
|
2021-11-20 15:41:21 +00:00
|
|
|
theme: ThemeType;
|
|
|
|
}>): React.ReactNode {
|
2020-11-20 17:30:45 +00:00
|
|
|
if (!members.length) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-03-29 17:15:54 +00:00
|
|
|
let text: string;
|
|
|
|
switch (kind) {
|
|
|
|
case 'invited':
|
|
|
|
text =
|
|
|
|
members.length === 1
|
2023-03-30 00:03:25 +00:00
|
|
|
? i18n('icu:GroupV1--Migration--info--invited--one')
|
|
|
|
: i18n('icu:GroupV1--Migration--info--invited--many');
|
2023-03-29 17:15:54 +00:00
|
|
|
break;
|
|
|
|
case 'dropped':
|
|
|
|
if (hasMigrated) {
|
|
|
|
text =
|
|
|
|
members.length === 1
|
2023-03-30 00:03:25 +00:00
|
|
|
? i18n('icu:GroupV1--Migration--info--removed--before--one')
|
|
|
|
: i18n('icu:GroupV1--Migration--info--removed--before--many');
|
2023-03-29 17:15:54 +00:00
|
|
|
} else {
|
|
|
|
text =
|
|
|
|
members.length === 1
|
2023-03-30 00:03:25 +00:00
|
|
|
? i18n('icu:GroupV1--Migration--info--removed--after--one')
|
|
|
|
: i18n('icu:GroupV1--Migration--info--removed--after--many');
|
2023-03-29 17:15:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw missingCaseError(kind);
|
|
|
|
}
|
2020-11-20 17:30:45 +00:00
|
|
|
|
|
|
|
return (
|
2021-03-03 20:09:58 +00:00
|
|
|
<>
|
2023-03-29 17:15:54 +00:00
|
|
|
<GroupDialog.Paragraph>{text}</GroupDialog.Paragraph>
|
2021-11-20 15:41:21 +00:00
|
|
|
<GroupDialog.Contacts
|
|
|
|
contacts={sortByTitle(members)}
|
|
|
|
getPreferredBadge={getPreferredBadge}
|
|
|
|
i18n={i18n}
|
|
|
|
theme={theme}
|
|
|
|
/>
|
2021-03-03 20:09:58 +00:00
|
|
|
</>
|
2020-11-20 17:30:45 +00:00
|
|
|
);
|
|
|
|
}
|