fix(message): Re-write nasty code in participants()

This commit is contained in:
Ben Gotow 2016-04-20 17:47:40 -07:00
parent 8fb062f765
commit 476431bcb1

View file

@ -222,12 +222,15 @@ class Message extends ModelWithMetadata
# Public: Returns a set of uniqued message participants by combining the
# `to`, `cc`, and `from` fields.
participants: ->
participants = {}
contacts = _.union((@to ? []), (@cc ? []), (@from ? []))
for contact in contacts
if contact? and contact.email?.length > 0
participants["#{(contact?.email ? "").toLowerCase().trim()} #{(contact?.name ? "").toLowerCase().trim()}"] = contact if contact?
return _.values(participants)
seen = {}
all = []
for contact in [].concat(@to, @cc, @from)
continue unless contact.email
key = contact.toString().trim().toLowerCase()
continue if seen[key]
seen[key] = true
all.push(contact)
all
# Public: Returns a hash with `to` and `cc` keys for authoring a new draft in
# "reply all" to this message. This method takes into account whether the