// Copyright 2018-2022 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import type { ReactChild, ReactElement } from 'react'; import React from 'react'; import classNames from 'classnames'; import Measure from 'react-measure'; import type { LocalizerType } from '../../types/Util'; import type { DirectionType, MessageStatusType } from './Message'; import { ExpireTimer } from './ExpireTimer'; import { MessageTimestamp } from './MessageTimestamp'; import { Spinner } from '../Spinner'; import type { PushPanelForConversationActionType } from '../../state/ducks/conversations'; import { PanelType } from '../../types/Panels'; type PropsType = { conversationId: string; deletedForEveryone?: boolean; direction: DirectionType; expirationLength?: number; expirationTimestamp?: number; hasText: boolean; i18n: LocalizerType; id: string; isInline?: boolean; isShowingImage: boolean; isSticker?: boolean; isTapToViewExpired?: boolean; onWidthMeasured?: (width: number) => unknown; pushPanelForConversation: PushPanelForConversationActionType; status?: MessageStatusType; textPending?: boolean; timestamp: number; }; export function MessageMetadata({ conversationId, deletedForEveryone, direction, expirationLength, expirationTimestamp, hasText, i18n, id, isInline, isShowingImage, isSticker, isTapToViewExpired, onWidthMeasured, pushPanelForConversation, status, textPending, timestamp, }: Readonly): ReactElement { const withImageNoCaption = Boolean(!isSticker && !hasText && isShowingImage); const metadataDirection = isSticker ? undefined : direction; let timestampNode: ReactChild; { const isError = status === 'error' && direction === 'outgoing'; const isPartiallySent = status === 'partial-sent' && direction === 'outgoing'; const isPaused = status === 'paused'; if (isError || isPartiallySent || isPaused) { let statusInfo: React.ReactChild; if (isError) { statusInfo = deletedForEveryone ? i18n('deleteFailed') : i18n('sendFailed'); } else if (isPaused) { statusInfo = i18n('sendPaused'); } else { statusInfo = ( ); } timestampNode = ( {statusInfo} ); } else { timestampNode = ( ); } } const className = classNames( 'module-message__metadata', isInline && 'module-message__metadata--inline', withImageNoCaption && 'module-message__metadata--with-image-no-caption', deletedForEveryone && 'module-message__metadata--deleted-for-everyone' ); const children = ( <> {timestampNode} {expirationLength ? ( ) : null} {textPending ? (
) : null} {(!deletedForEveryone || status === 'sending') && !textPending && direction === 'outgoing' && status !== 'error' && status !== 'partial-sent' ? (
) : null} ); if (onWidthMeasured) { return ( { onWidthMeasured(bounds?.width || 0); }} > {({ measureRef }) => (
{children}
)}
); } return
{children}
; }