2023-03-27 23:48:57 +00:00
|
|
|
// Copyright 2023 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import React, { useMemo } from 'react';
|
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
import type { GlobalModalsStateType } from '../ducks/globalModals';
|
|
|
|
import type { MessageAttributesType } from '../../model-types.d';
|
|
|
|
import type { StateType } from '../reducer';
|
|
|
|
import { EditHistoryMessagesModal } from '../../components/EditHistoryMessagesModal';
|
2023-04-03 20:16:27 +00:00
|
|
|
import { getIntl, getPlatform } from '../selectors/user';
|
2023-03-27 23:48:57 +00:00
|
|
|
import { getMessagePropsSelector } from '../selectors/message';
|
|
|
|
import { getPreferredBadgeSelector } from '../selectors/badges';
|
|
|
|
import { useConversationsActions } from '../ducks/conversations';
|
|
|
|
import { useGlobalModalActions } from '../ducks/globalModals';
|
|
|
|
import { useLightboxActions } from '../ducks/lightbox';
|
|
|
|
import { strictAssert } from '../../util/assert';
|
|
|
|
|
|
|
|
export function SmartEditHistoryMessagesModal(): JSX.Element {
|
|
|
|
const i18n = useSelector(getIntl);
|
2023-04-03 20:16:27 +00:00
|
|
|
const platform = useSelector(getPlatform);
|
2023-03-27 23:48:57 +00:00
|
|
|
|
|
|
|
const { closeEditHistoryModal } = useGlobalModalActions();
|
|
|
|
|
|
|
|
const { kickOffAttachmentDownload } = useConversationsActions();
|
|
|
|
const { showLightbox } = useLightboxActions();
|
|
|
|
|
|
|
|
const getPreferredBadge = useSelector(getPreferredBadgeSelector);
|
|
|
|
|
|
|
|
const { editHistoryMessages: messagesAttributes } = useSelector<
|
|
|
|
StateType,
|
|
|
|
GlobalModalsStateType
|
|
|
|
>(state => state.globalModals);
|
|
|
|
|
|
|
|
const messagePropsSelector = useSelector(getMessagePropsSelector);
|
|
|
|
|
|
|
|
strictAssert(messagesAttributes, 'messages not provided');
|
|
|
|
|
|
|
|
const editHistoryMessages = useMemo(() => {
|
|
|
|
return messagesAttributes.map(messageAttributes => ({
|
|
|
|
...messagePropsSelector(messageAttributes as MessageAttributesType),
|
|
|
|
// Make sure the messages don't get an "edited" badge
|
2023-06-26 22:45:56 +00:00
|
|
|
isEditedMessage: false,
|
2023-03-27 23:48:57 +00:00
|
|
|
// Do not show the same reactions in the message history UI
|
|
|
|
reactions: undefined,
|
2023-07-05 22:38:37 +00:00
|
|
|
// Make sure that the timestamp is the correct timestamp from attributes
|
|
|
|
// not the one that the selector derives.
|
|
|
|
timestamp: messageAttributes.timestamp,
|
2023-03-27 23:48:57 +00:00
|
|
|
}));
|
|
|
|
}, [messagesAttributes, messagePropsSelector]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<EditHistoryMessagesModal
|
|
|
|
closeEditHistoryModal={closeEditHistoryModal}
|
|
|
|
editHistoryMessages={editHistoryMessages}
|
|
|
|
getPreferredBadge={getPreferredBadge}
|
|
|
|
i18n={i18n}
|
2023-04-03 20:16:27 +00:00
|
|
|
platform={platform}
|
2023-03-27 23:48:57 +00:00
|
|
|
kickOffAttachmentDownload={kickOffAttachmentDownload}
|
|
|
|
showLightbox={showLightbox}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|