2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
2020-12-01 16:42:35 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
2024-03-13 20:44:13 +00:00
|
|
|
import React, { memo, useCallback, useMemo } from 'react';
|
|
|
|
import { useSelector } from 'react-redux';
|
2022-12-08 06:41:37 +00:00
|
|
|
import type { DataPropsType as GroupV1MigrationDialogPropsType } from '../../components/GroupV1MigrationDialog';
|
2021-10-26 19:15:33 +00:00
|
|
|
import { GroupV1MigrationDialog } from '../../components/GroupV1MigrationDialog';
|
2024-03-13 20:44:13 +00:00
|
|
|
import { useConversationsActions } from '../ducks/conversations';
|
2021-11-20 15:41:21 +00:00
|
|
|
import { getPreferredBadgeSelector } from '../selectors/badges';
|
2020-12-01 16:42:35 +00:00
|
|
|
import { getConversationSelector } from '../selectors/conversations';
|
2021-11-20 15:41:21 +00:00
|
|
|
import { getIntl, getTheme } from '../selectors/user';
|
2021-09-17 18:27:53 +00:00
|
|
|
import * as log from '../../logging/log';
|
2024-03-13 20:44:13 +00:00
|
|
|
import { useGlobalModalActions } from '../ducks/globalModals';
|
2020-12-01 16:42:35 +00:00
|
|
|
|
|
|
|
export type PropsType = {
|
2024-03-13 20:44:13 +00:00
|
|
|
readonly conversationId: string;
|
2020-12-01 16:42:35 +00:00
|
|
|
readonly droppedMemberIds: Array<string>;
|
|
|
|
readonly invitedMemberIds: Array<string>;
|
|
|
|
} & Omit<
|
|
|
|
GroupV1MigrationDialogPropsType,
|
2021-11-20 15:41:21 +00:00
|
|
|
'i18n' | 'droppedMembers' | 'invitedMembers' | 'theme' | 'getPreferredBadge'
|
2020-12-01 16:42:35 +00:00
|
|
|
>;
|
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
function isNonNullable<T>(value: T | null | undefined): value is T {
|
|
|
|
return value != null;
|
|
|
|
}
|
2020-12-01 16:42:35 +00:00
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
export const SmartGroupV1MigrationDialog = memo(
|
|
|
|
function SmartGroupV1MigrationDialog({
|
|
|
|
conversationId,
|
|
|
|
areWeInvited,
|
|
|
|
hasMigrated,
|
|
|
|
droppedMemberIds,
|
|
|
|
invitedMemberIds,
|
|
|
|
}: PropsType) {
|
|
|
|
const i18n = useSelector(getIntl);
|
|
|
|
const theme = useSelector(getTheme);
|
|
|
|
const getConversation = useSelector(getConversationSelector);
|
|
|
|
const getPreferredBadge = useSelector(getPreferredBadgeSelector);
|
2020-12-01 16:42:35 +00:00
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
const { initiateMigrationToGroupV2 } = useConversationsActions();
|
|
|
|
const { closeGV2MigrationDialog } = useGlobalModalActions();
|
2020-12-01 16:42:35 +00:00
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
const droppedMembers = useMemo(() => {
|
|
|
|
const result = droppedMemberIds
|
|
|
|
.map(getConversation)
|
|
|
|
.filter(isNonNullable);
|
|
|
|
if (result.length !== droppedMemberIds.length) {
|
|
|
|
log.warn('smart/GroupV1MigrationDialog: droppedMembers length changed');
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}, [droppedMemberIds, getConversation]);
|
2020-12-01 16:42:35 +00:00
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
const invitedMembers = useMemo(() => {
|
|
|
|
const result = invitedMemberIds
|
|
|
|
.map(getConversation)
|
|
|
|
.filter(isNonNullable);
|
|
|
|
if (result.length !== invitedMemberIds.length) {
|
|
|
|
log.warn('smart/GroupV1MigrationDialog: invitedMembers length changed');
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}, [invitedMemberIds, getConversation]);
|
|
|
|
|
|
|
|
const handleMigrate = useCallback(() => {
|
|
|
|
initiateMigrationToGroupV2(conversationId);
|
|
|
|
}, [initiateMigrationToGroupV2, conversationId]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<GroupV1MigrationDialog
|
|
|
|
i18n={i18n}
|
|
|
|
theme={theme}
|
|
|
|
areWeInvited={areWeInvited}
|
|
|
|
hasMigrated={hasMigrated}
|
|
|
|
getPreferredBadge={getPreferredBadge}
|
|
|
|
droppedMembers={droppedMembers}
|
2024-04-30 13:24:21 +00:00
|
|
|
droppedMemberCount={droppedMembers.length}
|
2024-03-13 20:44:13 +00:00
|
|
|
invitedMembers={invitedMembers}
|
2024-04-30 13:24:21 +00:00
|
|
|
invitedMemberCount={invitedMembers.length}
|
2024-03-13 20:44:13 +00:00
|
|
|
onMigrate={handleMigrate}
|
|
|
|
onClose={closeGV2MigrationDialog}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|