import type { FC } from '../../lib/teact/teact'; import React, { useRef } from '../../lib/teact/teact'; import type { ApiUser, ApiMessage, ApiChat } from '../../api/types'; import { getMessageMediaHash, isActionMessage, getSenderTitle, getMessageRoundVideo, getUserColorKey, } from '../../global/helpers'; import renderText from './helpers/renderText'; import { getPictogramDimensions } from './helpers/mediaDimensions'; import buildClassName from '../../util/buildClassName'; import { renderMessageSummary } from './helpers/renderMessageText'; import type { ObserveFn } from '../../hooks/useIntersectionObserver'; import { useIsIntersecting } from '../../hooks/useIntersectionObserver'; import useMedia from '../../hooks/useMedia'; import useThumbnail from '../../hooks/useThumbnail'; import useLang from '../../hooks/useLang'; import ActionMessage from '../middle/ActionMessage'; import './EmbeddedMessage.scss'; type OwnProps = { observeIntersection?: ObserveFn; className?: string; message?: ApiMessage; sender?: ApiUser | ApiChat; title?: string; customText?: string; noUserColors?: boolean; isProtected?: boolean; hasContextMenu?: boolean; onClick: NoneToVoidFunction; }; const NBSP = '\u00A0'; const EmbeddedMessage: FC = ({ className, message, sender, title, customText, isProtected, noUserColors, hasContextMenu, observeIntersection, onClick, }) => { // eslint-disable-next-line no-null/no-null const ref = useRef(null); const isIntersecting = useIsIntersecting(ref, observeIntersection); const mediaBlobUrl = useMedia(message && getMessageMediaHash(message, 'pictogram'), !isIntersecting); const mediaThumbnail = useThumbnail(message); const isRoundVideo = Boolean(message && getMessageRoundVideo(message)); const lang = useLang(); const senderTitle = sender ? getSenderTitle(lang, sender) : message?.forwardInfo?.hiddenUserName; return (
{mediaThumbnail && renderPictogram(mediaThumbnail, mediaBlobUrl, isRoundVideo, isProtected)}

{!message ? ( customText || NBSP ) : isActionMessage(message) ? ( ) : ( renderMessageSummary(lang, message, Boolean(mediaThumbnail)) )}

{renderText(senderTitle || title || NBSP)}
{hasContextMenu && }
); }; function renderPictogram( thumbDataUri: string, blobUrl?: string, isRoundVideo?: boolean, isProtected?: boolean, ) { const { width, height } = getPictogramDimensions(); return ( <> {isProtected && } ); } export default EmbeddedMessage;