2015-03-26 03:41:48 +08:00
|
|
|
React = require 'react'
|
2015-05-20 07:06:59 +08:00
|
|
|
_ = require 'underscore'
|
2015-05-15 08:08:30 +08:00
|
|
|
{NamespaceStore} = require 'nylas-exports'
|
2015-03-26 03:41:48 +08:00
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
class ThreadListParticipants extends React.Component
|
|
|
|
@displayName: 'ThreadListParticipants'
|
2015-03-26 03:41:48 +08:00
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
@propTypes:
|
2015-03-26 03:41:48 +08:00
|
|
|
thread: React.PropTypes.object.isRequired
|
2015-05-02 03:58:25 +08:00
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
render: =>
|
2015-03-26 03:41:48 +08:00
|
|
|
items = @getParticipants()
|
|
|
|
|
2015-04-07 02:46:20 +08:00
|
|
|
spans = []
|
|
|
|
accumulated = null
|
|
|
|
accumulatedUnread = false
|
2015-03-26 03:41:48 +08:00
|
|
|
|
2015-04-07 02:46:20 +08:00
|
|
|
flush = ->
|
|
|
|
if accumulated
|
|
|
|
spans.push <span key={spans.length} className="unread-#{accumulatedUnread}">{accumulated}</span>
|
|
|
|
accumulated = null
|
|
|
|
accumulatedUnread = false
|
|
|
|
|
|
|
|
accumulate = (text, unread) ->
|
|
|
|
if accumulated and unread and accumulatedUnread isnt unread
|
|
|
|
flush()
|
|
|
|
if accumulated
|
|
|
|
accumulated += text
|
|
|
|
else
|
|
|
|
accumulated = text
|
|
|
|
accumulatedUnread = unread
|
|
|
|
|
|
|
|
for {spacer, contact, unread}, idx in items
|
2015-03-28 07:34:59 +08:00
|
|
|
if spacer
|
2015-04-07 02:46:20 +08:00
|
|
|
accumulate('...')
|
2015-03-26 03:41:48 +08:00
|
|
|
else
|
2015-03-28 07:34:59 +08:00
|
|
|
if contact.name.length > 0
|
2015-03-26 03:41:48 +08:00
|
|
|
if items.length > 1
|
2015-03-28 07:34:59 +08:00
|
|
|
short = contact.displayFirstName()
|
2015-03-26 03:41:48 +08:00
|
|
|
else
|
2015-03-28 07:34:59 +08:00
|
|
|
short = contact.displayName()
|
2015-03-26 03:41:48 +08:00
|
|
|
else
|
2015-03-28 07:34:59 +08:00
|
|
|
short = contact.email
|
2015-03-26 03:41:48 +08:00
|
|
|
if idx < items.length-1 and not items[idx+1].spacer
|
|
|
|
short += ", "
|
2015-04-07 02:46:20 +08:00
|
|
|
accumulate(short, unread)
|
|
|
|
|
|
|
|
if @props.thread.metadata and @props.thread.metadata.length > 1
|
|
|
|
accumulate(" (#{@props.thread.metadata.length})")
|
|
|
|
|
|
|
|
flush()
|
2015-03-26 03:41:48 +08:00
|
|
|
|
|
|
|
<div className="participants">
|
2015-04-07 02:46:20 +08:00
|
|
|
{spans}
|
2015-03-26 03:41:48 +08:00
|
|
|
</div>
|
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
getParticipants: =>
|
2015-04-07 02:46:20 +08:00
|
|
|
if @props.thread.metadata
|
2015-03-26 03:41:48 +08:00
|
|
|
list = []
|
|
|
|
last = null
|
2015-04-07 02:46:20 +08:00
|
|
|
for msg in @props.thread.metadata
|
feat(*): draft icon, misc fixes, and WorkspaceStore / custom toolbar in secondary windows
Summary:
Features:
- ThreadListParticipants ignores drafts when computing participants, renders "Draft" label, pending design
- Put the WorkspaceStore in every window—means they all get toolbars and custom gumdrop icons on Mac OS X
Bug Fixes:
- Never display notifications for email the user just sent
- Fix obscure issue with DatabaseView trying to update metadata on items it froze. This resolves issue with names remaining bold after marking as read, drafts not appearing in message list immediately.
- When you pop out a draft, save it first and *wait* for the commit() promise to succeed.
- If you scroll very fast, you node.contentWindow can be null in eventedIframe
Other:
Make it OK to re-register the same component
Make it possible to unregister a hot window
Break the Sheet Toolbar out into it's own file to make things manageable
Replace `package.windowPropsReceived` with a store-style model where anyone can listen for changes to `windowProps`
When I put the WorkspaceStore in every window, I ran into a problem because the package was no longer rendering an instance of the Composer, it was declaring a root sheet with a composer in it. This meant that it was actually a React component that needed to listen to window props, not the package itself.
`atom` is already an event emitter, so I added a `onWindowPropsReceived` hook so that components can listen to window props as if they were listening to a store. I think this might be more flexible than only broadcasting the props change event to packages.
Test Plan: Run tests
Reviewers: evan
Reviewed By: evan
Differential Revision: https://phab.nylas.com/D1592
2015-06-04 07:02:19 +08:00
|
|
|
continue if msg.draft
|
2015-03-26 03:41:48 +08:00
|
|
|
from = msg.from[0]
|
2015-03-28 07:34:59 +08:00
|
|
|
if from and from.email isnt last
|
|
|
|
list.push({
|
|
|
|
contact: msg.from[0]
|
|
|
|
unread: msg.unread
|
|
|
|
})
|
2015-03-26 03:41:48 +08:00
|
|
|
last = from.email
|
|
|
|
|
|
|
|
else
|
|
|
|
list = @props.thread.participants
|
|
|
|
return [] unless list and list instanceof Array
|
|
|
|
me = NamespaceStore.current().emailAddress
|
2015-03-26 09:22:52 +08:00
|
|
|
list = _.reject list, (p) -> p.email is me
|
|
|
|
|
|
|
|
# Removing "Me" may remove "Me" several times due to the way
|
|
|
|
# participants is created. If we're left with an empty array,
|
|
|
|
# put one a "Me" back in.
|
2015-04-07 02:46:20 +08:00
|
|
|
if list.length is 0 and @props.thread.participants.length > 0
|
2015-03-26 09:22:52 +08:00
|
|
|
list.push(@props.thread.participants[0])
|
2015-03-26 03:41:48 +08:00
|
|
|
|
2015-03-31 02:21:23 +08:00
|
|
|
# Change the list to have the appropriate output format
|
|
|
|
list = list.map (contact) ->
|
|
|
|
contact: contact
|
|
|
|
unread: false # We don't have the data.
|
|
|
|
|
2015-03-26 03:41:48 +08:00
|
|
|
# We only ever want to show three. Ben...Kevin... Marty
|
|
|
|
# But we want the *right* three.
|
|
|
|
if list.length > 3
|
|
|
|
listTrimmed = []
|
|
|
|
|
|
|
|
# Always include the first item
|
|
|
|
listTrimmed.push(list[0])
|
|
|
|
listTrimmed.push({spacer: true})
|
|
|
|
|
|
|
|
# Always include the last two item
|
|
|
|
listTrimmed.push(list[list.length - 2])
|
|
|
|
listTrimmed.push(list[list.length - 1])
|
|
|
|
list = listTrimmed
|
|
|
|
|
|
|
|
list
|
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
|
|
|
|
module.exports = ThreadListParticipants
|