import React from 'react'; import classNames from 'classnames'; import { MessageBody } from './conversation/MessageBody'; import { Timestamp } from './conversation/Timestamp'; import { ContactName } from './conversation/ContactName'; import { Localizer } from '../types/Util'; interface Props { phoneNumber: string; profileName?: string; name?: string; color?: string; avatarPath?: string; lastUpdated: number; hasUnread: boolean; isSelected: boolean; lastMessage?: { status: 'sending' | 'sent' | 'delivered' | 'read' | 'error'; text: string; }; i18n: Localizer; onClick?: () => void; } function getInitial(name: string): string { return name.trim()[0] || '#'; } export class ConversationListItem extends React.Component { public renderAvatar() { const { avatarPath, color, i18n, name, phoneNumber, profileName, } = this.props; if (!avatarPath) { const initial = getInitial(name || ''); return (
{initial}
); } const title = `${name || phoneNumber}${ !name && profileName ? ` ~${profileName}` : '' }`; return ( {i18n('contactAvatarAlt', ); } public renderHeader() { const { i18n, lastUpdated, name, phoneNumber, profileName } = this.props; return (
); } public renderMessage() { const { lastMessage, hasUnread, i18n } = this.props; if (!lastMessage) { return null; } return (
{lastMessage.text ? (
) : null} {lastMessage.status ? (
) : null}
); } public render() { const { hasUnread, onClick, isSelected } = this.props; return (
{this.renderAvatar()}
{this.renderHeader()} {this.renderMessage()}
); } }