2016-01-15 06:04:51 +08:00
|
|
|
_ = require 'underscore'
|
|
|
|
React = require 'react'
|
|
|
|
classNames = require 'classnames'
|
2016-07-29 08:42:14 +08:00
|
|
|
moment = require 'moment'
|
2016-01-15 06:04:51 +08:00
|
|
|
|
|
|
|
{ListTabular,
|
|
|
|
RetinaImg,
|
2016-03-03 02:05:17 +08:00
|
|
|
MailLabelSet,
|
2016-01-15 06:04:51 +08:00
|
|
|
MailImportantIcon,
|
2016-10-14 00:43:20 +08:00
|
|
|
InjectedComponent,
|
2016-01-15 06:04:51 +08:00
|
|
|
InjectedComponentSet} = require 'nylas-component-kit'
|
|
|
|
|
2016-07-29 08:42:14 +08:00
|
|
|
{Thread, FocusedPerspectiveStore, Utils, DateUtils} = require 'nylas-exports'
|
2016-01-15 06:04:51 +08:00
|
|
|
|
|
|
|
{ThreadArchiveQuickAction,
|
|
|
|
ThreadTrashQuickAction} = require './thread-list-quick-actions'
|
|
|
|
|
|
|
|
ThreadListParticipants = require './thread-list-participants'
|
|
|
|
ThreadListStore = require './thread-list-store'
|
|
|
|
ThreadListIcon = require './thread-list-icon'
|
|
|
|
|
2016-07-29 08:42:14 +08:00
|
|
|
# Get and format either last sent or last received timestamp depending on thread-list being viewed
|
2016-10-14 00:43:20 +08:00
|
|
|
ThreadListTimestamp = ({thread}) ->
|
2016-03-10 03:40:35 +08:00
|
|
|
if FocusedPerspectiveStore.current().isSent()
|
2016-07-29 08:42:14 +08:00
|
|
|
rawTimestamp = thread.lastMessageSentTimestamp
|
2016-03-18 00:50:30 +08:00
|
|
|
else
|
2016-07-29 08:42:14 +08:00
|
|
|
rawTimestamp = thread.lastMessageReceivedTimestamp
|
|
|
|
timestamp = DateUtils.shortTimeString(rawTimestamp)
|
2016-10-14 00:43:20 +08:00
|
|
|
return <span className="timestamp">{timestamp}</span>
|
2016-11-02 02:39:38 +08:00
|
|
|
ThreadListTimestamp.containerRequired = false
|
2016-03-18 00:50:30 +08:00
|
|
|
|
|
|
|
subject = (subj) ->
|
|
|
|
if (subj ? "").trim().length is 0
|
|
|
|
return <span className="no-subject">(No Subject)</span>
|
2016-03-27 03:14:29 +08:00
|
|
|
else if subj.split(/([\uD800-\uDBFF][\uDC00-\uDFFF])/g).length > 1
|
|
|
|
subjComponents = []
|
|
|
|
subjParts = subj.split /([\uD800-\uDBFF][\uDC00-\uDFFF])/g
|
2016-09-21 08:28:50 +08:00
|
|
|
for part, idx in subjParts
|
2016-03-27 03:14:29 +08:00
|
|
|
if part.match /([\uD800-\uDBFF][\uDC00-\uDFFF])/g
|
2016-09-21 08:28:50 +08:00
|
|
|
subjComponents.push <span className="emoji" key={idx}>{part}</span>
|
2016-03-27 03:14:29 +08:00
|
|
|
else
|
2016-09-21 08:28:50 +08:00
|
|
|
subjComponents.push <span key={idx}>{part}</span>
|
2016-03-27 03:14:29 +08:00
|
|
|
return subjComponents
|
2016-03-10 03:40:35 +08:00
|
|
|
else
|
2016-03-18 00:50:30 +08:00
|
|
|
return subj
|
2016-03-10 03:40:35 +08:00
|
|
|
|
2016-10-14 00:43:20 +08:00
|
|
|
getSnippet = (thread) ->
|
|
|
|
messages = thread.__messages || []
|
|
|
|
if (messages.length is 0)
|
|
|
|
return thread.snippet
|
|
|
|
|
|
|
|
return messages[messages.length - 1].snippet
|
|
|
|
|
2016-01-15 06:04:51 +08:00
|
|
|
|
|
|
|
c1 = new ListTabular.Column
|
|
|
|
name: "★"
|
|
|
|
resolver: (thread) =>
|
|
|
|
[
|
|
|
|
<ThreadListIcon key="thread-list-icon" thread={thread} />
|
2016-01-29 08:44:44 +08:00
|
|
|
<MailImportantIcon
|
|
|
|
key="mail-important-icon"
|
|
|
|
thread={thread}
|
2016-10-14 00:43:20 +08:00
|
|
|
showIfAvailableForAnyAccount={true}
|
|
|
|
/>
|
2016-01-15 06:04:51 +08:00
|
|
|
<InjectedComponentSet
|
|
|
|
key="injected-component-set"
|
|
|
|
inline={true}
|
|
|
|
containersRequired={false}
|
|
|
|
matching={role: "ThreadListIcon"}
|
|
|
|
className="thread-injected-icons"
|
2016-10-14 00:43:20 +08:00
|
|
|
exposedProps={thread: thread}
|
|
|
|
/>
|
2016-01-15 06:04:51 +08:00
|
|
|
]
|
|
|
|
|
|
|
|
c2 = new ListTabular.Column
|
|
|
|
name: "Participants"
|
|
|
|
width: 200
|
|
|
|
resolver: (thread) =>
|
2016-10-14 00:43:20 +08:00
|
|
|
hasDraft = (thread.__messages || []).find((m) => m.draft)
|
2016-01-15 06:04:51 +08:00
|
|
|
if hasDraft
|
|
|
|
<div style={display: 'flex'}>
|
|
|
|
<ThreadListParticipants thread={thread} />
|
|
|
|
<RetinaImg name="icon-draft-pencil.png"
|
|
|
|
className="draft-icon"
|
|
|
|
mode={RetinaImg.Mode.ContentPreserve} />
|
|
|
|
</div>
|
|
|
|
else
|
|
|
|
<ThreadListParticipants thread={thread} />
|
|
|
|
|
|
|
|
c3 = new ListTabular.Column
|
|
|
|
name: "Message"
|
|
|
|
flex: 4
|
|
|
|
resolver: (thread) =>
|
2016-04-21 01:44:26 +08:00
|
|
|
attachment = false
|
2016-11-02 02:39:38 +08:00
|
|
|
messages = thread.__messages || []
|
2016-04-21 01:44:26 +08:00
|
|
|
|
2016-10-14 00:43:20 +08:00
|
|
|
hasAttachments = thread.hasAttachments and messages.find (m) -> Utils.showIconForAttachments(m.files)
|
2016-04-21 01:44:26 +08:00
|
|
|
if hasAttachments
|
2016-01-15 06:04:51 +08:00
|
|
|
attachment = <div className="thread-icon thread-icon-attachment"></div>
|
|
|
|
|
|
|
|
<span className="details">
|
2016-03-03 02:05:17 +08:00
|
|
|
<MailLabelSet thread={thread} />
|
2016-01-15 06:04:51 +08:00
|
|
|
<span className="subject">{subject(thread.subject)}</span>
|
2016-10-14 00:43:20 +08:00
|
|
|
<span className="snippet">{getSnippet(thread)}</span>
|
2016-01-15 06:04:51 +08:00
|
|
|
{attachment}
|
|
|
|
</span>
|
|
|
|
|
|
|
|
c4 = new ListTabular.Column
|
|
|
|
name: "Date"
|
|
|
|
resolver: (thread) =>
|
2016-11-02 02:39:38 +08:00
|
|
|
return (
|
|
|
|
<InjectedComponent
|
|
|
|
className="thread-injected-timestamp"
|
|
|
|
fallback={ThreadListTimestamp}
|
|
|
|
exposedProps={thread: thread}
|
|
|
|
matching={role: "ThreadListTimestamp"}
|
|
|
|
/>
|
|
|
|
)
|
2016-01-15 06:04:51 +08:00
|
|
|
|
|
|
|
c5 = new ListTabular.Column
|
|
|
|
name: "HoverActions"
|
|
|
|
resolver: (thread) =>
|
|
|
|
<div className="inner">
|
|
|
|
<InjectedComponentSet
|
|
|
|
key="injected-component-set"
|
|
|
|
inline={true}
|
|
|
|
containersRequired={false}
|
|
|
|
children=
|
|
|
|
{[
|
|
|
|
<ThreadTrashQuickAction key="thread-trash-quick-action" thread={thread} />
|
2016-02-05 06:14:24 +08:00
|
|
|
<ThreadArchiveQuickAction key="thread-archive-quick-action" thread={thread} />
|
2016-01-15 06:04:51 +08:00
|
|
|
]}
|
|
|
|
matching={role: "ThreadListQuickAction"}
|
|
|
|
className="thread-injected-quick-actions"
|
2016-10-14 00:43:20 +08:00
|
|
|
exposedProps={thread: thread}
|
|
|
|
/>
|
2016-01-15 06:04:51 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
cNarrow = new ListTabular.Column
|
|
|
|
name: "Item"
|
|
|
|
flex: 1
|
|
|
|
resolver: (thread) =>
|
2016-04-21 01:44:26 +08:00
|
|
|
pencil = false
|
|
|
|
attachment = false
|
2016-11-02 02:39:38 +08:00
|
|
|
messages = thread.__messages || []
|
2016-04-21 01:44:26 +08:00
|
|
|
|
2016-10-14 00:43:20 +08:00
|
|
|
hasAttachments = thread.hasAttachments and messages.find (m) -> Utils.showIconForAttachments(m.files)
|
2016-04-21 01:44:26 +08:00
|
|
|
if hasAttachments
|
2016-01-15 06:04:51 +08:00
|
|
|
attachment = <div className="thread-icon thread-icon-attachment"></div>
|
2016-04-21 01:44:26 +08:00
|
|
|
|
2016-10-14 00:43:20 +08:00
|
|
|
hasDraft = messages.find((m) => m.draft)
|
2016-01-15 06:04:51 +08:00
|
|
|
if hasDraft
|
|
|
|
pencil = <RetinaImg name="icon-draft-pencil.png" className="draft-icon" mode={RetinaImg.Mode.ContentPreserve} />
|
|
|
|
|
2016-03-25 03:32:01 +08:00
|
|
|
# TODO We are limiting the amount on injected icons in narrow mode to 1
|
|
|
|
# until we revisit the UI to accommodate more icons
|
2016-03-25 02:59:12 +08:00
|
|
|
<div style={display: 'flex', alignItems: 'flex-start'}>
|
|
|
|
<div className="icons-column">
|
2016-01-15 06:04:51 +08:00
|
|
|
<ThreadListIcon thread={thread} />
|
2016-03-25 02:59:12 +08:00
|
|
|
<InjectedComponentSet
|
|
|
|
inline={true}
|
2016-03-25 03:32:01 +08:00
|
|
|
matchLimit={1}
|
2016-03-25 02:59:12 +08:00
|
|
|
direction="column"
|
|
|
|
containersRequired={false}
|
2016-03-25 03:32:01 +08:00
|
|
|
key="injected-component-set"
|
|
|
|
exposedProps={thread: thread}
|
2016-03-25 02:59:12 +08:00
|
|
|
matching={role: "ThreadListIcon"}
|
|
|
|
className="thread-injected-icons"
|
|
|
|
/>
|
|
|
|
<MailImportantIcon
|
|
|
|
thread={thread}
|
|
|
|
showIfAvailableForAnyAccount={true}
|
|
|
|
/>
|
2016-01-15 06:04:51 +08:00
|
|
|
</div>
|
2016-03-25 02:59:12 +08:00
|
|
|
<div className="thread-info-column">
|
|
|
|
<div className="participants-wrapper">
|
|
|
|
<ThreadListParticipants thread={thread} />
|
|
|
|
{pencil}
|
|
|
|
<span style={flex:1}></span>
|
|
|
|
{attachment}
|
2016-10-14 00:43:20 +08:00
|
|
|
<InjectedComponent
|
|
|
|
key="thread-injected-timestamp"
|
|
|
|
className="thread-injected-timestamp"
|
|
|
|
fallback={ThreadListTimestamp}
|
|
|
|
exposedProps={thread: thread}
|
|
|
|
matching={role: "ThreadListTimestamp"}
|
|
|
|
/>
|
2016-03-25 02:59:12 +08:00
|
|
|
</div>
|
|
|
|
<div className="subject">{subject(thread.subject)}</div>
|
|
|
|
<div className="snippet-and-labels">
|
2016-10-14 00:43:20 +08:00
|
|
|
<div className="snippet">{getSnippet(thread)} </div>
|
2016-03-25 02:59:12 +08:00
|
|
|
<div style={flex: 1, flexShrink: 1}></div>
|
|
|
|
<MailLabelSet thread={thread} />
|
|
|
|
</div>
|
2016-02-12 07:24:33 +08:00
|
|
|
</div>
|
2016-01-15 06:04:51 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
module.exports =
|
|
|
|
Narrow: [cNarrow]
|
|
|
|
Wide: [c1, c2, c3, c4, c5]
|