import _ from 'underscore'; import React from "react"; import classnames from 'classnames'; import{Actions, Contact} from 'nylas-exports'; import {remote} from 'electron'; const {Menu, MenuItem} = remote; const MAX_COLLAPSED = 5; export default class MessageParticipants extends React.Component { static displayName = 'MessageParticipants'; static propTypes = { to: React.PropTypes.array, cc: React.PropTypes.array, bcc: React.PropTypes.array, from: React.PropTypes.array, onClick: React.PropTypes.func, isDetailed: React.PropTypes.bool, }; static defaultProps = { to: [], cc: [], bcc: [], from: [], }; // Helpers _allToParticipants() { return _.union(this.props.to, this.props.cc, this.props.bcc) } _shortNames(contacts = [], max = MAX_COLLAPSED) { const names = contacts.map((c) => c.displayName({includeAccountLabel: true, compact: true}) ); if (names.length > max) { extra = names.length - max; names = names.slice(0, max); names.push(`and ${extra} more`); } return names.join(", "); } _onSelectText = (e) => { const textNode = e.currentTarget.childNodes[0]; const range = document.createRange(); range.setStart(textNode, 0); range.setEnd(textNode, textNode.length); const selection = document.getSelection(); selection.removeAllRanges(); selection.addRange(range); } _onContactContextMenu = (contact) => { const menu = new Menu(); menu.append(new MenuItem({role: 'copy'})); menu.append(new MenuItem({ label: `Email ${contact.email}`, click: () => Actions.composeNewDraftToRecipient(contact) })); menu.popup(NylasEnv.getCurrentWindow()); } _renderFullContacts(contacts = []) { return contacts.map((c, i) => { let comma = ","; if ((contacts.length === 1) || (i === contacts.length - 1)) { comma = ""; } if (c.name && c.name.length > 0 && c.name !== c.email) { return (