import React from 'react'; import { SessionIcon, SessionIconButton } from '../icon'; import styled from 'styled-components'; import { useDispatch, useSelector } from 'react-redux'; import { quoteMessage } from '../../state/ducks/conversations'; import { getQuotedMessage } from '../../state/selectors/conversations'; import { getAlt, isAudio } from '../../types/Attachment'; import { AUDIO_MP3 } from '../../types/MIME'; import { Flex } from '../basic/Flex'; import { Image } from '../../../ts/components/conversation/Image'; // tslint:disable-next-line: no-submodule-imports import useKey from 'react-use/lib/useKey'; import { getAbsoluteAttachmentPath } from '../../types/MessageAttachment'; const QuotedMessageComposition = styled(Flex)` border-top: 1px solid var(--border-color); `; const QuotedMessageCompositionReply = styled(Flex)<{ hasAttachments: boolean }>` ${props => !props.hasAttachments && 'border-left: 3px solid var(--primary-color);'} `; const Subtle = styled.div` overflow: hidden; text-overflow: ellipsis; word-break: break-all; -webkit-line-clamp: 1; -webkit-box-orient: vertical; display: -webkit-box; color: var(--text-primary-color); `; const StyledImage = styled.div` div { border-radius: 4px; overflow: hidden; } `; const StyledText = styled(Flex)` margin: 0 0 0 var(--margins-sm); p { font-weight: bold; margin: 0; } `; export const SessionQuotedMessageComposition = () => { const quotedMessageProps = useSelector(getQuotedMessage); const dispatch = useDispatch(); const { author, attachments, text: quoteText } = quotedMessageProps || {}; const hasAttachments = attachments && attachments.length > 0 && attachments[0]; const firstImageAttachment = hasAttachments && attachments[0].contentType !== AUDIO_MP3 && attachments[0].thumbnail ? attachments[0] : undefined; const hasAudio = hasAttachments && isAudio(attachments); const hasAudioAttachment = hasAudio !== false && hasAudio !== undefined && hasAudio !== ''; const subtitleText = hasAttachments && firstImageAttachment ? window.i18n('image') : hasAudioAttachment ? window.i18n('audio') : quoteText !== '' ? quoteText : null; const removeQuotedMessage = () => { dispatch(quoteMessage(undefined)); }; useKey('Escape', removeQuotedMessage, undefined, []); if (!author || !quotedMessageProps?.id) { return null; } return ( {hasAttachments && ( {firstImageAttachment ? ( {getAlt(firstImageAttachment)} ) : hasAudioAttachment ? (
) : null}
)}

{author}

{subtitleText && {subtitleText}}
); };