import React from 'react'; import classNames from 'classnames'; import { Avatar } from './Avatar'; import { MessageBodyHighlight } from './MessageBodyHighlight'; import { Timestamp } from './conversation/Timestamp'; import { ContactName } from './conversation/ContactName'; import { LocalizerType } from '../types/Util'; export type PropsData = { id: string; conversationId: string; receivedAt: number; snippet: string; from: { phoneNumber: string; isMe?: boolean; name?: string; color?: string; profileName?: string; avatarPath?: string; }; to: { groupName?: string; phoneNumber: string; isMe?: boolean; name?: string; profileName?: string; }; }; type PropsHousekeeping = { isSelected?: boolean; i18n: LocalizerType; onClick: (conversationId: string, messageId?: string) => void; }; type Props = PropsData & PropsHousekeeping; export class MessageSearchResult extends React.PureComponent { public renderFromName() { const { from, i18n, to } = this.props; if (from.isMe && to.isMe) { return ( {i18n('noteToSelf')} ); } if (from.isMe) { return ( {i18n('you')} ); } return ( ); } public renderFrom() { const { i18n, to } = this.props; const fromName = this.renderFromName(); if (!to.isMe) { return (
{fromName} {i18n('to')}{' '}
); } return (
{fromName}
); } public renderAvatar() { const { from, i18n, to } = this.props; const isNoteToSelf = from.isMe && to.isMe; return ( ); } public render() { const { from, i18n, id, isSelected, conversationId, onClick, receivedAt, snippet, to, } = this.props; if (!from || !to) { return null; } return (
{ if (onClick) { onClick(conversationId, id); } }} className={classNames( 'module-message-search-result', isSelected ? 'module-message-search-result--is-selected' : null )} > {this.renderAvatar()}
{this.renderFrom()}
); } }