Mailspring/internal_packages/thread-list/lib/thread-list-participants.cjsx
Ben Gotow d9ee12cf81 refactor(*): Thread list fixes, flexible workspace store, multiple root sheets
Summary:
Remember to remove all the event listeners added to email frame

New files tab, queryable filename, not attribute

Rename ThreadSelectionBar to RootSelectionBar to go with RootCenterComponent, make it appear for draft selection and file selection as well

Initial file list and file list store, File Location

Remove unnecessary shouldComponentUpdate

Always track whether new requests have happened since ours to prevent out of order triggers

Always scroll to the current [focused/keyboard-cursor] in lists

So goodbye to the trash tag

Only scroll to current item if focus or keyboard has moved

Show message snippet in notification if no subject line

Make the RootSelectionBar pull items from Component Registry

New Archive button (prettier than the other one)

Refactor event additions to iframe so iframe can be used for file display also

Thread List is no longer the uber root package - drafts and files moved to separate packages

WorkspaceStore now allows packages to register sheets, "view" concept replaced with "root sheet" concept, "mode" may not be observed by all sheets, and is now called "preferred mode"

Don't animate transitions between two root sheets

Mode switch is only visible on root sheets that support multiple modes

Account sidebar now shows "Views" that have registered themselves: drafts and files for now

Model Selection Bar is now a component, just like ModelList. Meant to be in the toolbar above a Model List

Misc supporting changes

New files package which registers it's views and components

Rename files package to `file-list`

Move checkmark column down into model list

Don't throw exception if shift-down arrow and nothing selected

Takes a long time on login to fetch first page of threads, make pages smaller

Displaynames, spec fixes

Test Plan: Run tests

Reviewers: evan

Reviewed By: evan

Differential Revision: https://review.inboxapp.com/D1412
2015-04-10 14:33:05 -07:00

104 lines
2.8 KiB
CoffeeScript

React = require 'react'
_ = require 'underscore-plus'
{NamespaceStore} = require 'inbox-exports'
module.exports =
ThreadListParticipants = React.createClass
displayName: 'ThreadListParticipants'
propTypes:
thread: React.PropTypes.object.isRequired
render: ->
items = @getParticipants()
spans = []
accumulated = null
accumulatedUnread = false
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
if spacer
accumulate('...')
else
if contact.name.length > 0
if items.length > 1
short = contact.displayFirstName()
else
short = contact.displayName()
else
short = contact.email
if idx < items.length-1 and not items[idx+1].spacer
short += ", "
accumulate(short, unread)
if @props.thread.metadata and @props.thread.metadata.length > 1
accumulate(" (#{@props.thread.metadata.length})")
flush()
<div className="participants">
{spans}
</div>
getParticipants: ->
if @props.thread.metadata
list = []
last = null
for msg in @props.thread.metadata
from = msg.from[0]
if from and from.email isnt last
list.push({
contact: msg.from[0]
unread: msg.unread
})
last = from.email
else
list = @props.thread.participants
return [] unless list and list instanceof Array
me = NamespaceStore.current().emailAddress
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.
if list.length is 0 and @props.thread.participants.length > 0
list.push(@props.thread.participants[0])
# Change the list to have the appropriate output format
list = list.map (contact) ->
contact: contact
unread: false # We don't have the data.
# 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