-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathmessage-participants.cjsx
148 lines (120 loc) · 4.02 KB
/
message-participants.cjsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
_ = require 'underscore'
React = require "react"
classnames = require 'classnames'
{Contact} = require 'nylas-exports'
MAX_COLLAPSED = 5
class MessageParticipants extends React.Component
@displayName: 'MessageParticipants'
@propTypes:
to: React.PropTypes.array
cc: React.PropTypes.array
bcc: React.PropTypes.array
from: React.PropTypes.array
onClick: React.PropTypes.func
isDetailed: React.PropTypes.bool
@defaultProps:
to: []
cc: []
bcc: []
from: []
# Helpers
_allToParticipants: =>
_.union(@props.to, @props.cc, @props.bcc)
_selectText: (e) =>
textNode = e.currentTarget.childNodes[0]
range = document.createRange()
range.setStart(textNode, 0)
range.setEnd(textNode, textNode.length)
selection = document.getSelection()
selection.removeAllRanges()
selection.addRange(range)
_shortNames: (contacts = [], max = MAX_COLLAPSED) =>
isCompact = not NylasEnv.config.get('core.reading.useLongDisplayNames')
names = _.map(contacts, (c) -> c.displayName(includeAccountLabel: true, compact: isCompact))
if names.length > max
extra = names.length - max
names = names.slice(0, max)
names.push("and #{extra} more")
names.join(", ")
# Renderers
_renderFullContacts: (contacts = []) =>
_.map(contacts, (c, i) =>
if contacts.length is 1 then comma = ""
else if i is contacts.length-1 then comma = ""
else comma = ","
if c.name?.length > 0 and c.name isnt c.email
<div key={"#{c.email}-#{i}"} className="participant selectable">
<div className="participant-primary" onClick={@_selectText}>
{c.fullName()}
</div>
<div className="participant-secondary">
{"<"}<span onClick={@_selectText}>{c.email}</span>{">#{comma}"}
</div>
</div>
else
<div key={"#{c.email}-#{i}"} className="participant selectable">
<div className="participant-primary">
<span onClick={@_selectText}>{c.email}</span>{comma}
</div>
</div>
)
_renderExpandedField: (name, field, {includeLabel} = {}) =>
includeLabel ?= true
<div className="participant-type" key={"participant-type-#{name}"}>
{
if includeLabel
<div className={"participant-label #{name}-label"}>{name}: </div>
else
undefined
}
<div className={"participant-name #{name}-contact"}>
{@_renderFullContacts(field)}
</div>
</div>
_renderExpanded: =>
expanded = []
if @props.from.length > 0
expanded.push(
@_renderExpandedField('from', @props.from, includeLabel: false)
)
if @props.to.length > 0
expanded.push(
@_renderExpandedField('to', @props.to)
)
if @props.cc.length > 0
expanded.push(
@_renderExpandedField('cc', @props.cc)
)
if @props.bcc.length > 0
expanded.push(
@_renderExpandedField('bcc', @props.bcc)
)
<div className="expanded-participants">
{expanded}
</div>
_renderCollapsed: =>
childSpans = []
toParticipants = @_allToParticipants()
if @props.from.length > 0
childSpans.push(
<span className="participant-name from-contact" key="from">{@_shortNames(@props.from)}</span>
)
if toParticipants.length > 0
childSpans.push(
<span className="participant-label to-label" key="to-label">To: </span>
<span className="participant-name to-contact" key="to-value">{@_shortNames(toParticipants)}</span>
)
<span className="collapsed-participants">
{childSpans}
</span>
render: =>
classSet = classnames
"participants": true
"message-participants": true
"collapsed": not @props.isDetailed
"from-participants": @props.from.length > 0
"to-participants": @_allToParticipants().length > 0
<div className={classSet} onClick={@props.onClick}>
{if @props.isDetailed then @_renderExpanded() else @_renderCollapsed()}
</div>
module.exports = MessageParticipants