import classNames from 'classnames'; import React from 'react'; import { isImageAttachment } from '../../../../types/Attachment'; import { ImageGrid } from '../../ImageGrid'; import { Image } from '../../Image'; import { MessageRenderingProps } from '../../../../models/messageType'; import { useDispatch, useSelector } from 'react-redux'; import { getMessagePreviewProps } from '../../../../state/selectors/conversations'; import { SessionIcon } from '../../../icon'; import { MINIMUM_LINK_PREVIEW_IMAGE_WIDTH } from '../message-item/Message'; import { showLinkVisitWarningDialog } from '../../../dialog/SessionConfirm'; export type MessagePreviewSelectorProps = Pick; type Props = { handleImageError: () => void; messageId: string; }; export const MessagePreview = (props: Props) => { const selected = useSelector(state => getMessagePreviewProps(state as any, props.messageId)); const dispatch = useDispatch(); if (!selected) { return null; } const { attachments, previews } = selected; // Attachments take precedence over Link Previews if (attachments && attachments.length) { return null; } if (!previews || previews.length < 1) { return null; } const first = previews[0]; if (!first) { return null; } const previewHasImage = first.image && isImageAttachment(first.image); const width = first.image && first.image.width; const isFullSizeImage = width && width >= MINIMUM_LINK_PREVIEW_IMAGE_WIDTH; function openLinkFromPreview() { if (previews?.length && previews[0].url) { showLinkVisitWarningDialog(previews[0].url, dispatch); } } return (
{first.image && previewHasImage && isFullSizeImage ? ( ) : null}
{first.image && previewHasImage && !isFullSizeImage ? (
{window.i18n('previewThumbnail',
) : !first.image || !previewHasImage ? (
) : null}
{first.title}
{first.domain}
); };