import React from 'react'; import classNames from 'classnames'; import { Avatar } from './Avatar'; import { MessageBody } from './conversation/MessageBody'; import { Timestamp } from './conversation/Timestamp'; import { ContactName } from './conversation/ContactName'; import { TypingAnimation } from './conversation/TypingAnimation'; import { LocalizerType } from '../types/Util'; export type PropsData = { id: string; phoneNumber: string; color?: string; profileName?: string; name?: string; type: 'group' | 'direct'; avatarPath?: string; isMe: boolean; lastUpdated: number; unreadCount: number; isSelected: boolean; isTyping: boolean; lastMessage?: { status: 'sending' | 'sent' | 'delivered' | 'read' | 'error'; text: string; }; }; type PropsHousekeeping = { i18n: LocalizerType; style?: Object; onClick?: (id: string) => void; }; type Props = PropsData & PropsHousekeeping; export class ConversationListItem extends React.PureComponent { public renderAvatar() { const { avatarPath, color, type, i18n, isMe, name, phoneNumber, profileName, } = this.props; return (
{this.renderUnread()}
); } public renderUnread() { const { unreadCount } = this.props; if (unreadCount > 0) { return (
{unreadCount}
); } return null; } public renderHeader() { const { unreadCount, i18n, isMe, lastUpdated, name, phoneNumber, profileName, } = this.props; return (
0 ? 'module-conversation-list-item__header__name--with-unread' : null )} > {isMe ? ( i18n('noteToSelf') ) : ( )}
0 ? 'module-conversation-list-item__header__date--has-unread' : null )} >
); } public renderMessage() { const { lastMessage, isTyping, unreadCount, i18n } = this.props; if (!lastMessage && !isTyping) { return null; } const text = lastMessage && lastMessage.text ? lastMessage.text : ''; return (
0 ? 'module-conversation-list-item__message__text--has-unread' : null )} > {isTyping ? ( ) : ( )}
{lastMessage && lastMessage.status ? (
) : null}
); } public render() { const { unreadCount, onClick, id, isSelected, style } = this.props; return (
{ if (onClick) { onClick(id); } }} style={style} className={classNames( 'module-conversation-list-item', unreadCount > 0 ? 'module-conversation-list-item--has-unread' : null, isSelected ? 'module-conversation-list-item--is-selected' : null )} > {this.renderAvatar()}
{this.renderHeader()} {this.renderMessage()}
); } }