// A single topic or user. import React from 'react'; import { FormattedMessage, injectIntl } from 'react-intl'; import ContactBadges from './contact-badges.jsx'; import LetterTile from './letter-tile.jsx'; import UnreadBadge from './unread-badge.jsx'; import { Drafty } from 'tinode-sdk'; import { previewFormatter } from '../lib/formatters.js'; import { deliveryMarker } from '../lib/utils.js'; class Contact extends React.Component { constructor(props) { super(props); this.handleClick = this.handleClick.bind(this); this.handleContextClick = this.handleContextClick.bind(this); } handleClick(e) { e.preventDefault(); e.stopPropagation(); if (this.props.onSelected) { // Index this.props.index is used by GroupManager. this.props.onSelected(this.props.item, this.props.index); } } handleContextClick(e) { e.preventDefault(); e.stopPropagation(); this.props.showContextMenu({ topicName: this.props.item, y: e.pageY, x: e.pageX }); } render() { let title = this.props.title; if (!title) { title = ; } else if (title.length > 30) { // FIXME: this is probably wrong for RTL languages. title = title.substring(0, 28) + '…'; } const online = this.props.now ? 'online' : 'offline'; const avatar = this.props.avatar ? this.props.avatar : true; const badges = this.props.badges ? this.props.badges.slice() : []; const icon_badges = []; if (this.props.isVerified) { icon_badges.push({icon: 'verified', color: 'verified-color'}); } if (this.props.isStaff) { icon_badges.push({icon: 'staff', color: 'staff-color'}); } if (this.props.isDangerous) { icon_badges.push({icon: 'dangerous', color: 'danger-color'}); } if (this.props.acs) { if (this.props.showMode) { badges.push({name: this.props.acs.getMode(), key: 'mode'}); } if (this.props.acs.isMuted()) { icon_badges.push({icon: 'muted'}); } if (!this.props.acs.isJoiner()) { icon_badges.push({icon: 'banned'}); } } // The this.props.preview contains alreay shortened Drafty or string. let preview; if (typeof this.props.preview == 'string') { preview = this.props.preview; } else if (Drafty.isValid(this.props.preview)) { preview = React.createElement(React.Fragment, null, Drafty.format(this.props.preview, previewFormatter, {formatMessage: this.props.intl.formatMessage, previewIsResponse: this.props.previewIsResponse})); } else if (this.props.preview) { preview = <>warning_amber ; } const icon = deliveryMarker(this.props.received); const marker = icon ? {icon.name} : null; const titleClass = 'contact-title' + (this.props.deleted ? ' deleted' : ''); return (
  • {this.props.deleted ? cancel : this.props.showOnline ? : (this.props.showCheckmark && this.props.selected) ? check_circle : null}
    {title} {this.props.isChannel ? channel : null} {!this.props.deleted ? : null}
    {this.props.showMode ? : this.props.small ? null :
    {marker}{preview || this.props.comment || '\u00A0'}
    }
    {this.props.showContextMenu ? expand_more : null}
  • ); } }; export default injectIntl(Contact);