2022-03-24 21:46:17 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
import React, { memo, useCallback } from 'react';
|
2022-03-24 21:46:17 +00:00
|
|
|
import { useSelector } from 'react-redux';
|
2024-02-06 02:13:13 +00:00
|
|
|
import { mapValues } from 'lodash';
|
2022-03-24 21:46:17 +00:00
|
|
|
import type { StateType } from '../reducer';
|
|
|
|
import { ContactSpoofingReviewDialog } from '../../components/conversation/ContactSpoofingReviewDialog';
|
2022-12-21 03:25:10 +00:00
|
|
|
import { useConversationsActions } from '../ducks/conversations';
|
2024-02-06 02:13:13 +00:00
|
|
|
import {
|
|
|
|
getConversationSelector,
|
|
|
|
getConversationByServiceIdSelector,
|
|
|
|
getSafeConversationWithSameTitle,
|
|
|
|
} from '../selectors/conversations';
|
|
|
|
import { getOwn } from '../../util/getOwn';
|
|
|
|
import { assertDev } from '../../util/assert';
|
2022-03-24 21:46:17 +00:00
|
|
|
import { ContactSpoofingType } from '../../util/contactSpoofing';
|
2024-02-06 02:13:13 +00:00
|
|
|
import { getGroupMemberships } from '../../util/getGroupMemberships';
|
|
|
|
import { isSignalConnection } from '../../util/getSignalConnections';
|
|
|
|
import {
|
|
|
|
getCollisionsFromMemberships,
|
|
|
|
invertIdsByTitle,
|
|
|
|
} from '../../util/groupMemberNameCollisions';
|
2022-12-21 03:25:10 +00:00
|
|
|
import { useGlobalModalActions } from '../ducks/globalModals';
|
|
|
|
import { getPreferredBadgeSelector } from '../selectors/badges';
|
|
|
|
import { getIntl, getTheme } from '../selectors/user';
|
2022-03-24 21:46:17 +00:00
|
|
|
|
2024-02-06 02:13:13 +00:00
|
|
|
export type PropsType = Readonly<{
|
|
|
|
conversationId: string;
|
|
|
|
onClose: () => void;
|
|
|
|
}>;
|
2022-03-24 21:46:17 +00:00
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
export const SmartContactSpoofingReviewDialog = memo(
|
|
|
|
function SmartContactSpoofingReviewDialog(props: PropsType) {
|
|
|
|
const { conversationId } = props;
|
|
|
|
|
|
|
|
const getConversation = useSelector(getConversationSelector);
|
|
|
|
|
|
|
|
const {
|
|
|
|
acceptConversation,
|
|
|
|
reportSpam,
|
|
|
|
blockAndReportSpam,
|
|
|
|
blockConversation,
|
|
|
|
deleteConversation,
|
|
|
|
removeMember,
|
|
|
|
updateSharedGroups,
|
|
|
|
} = useConversationsActions();
|
|
|
|
const { showContactModal, toggleSignalConnectionsModal } =
|
|
|
|
useGlobalModalActions();
|
|
|
|
const getPreferredBadge = useSelector(getPreferredBadgeSelector);
|
|
|
|
const i18n = useSelector(getIntl);
|
|
|
|
const theme = useSelector(getTheme);
|
|
|
|
const getConversationByServiceId = useSelector(
|
|
|
|
getConversationByServiceIdSelector
|
2024-02-06 02:13:13 +00:00
|
|
|
);
|
2024-03-13 20:44:13 +00:00
|
|
|
const conversation = getConversation(conversationId);
|
|
|
|
|
|
|
|
// Just binding the options argument
|
|
|
|
const safeConversationSelector = useCallback(
|
|
|
|
(state: StateType) => {
|
|
|
|
return getSafeConversationWithSameTitle(state, {
|
|
|
|
possiblyUnsafeConversation: conversation,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
[conversation]
|
2024-02-06 02:13:13 +00:00
|
|
|
);
|
2024-03-13 20:44:13 +00:00
|
|
|
const safeConvo = useSelector(safeConversationSelector);
|
|
|
|
|
|
|
|
const sharedProps = {
|
|
|
|
...props,
|
|
|
|
acceptConversation,
|
|
|
|
reportSpam,
|
|
|
|
blockAndReportSpam,
|
|
|
|
blockConversation,
|
|
|
|
deleteConversation,
|
|
|
|
getPreferredBadge,
|
|
|
|
i18n,
|
|
|
|
removeMember,
|
|
|
|
updateSharedGroups,
|
|
|
|
showContactModal,
|
|
|
|
toggleSignalConnectionsModal,
|
|
|
|
theme,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (conversation.type === 'group') {
|
|
|
|
const { memberships } = getGroupMemberships(
|
|
|
|
conversation,
|
|
|
|
getConversationByServiceId
|
|
|
|
);
|
|
|
|
const groupNameCollisions = getCollisionsFromMemberships(memberships);
|
|
|
|
|
|
|
|
const previouslyAcknowledgedTitlesById = invertIdsByTitle(
|
|
|
|
conversation.acknowledgedGroupNameCollisions
|
|
|
|
);
|
|
|
|
|
|
|
|
const collisionInfoByTitle = mapValues(groupNameCollisions, collisions =>
|
|
|
|
collisions.map(collision => ({
|
|
|
|
conversation: collision,
|
|
|
|
isSignalConnection: isSignalConnection(collision),
|
|
|
|
oldName: getOwn(previouslyAcknowledgedTitlesById, collision.id),
|
|
|
|
}))
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ContactSpoofingReviewDialog
|
|
|
|
{...sharedProps}
|
|
|
|
type={ContactSpoofingType.MultipleGroupMembersWithSameTitle}
|
|
|
|
group={conversation}
|
|
|
|
collisionInfoByTitle={collisionInfoByTitle}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const possiblyUnsafeConvo = conversation;
|
|
|
|
assertDev(
|
|
|
|
possiblyUnsafeConvo.type === 'direct',
|
|
|
|
'DirectConversationWithSameTitle: expects possibly unsafe direct ' +
|
|
|
|
'conversation'
|
2024-02-06 02:13:13 +00:00
|
|
|
);
|
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
if (!safeConvo) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const possiblyUnsafe = {
|
|
|
|
conversation: possiblyUnsafeConvo,
|
|
|
|
isSignalConnection: isSignalConnection(possiblyUnsafeConvo),
|
|
|
|
};
|
|
|
|
const safe = {
|
|
|
|
conversation: safeConvo,
|
|
|
|
isSignalConnection: isSignalConnection(safeConvo),
|
|
|
|
};
|
|
|
|
|
2022-03-24 21:46:17 +00:00
|
|
|
return (
|
|
|
|
<ContactSpoofingReviewDialog
|
2022-12-21 03:25:10 +00:00
|
|
|
{...sharedProps}
|
2024-03-13 20:44:13 +00:00
|
|
|
type={ContactSpoofingType.DirectConversationWithSameTitle}
|
|
|
|
possiblyUnsafe={possiblyUnsafe}
|
|
|
|
safe={safe}
|
2022-03-24 21:46:17 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2024-03-13 20:44:13 +00:00
|
|
|
);
|