import React from 'react'; import classNames from 'classnames'; import moment from 'moment'; import { ContactName } from './ContactName'; import { Message, Props as MessageProps } from './Message'; import { Localizer } from '../../types/Util'; interface Contact { status: string; phoneNumber: string; name?: string; profileName?: string; avatarPath?: string; color: string; isOutgoingKeyError: boolean; errors?: Array; onSendAnyway: () => void; onShowSafetyNumber: () => void; } interface Props { sentAt: number; receivedAt: number; message: MessageProps; errors: Array; contacts: Array; i18n: Localizer; } function getInitial(name: string): string { return name.trim()[0] || '#'; } export class MessageDetail extends React.Component { public renderAvatar(contact: Contact) { const { i18n } = this.props; const { avatarPath, color, phoneNumber, name, profileName } = contact; if (!avatarPath) { const initial = getInitial(name || ''); return (
{initial}
); } const title = `${name || phoneNumber}${ !name && profileName ? ` ~${profileName}` : '' }`; return ( {i18n('contactAvatarAlt', ); } public renderDeleteButton() { const { i18n, message } = this.props; return (
); } public renderContact(contact: Contact) { const { i18n } = this.props; const errors = contact.errors || []; const errorComponent = contact.isOutgoingKeyError ? (
) : null; const statusComponent = !contact.isOutgoingKeyError ? (
) : null; return (
{this.renderAvatar(contact)}
{errors.map((error, index) => (
{error.message}
))}
{errorComponent} {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 => ( ))} {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()}
); } }