import React from 'react'; import classNames from 'classnames'; import moment from 'moment'; import { Avatar } from '../Avatar'; import { ContactName } from './ContactName'; import { Message, Props as MessageProps } from './Message'; import { LocalizerType } from '../../types/Util'; interface Contact { status: string; phoneNumber: string; name?: string; profileName?: string; avatarPath?: string; color: string; isOutgoingKeyError: boolean; isUnidentifiedDelivery: boolean; errors?: Array; onSendAnyway: () => void; onShowSafetyNumber: () => void; } interface Props { sentAt: number; receivedAt: number; message: MessageProps; errors: Array; contacts: Array; i18n: LocalizerType; } export class MessageDetail extends React.Component { public renderAvatar(contact: Contact) { const { i18n } = this.props; const { avatarPath, phoneNumber, name, profileName } = contact; const userName = name || profileName || phoneNumber; return ( ); } public renderDeleteButton() { const { i18n, message } = this.props; return message.isDeletable ? (
) : null; } public renderContact(contact: Contact) { const { i18n } = this.props; const errors = contact.errors || []; const errorComponent = contact.isOutgoingKeyError ? (
) : null; const statusComponent = !contact.isOutgoingKeyError ? (
) : null; const unidentifiedDeliveryComponent = contact.isUnidentifiedDelivery ? (
) : null; return (
{this.renderAvatar(contact)}
{errors.map((error, index) => (
{error.message}
))}
{errorComponent} {unidentifiedDeliveryComponent} {statusComponent}
); } public renderContacts() { const { contacts } = this.props; if (!contacts || !contacts.length) { return null; } return (
{contacts.map(contact => this.renderContact(contact))}
); } public render() { const { errors, message, receivedAt, sentAt, i18n } = this.props; return (
{(errors || []).map((error, index) => ( ))} {receivedAt ? ( ) : null}
{i18n('error')} {' '} {error.message}{' '}
{i18n('sent')} {moment(sentAt).format('LLLL')}{' '} ({sentAt})
{i18n('received')} {moment(receivedAt).format('LLLL')}{' '} ({receivedAt})
{message.direction === 'incoming' ? i18n('from') : i18n('to')}
{this.renderContacts()} {this.renderDeleteButton()}
); } }