import React from 'react'; import { ListTabular, RetinaImg, MailLabelSet, MailImportantIcon, InjectedComponent, InjectedComponentSet, } from 'mailspring-component-kit'; import { localized, FocusedPerspectiveStore, Utils, DateUtils } from 'mailspring-exports'; import { ThreadArchiveQuickAction, ThreadTrashQuickAction } from './thread-list-quick-actions'; import ThreadListParticipants from './thread-list-participants'; import ThreadListIcon from './thread-list-icon'; // Get and format either last sent or last received timestamp depending on thread-list being viewed const ThreadListTimestamp = function({ thread }) { const rawTimestamp = FocusedPerspectiveStore.current().isSent() ? thread.lastMessageSentTimestamp : thread.lastMessageReceivedTimestamp; const timestamp = rawTimestamp ? DateUtils.shortTimeString(rawTimestamp) : localized('No Date'); return {timestamp}; }; ThreadListTimestamp.containerRequired = false; const subject = function(subj) { if ((subj || '').trim().length === 0) { return {localized('(No Subject)')}; } else if (subj.split(/([\uD800-\uDBFF][\uDC00-\uDFFF])/g).length > 1) { const subjComponents = []; const subjParts = subj.split(/([\uD800-\uDBFF][\uDC00-\uDFFF])/g); for (let idx = 0; idx < subjParts.length; idx++) { const part = subjParts[idx]; if (part.match(/([\uD800-\uDBFF][\uDC00-\uDFFF])/g)) { subjComponents.push( {part} ); } else { subjComponents.push({part}); } } return subjComponents; } else { return subj; } }; const getSnippet = function(thread) { const messages = thread.__messages || []; if (messages.length === 0) { return thread.snippet; } for (let ii = messages.length - 1; ii >= 0; ii--) { if (messages[ii].snippet) return messages[ii].snippet; } return null; }; const c1 = new ListTabular.Column({ name: '★', resolver: thread => { return [ , , , ]; }, }); const c2 = new ListTabular.Column({ name: 'Participants', width: 200, resolver: thread => { const hasDraft = (thread.__messages || []).find(m => m.draft); if (hasDraft) { return (
); } else { return ; } }, }); const c3 = new ListTabular.Column({ name: 'Message', flex: 4, resolver: thread => { let attachment: JSX.Element = null; const messages = thread.__messages || []; const hasAttachments = thread.attachmentCount > 0 && messages.find(m => Utils.showIconForAttachments(m.files)); if (hasAttachments) { attachment =
; } return ( {subject(thread.subject)} {getSnippet(thread)} {attachment} ); }, }); const c4 = new ListTabular.Column({ name: 'Date', resolver: thread => { return ( ); }, }); const c5 = new ListTabular.Column({ name: 'HoverActions', resolver: thread => { return (
, , ]} matching={{ role: 'ThreadListQuickAction' }} className="thread-injected-quick-actions" exposedProps={{ thread: thread }} />
); }, }); const cNarrow = new ListTabular.Column({ name: 'Item', flex: 1, resolver: thread => { let pencil: JSX.Element = null; let attachment: JSX.Element = null; const messages = thread.__messages || []; const hasAttachments = thread.attachmentCount > 0 && messages.find(m => Utils.showIconForAttachments(m.files)); if (hasAttachments) { attachment =
; } const hasDraft = messages.find(m => m.draft); if (hasDraft) { pencil = ( ); } // TODO We are limiting the amount on injected icons in narrow mode to 1 // until we revisit the UI to accommodate more icons return (
{pencil} {attachment}
{subject(thread.subject)}
{getSnippet(thread)} 
); }, }); export const Narrow = [cNarrow]; export const Wide = [c1, c2, c3, c4, c5];