import React, { useState, MouseEvent } from 'react'; import classNames from 'classnames'; import * as MIME from '../../../../../types/MIME'; import { useSelector } from 'react-redux'; import { isPublicGroupConversation } from '../../../../../state/selectors/conversations'; import { QuoteAuthor } from './QuoteAuthor'; import { QuoteGenericFile } from './QuoteGenericFile'; import { QuoteText } from './QuoteText'; import { QuoteIconContainer } from './QuoteIconContainer'; import styled from 'styled-components'; export type QuotePropsWithoutListener = { attachment?: QuotedAttachmentType; sender: string; authorProfileName?: string; authorName?: string; isFromMe: boolean; isIncoming: boolean; text: string | null; referencedMessageNotFound: boolean; }; export type QuotePropsWithListener = QuotePropsWithoutListener & { onClick?: (e: React.MouseEvent) => void; }; export interface Attachment { contentType: MIME.MIMEType; /** Not included in protobuf, and is loaded asynchronously */ objectUrl?: string; } export interface QuotedAttachmentType { contentType: MIME.MIMEType; fileName: string; /** Not included in protobuf */ isVoiceMessage: boolean; thumbnail?: Attachment; } function validateQuote(quote: QuotePropsWithoutListener): boolean { if (quote.text) { return true; } if (quote.attachment) { return true; } return false; } const StyledQuote = styled.div<{ isIncoming: boolean; onClick: ((e: MouseEvent) => void) | undefined; }>` position: relative; display: flex; flex-direction: row; align-items: stretch; overflow: hidden; border-left: 4px solid ${props => props.isIncoming ? 'var(--message-bubbles-received-text-color)' : 'var(--message-bubbles-sent-text-color)'}; cursor: ${props => (props.onClick ? 'pointer' : 'auto')}; `; export const Quote = (props: QuotePropsWithListener) => { const [imageBroken, setImageBroken] = useState(false); const handleImageErrorBound = () => { setImageBroken(true); }; const isPublic = useSelector(isPublicGroupConversation); if (!validateQuote(props)) { return null; } const { isIncoming, attachment, text, onClick } = props; return (
); };