2015-06-09 08:02:50 +08:00
|
|
|
_ = require 'underscore'
|
|
|
|
React = require 'react'
|
|
|
|
{Actions,
|
|
|
|
Utils,
|
|
|
|
Thread,
|
2015-07-16 23:54:20 +08:00
|
|
|
UpdateThreadsTask,
|
2015-06-09 08:02:50 +08:00
|
|
|
NamespaceStore} = require 'nylas-exports'
|
|
|
|
|
|
|
|
class ThreadListIcon extends React.Component
|
|
|
|
@displayName: 'ThreadListIcon'
|
|
|
|
@propTypes:
|
|
|
|
thread: React.PropTypes.object
|
|
|
|
|
|
|
|
_iconType: =>
|
2015-06-20 02:31:27 +08:00
|
|
|
if !@props.thread
|
|
|
|
return 'thread-icon-star-on-hover'
|
2015-06-09 08:02:50 +08:00
|
|
|
|
2015-07-16 23:54:20 +08:00
|
|
|
if @props.thread.starred
|
2015-06-09 08:02:50 +08:00
|
|
|
return 'thread-icon-star'
|
2015-06-10 01:35:21 +08:00
|
|
|
|
|
|
|
if @props.thread.unread
|
2015-06-09 08:02:50 +08:00
|
|
|
return 'thread-icon-unread thread-icon-star-on-hover'
|
2015-06-10 01:35:21 +08:00
|
|
|
|
|
|
|
msgs = @_nonDraftMessages()
|
|
|
|
last = msgs[msgs.length - 1]
|
|
|
|
|
2015-06-20 02:31:27 +08:00
|
|
|
myEmail = NamespaceStore.current()?.emailAddress
|
2015-06-10 01:35:21 +08:00
|
|
|
if msgs.length > 1 and last.from[0]?.email is myEmail
|
|
|
|
if Utils.isForwardedMessage(last)
|
|
|
|
return 'thread-icon-forwarded thread-icon-star-on-hover'
|
|
|
|
else
|
|
|
|
return 'thread-icon-replied thread-icon-star-on-hover'
|
|
|
|
|
|
|
|
return 'thread-icon-star-on-hover'
|
|
|
|
|
|
|
|
_nonDraftMessages: =>
|
|
|
|
msgs = @props.thread.metadata
|
|
|
|
return [] unless msgs and msgs instanceof Array
|
|
|
|
msgs = _.filter msgs, (m) -> m.isSaved() and not m.draft
|
|
|
|
return msgs
|
2015-06-09 08:02:50 +08:00
|
|
|
|
|
|
|
render: =>
|
|
|
|
<div className="thread-icon #{@_iconType()}" onClick={@_onToggleStar}></div>
|
|
|
|
|
|
|
|
_onToggleStar: (event) =>
|
2015-07-16 23:54:20 +08:00
|
|
|
values = starred: (not @props.thread.starred)
|
|
|
|
task = new UpdateThreadsTask([@props.thread], values)
|
|
|
|
Actions.queueTask(task)
|
2015-06-09 08:02:50 +08:00
|
|
|
|
|
|
|
# Don't trigger the thread row click
|
|
|
|
event.stopPropagation()
|
|
|
|
|
|
|
|
module.exports = ThreadListIcon
|