2015-03-10 09:25:53 +08:00
|
|
|
_ = require 'underscore-plus'
|
|
|
|
React = require 'react'
|
2015-03-26 02:17:57 +08:00
|
|
|
{ListTabular, Spinner} = require 'ui-components'
|
2015-03-10 09:25:53 +08:00
|
|
|
{timestamp, subject} = require './formatting-utils'
|
2015-03-26 02:17:57 +08:00
|
|
|
{Actions,
|
2015-03-26 03:41:48 +08:00
|
|
|
Utils,
|
2015-03-26 02:17:57 +08:00
|
|
|
ThreadStore,
|
|
|
|
WorkspaceStore,
|
2015-03-26 03:41:48 +08:00
|
|
|
NamespaceStore} = require 'inbox-exports'
|
|
|
|
|
|
|
|
ThreadListParticipants = require './thread-list-participants'
|
2015-03-10 09:25:53 +08:00
|
|
|
|
|
|
|
module.exports =
|
|
|
|
ThreadList = React.createClass
|
|
|
|
displayName: 'ThreadList'
|
|
|
|
|
|
|
|
getInitialState: ->
|
|
|
|
@_getStateFromStores()
|
|
|
|
|
|
|
|
componentDidMount: ->
|
|
|
|
@thread_store_unsubscribe = ThreadStore.listen @_onChange
|
|
|
|
@thread_unsubscriber = atom.commands.add '.thread-list', {
|
|
|
|
'thread-list:star-thread': => @_onStarThread()
|
|
|
|
}
|
|
|
|
@body_unsubscriber = atom.commands.add 'body', {
|
|
|
|
'application:previous-item': => @_onShiftSelectedIndex(-1)
|
|
|
|
'application:next-item': => @_onShiftSelectedIndex(1)
|
2015-03-21 01:23:50 +08:00
|
|
|
'application:focus-item': => @_onFocusSelectedIndex()
|
2015-03-26 02:17:57 +08:00
|
|
|
'application:remove-item': @_onArchiveCurrentThread
|
|
|
|
'application:remove-and-previous': -> Actions.archiveAndPrevious()
|
|
|
|
'application:remove-and-next': -> Actions.archiveAndNext()
|
2015-03-10 09:25:53 +08:00
|
|
|
'application:reply': @_onReply
|
|
|
|
'application:reply-all': @_onReplyAll
|
|
|
|
'application:forward': @_onForward
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount: ->
|
|
|
|
@thread_store_unsubscribe()
|
|
|
|
@thread_unsubscriber.dispose()
|
|
|
|
@body_unsubscriber.dispose()
|
|
|
|
|
|
|
|
render: ->
|
2015-03-26 02:17:57 +08:00
|
|
|
classes = React.addons.classSet("thread-list": true, "ready": @state.ready)
|
|
|
|
<div className={classes}>
|
2015-03-10 09:25:53 +08:00
|
|
|
<ListTabular
|
|
|
|
columns={@state.columns}
|
|
|
|
items={@state.items}
|
|
|
|
itemClassProvider={ (item) -> if item.isUnread() then 'unread' else '' }
|
|
|
|
selectedId={@state.selectedId}
|
|
|
|
onSelect={ (item) -> Actions.selectThreadId(item.id) } />
|
2015-03-26 02:17:57 +08:00
|
|
|
<Spinner visible={!@state.ready} />
|
2015-03-10 09:25:53 +08:00
|
|
|
</div>
|
2015-03-20 08:16:38 +08:00
|
|
|
|
2015-03-10 09:25:53 +08:00
|
|
|
_computeColumns: ->
|
2015-03-26 03:41:48 +08:00
|
|
|
myEmail = NamespaceStore.current()?.emailAddress
|
|
|
|
|
2015-03-10 09:25:53 +08:00
|
|
|
labelComponents = (thread) =>
|
|
|
|
for label in @state.threadLabelComponents
|
|
|
|
LabelComponent = label.view
|
|
|
|
<LabelComponent thread={thread} />
|
|
|
|
|
2015-03-26 03:41:48 +08:00
|
|
|
lastMessageType = (thread) ->
|
|
|
|
msgs = thread.messageMetadata
|
|
|
|
return 'unknown' unless msgs and msgs instanceof Array and msgs.length > 0
|
|
|
|
msg = msgs[msgs.length - 1]
|
|
|
|
if thread.unread
|
|
|
|
return 'unread'
|
|
|
|
else if msg.from[0].email isnt myEmail
|
|
|
|
return 'other'
|
|
|
|
else if Utils.isForwardedMessage(msg)
|
|
|
|
return 'forwarded'
|
2015-03-10 09:25:53 +08:00
|
|
|
else
|
2015-03-26 03:41:48 +08:00
|
|
|
return 'replied'
|
2015-03-10 09:25:53 +08:00
|
|
|
|
2015-03-26 03:41:48 +08:00
|
|
|
c1 = new ListTabular.Column
|
2015-03-10 09:25:53 +08:00
|
|
|
name: "★"
|
|
|
|
resolver: (thread) ->
|
2015-03-26 03:41:48 +08:00
|
|
|
<div className="thread-icon thread-icon-#{lastMessageType(thread)}"></div>
|
2015-03-10 09:25:53 +08:00
|
|
|
|
2015-03-26 03:41:48 +08:00
|
|
|
c2 = new ListTabular.Column
|
2015-03-10 09:25:53 +08:00
|
|
|
name: "Name"
|
2015-03-26 09:22:52 +08:00
|
|
|
width: 200
|
2015-03-26 04:01:22 +08:00
|
|
|
resolver: (thread) ->
|
2015-03-26 03:41:48 +08:00
|
|
|
<ThreadListParticipants thread={thread} />
|
2015-03-10 09:25:53 +08:00
|
|
|
|
|
|
|
c3 = new ListTabular.Column
|
2015-03-26 03:41:48 +08:00
|
|
|
name: "Message"
|
2015-03-10 09:25:53 +08:00
|
|
|
flex: 4
|
|
|
|
resolver: (thread) ->
|
2015-03-26 03:41:48 +08:00
|
|
|
attachments = []
|
|
|
|
if thread.hasTagId('attachment')
|
|
|
|
attachments = <div className="thread-icon thread-icon-attachment"></div>
|
|
|
|
<span className="details">
|
|
|
|
<span className="subject">{subject(thread.subject)}</span>
|
|
|
|
<span className="snippet">{thread.snippet}</span>
|
|
|
|
{attachments}
|
|
|
|
</span>
|
2015-03-10 09:25:53 +08:00
|
|
|
|
|
|
|
c4 = new ListTabular.Column
|
|
|
|
name: "Date"
|
|
|
|
resolver: (thread) ->
|
|
|
|
<span className="timestamp">{timestamp(thread.lastMessageTimestamp)}</span>
|
|
|
|
|
|
|
|
[c1, c2, c3, c4]
|
|
|
|
|
2015-03-21 01:23:50 +08:00
|
|
|
_onFocusSelectedIndex: ->
|
|
|
|
Actions.selectThreadId(@state.selectedId)
|
|
|
|
|
2015-03-10 09:25:53 +08:00
|
|
|
_onShiftSelectedIndex: (delta) ->
|
|
|
|
item = _.find @state.items, (thread) => thread.id == @state.selectedId
|
|
|
|
index = if item then @state.items.indexOf(item) else -1
|
|
|
|
index = Math.max(0, Math.min(index + delta, @state.items.length-1))
|
|
|
|
Actions.selectThreadId(@state.items[index].id)
|
|
|
|
|
|
|
|
_onStarThread: ->
|
|
|
|
thread = ThreadStore.selectedThread()
|
|
|
|
thread.toggleStar() if thread
|
|
|
|
|
|
|
|
_onReply: ->
|
2015-03-26 02:17:57 +08:00
|
|
|
return unless @state.selectedId? and @_actionInVisualScope()
|
2015-03-10 09:25:53 +08:00
|
|
|
Actions.composeReply(threadId: @state.selectedId)
|
|
|
|
|
|
|
|
_onReplyAll: ->
|
2015-03-26 02:17:57 +08:00
|
|
|
return unless @state.selectedId? and @_actionInVisualScope()
|
2015-03-10 09:25:53 +08:00
|
|
|
Actions.composeReplyAll(threadId: @state.selectedId)
|
|
|
|
|
|
|
|
_onForward: ->
|
2015-03-26 02:17:57 +08:00
|
|
|
return unless @state.selectedId? and @_actionInVisualScope()
|
2015-03-10 09:25:53 +08:00
|
|
|
Actions.composeForward(threadId: @state.selectedId)
|
2015-03-26 02:17:57 +08:00
|
|
|
|
|
|
|
_actionInVisualScope: ->
|
|
|
|
if WorkspaceStore.selectedLayoutMode() is "list"
|
|
|
|
WorkspaceStore.sheet().type is "Thread"
|
|
|
|
else true
|
|
|
|
|
|
|
|
_onArchiveCurrentThread: ->
|
|
|
|
if WorkspaceStore.selectedLayoutMode() is "list"
|
|
|
|
Actions.archiveCurrentThread()
|
|
|
|
else if WorkspaceStore.selectedLayoutMode() is "split"
|
|
|
|
Actions.archiveAndNext()
|
|
|
|
|
2015-03-10 09:25:53 +08:00
|
|
|
_onChange: ->
|
|
|
|
@setState(@_getStateFromStores())
|
|
|
|
|
|
|
|
_getStateFromStores: ->
|
2015-03-26 02:17:57 +08:00
|
|
|
ready: not ThreadStore.itemsLoading()
|
2015-03-10 09:25:53 +08:00
|
|
|
items: ThreadStore.items()
|
|
|
|
columns: @_computeColumns()
|
|
|
|
selectedId: ThreadStore.selectedId()
|