_ = require 'underscore'
React = require 'react'
classNames = require 'classnames'
{ListTabular, MultiselectList} = require 'nylas-component-kit'
{timestamp, subject} = require './formatting-utils'
{Actions,
Utils,
Thread,
WorkspaceStore,
NamespaceStore} = require 'nylas-exports'
ThreadListParticipants = require './thread-list-participants'
ThreadListStore = require './thread-list-store'
class ThreadList extends React.Component
@displayName: 'ThreadList'
@containerRequired: false
componentWillMount: =>
labelComponents = (thread) =>
for label in @state.threadLabelComponents
LabelComponent = label.view
lastMessageType = (thread) ->
myEmail = NamespaceStore.current()?.emailAddress
msgs = thread.metadata
return 'unknown' unless msgs and msgs instanceof Array
msgs = _.filter msgs, (m) -> m.isSaved()
msg = msgs[msgs.length - 1]
return 'unknown' unless msgs.length > 0
if thread.unread
return 'unread'
else if msg.from[0]?.email isnt myEmail or msgs.length is 1
return 'other'
else if Utils.isForwardedMessage(msg)
return 'forwarded'
else
return 'replied'
c1 = new ListTabular.Column
name: "★"
resolver: (thread) =>
c2 = new ListTabular.Column
name: "Name"
width: 200
resolver: (thread) =>
c3 = new ListTabular.Column
name: "Message"
flex: 4
resolver: (thread) =>
attachments = []
if thread.hasTagId('attachment')
attachments =
{subject(thread.subject)}
{thread.snippet}
{attachments}
c4 = new ListTabular.Column
name: "Date"
resolver: (thread) =>
{timestamp(thread.lastMessageTimestamp)}
@columns = [c1, c2, c3, c4]
@commands =
'core:remove-item': @_onArchive
'core:remove-and-previous': -> Actions.archiveAndPrevious()
'core:remove-and-next': -> Actions.archiveAndNext()
'application:reply': @_onReply
'application:reply-all': @_onReplyAll
'application:forward': @_onForward
@itemPropsProvider = (item) ->
className: classNames
'unread': item.isUnread()
render: =>
# Additional Commands
_onArchive: =>
if @_viewingFocusedThread() or ThreadListStore.view().selection.count() is 0
Actions.archive()
else
Actions.archiveSelection()
_onReply: ({focusedId}) =>
return unless focusedId? and @_viewingFocusedThread()
Actions.composeReply(threadId: focusedId)
_onReplyAll: ({focusedId}) =>
return unless focusedId? and @_viewingFocusedThread()
Actions.composeReplyAll(threadId: focusedId)
_onForward: ({focusedId}) =>
return unless focusedId? and @_viewingFocusedThread()
Actions.composeForward(threadId: focusedId)
# Helpers
_viewingFocusedThread: =>
if WorkspaceStore.layoutMode() is "list"
WorkspaceStore.topSheet() is WorkspaceStore.Sheet.Thread
else
true
module.exports = ThreadList