import React from 'react'; import classNames from 'classnames'; import { isNumber } from 'lodash'; 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 { cleanId } from './_util'; import { ColorType, LocalizerType } from '../types/Util'; export type PropsData = { id: string; phoneNumber?: string; color?: ColorType; profileName?: string; title: string; name?: string; type: 'group' | 'direct'; avatarPath?: string; isMe?: boolean; lastUpdated: number; unreadCount?: number; isSelected: boolean; isAccepted?: boolean; draftPreview?: string; shouldShowDraft?: boolean; typingContact?: Object; lastMessage?: { status: 'sending' | 'sent' | 'delivered' | 'read' | 'error'; text: string; deletedForEveryone?: boolean; }; }; 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, title, } = this.props; return (
{this.renderUnread()}
); } public renderUnread() { const { unreadCount } = this.props; if (isNumber(unreadCount) && unreadCount > 0) { return (
{unreadCount}
); } return null; } public renderHeader() { const { unreadCount, i18n, isMe, lastUpdated, name, phoneNumber, profileName, title, } = this.props; const withUnread = isNumber(unreadCount) && unreadCount > 0; return (
{isMe ? ( i18n('noteToSelf') ) : ( )}
); } public renderMessage() { const { draftPreview, i18n, isAccepted, lastMessage, shouldShowDraft, typingContact, unreadCount, } = this.props; if (!lastMessage && !typingContact) { return null; } const withUnread = isNumber(unreadCount) && unreadCount > 0; const showingDraft = shouldShowDraft && draftPreview; const deletedForEveryone = Boolean( lastMessage && lastMessage.deletedForEveryone ); // Note: instead of re-using showingDraft here we explode it because // typescript can't tell that draftPreview is truthy otherwise const text = shouldShowDraft && draftPreview ? draftPreview : lastMessage && lastMessage.text ? lastMessage.text : ''; return (
{!isAccepted ? ( {i18n('ConversationListItem--message-request')} ) : typingContact ? ( ) : ( <> {showingDraft ? ( {i18n('ConversationListItem--draft-prefix')} ) : deletedForEveryone ? ( {i18n('message--deletedForEveryone')} ) : null} )}
{!showingDraft && lastMessage && lastMessage.status ? (
) : null}
); } public render() { const { unreadCount, onClick, id, isSelected, style } = this.props; const withUnread = isNumber(unreadCount) && unreadCount > 0; return ( ); } }