import _ from 'underscore'; import classnames from 'classnames'; import { React, PropTypes, Actions } from 'mailspring-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: PropTypes.array, cc: PropTypes.array, bcc: PropTypes.array, from: PropTypes.array, onClick: PropTypes.func, isDetailed: 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) { let names = contacts.map(c => c.displayName({ includeAccountLabel: true, compact: true })); if (names.length > max) { const 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(AppEnv.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 (