fix(reply-all): Fix edge case where same person in CC/To causes error when replying-all

This commit is contained in:
Ben Gotow 2015-08-04 13:57:12 -07:00
parent b54bf9feaa
commit dc727f0867
2 changed files with 33 additions and 2 deletions

View file

@ -18,6 +18,7 @@ fakeMessage1 = null
fakeMessage2 = null
msgFromMe = null
msgWithReplyTo = null
msgWithReplyToDuplicates = null
fakeMessages = null
class TestExtension extends DraftStoreExtension
@ -77,11 +78,23 @@ describe "DraftStore", ->
subject: 'Re: Fake Subject'
date: new Date(1415814587)
msgWithReplyToDuplicates = new Message
id: 'fake-message-reply-to-duplicates'
to: [new Contact(email: '1@1.com'), new Contact(email: '2@2.com')]
cc: [new Contact(email: '1@1.com'), new Contact(email: '4@4.com')]
from: [new Contact(email: 'reply-to@5.com')]
replyTo: [new Contact(email: 'reply-to@5.com')]
threadId: 'fake-thread-id'
body: 'Fake Message Duplicates'
subject: 'Re: Fake Subject'
date: new Date(1415814587)
fakeMessages =
'fake-message-1': fakeMessage1
'fake-message-3': msgFromMe
'fake-message-2': fakeMessage2
'fake-message-reply-to': msgWithReplyTo
'fake-message-reply-to-duplicates': msgWithReplyToDuplicates
spyOn(DatabaseStore, 'find').andCallFake (klass, id) ->
query = new ModelQuery(klass, {id})
@ -197,6 +210,20 @@ describe "DraftStore", ->
match = _.find all, (c) -> c.email is msgWithReplyTo.from[0].email
expect(match).toEqual(undefined)
describe "onComposeReplyAll", ->
describe "when the message provided has one or more 'ReplyTo' recipients and duplicates in the To/Cc fields", ->
it "should unique the to/cc fields", ->
runs ->
DraftStore._onComposeReplyAll({threadId: fakeThread.id, messageId: msgWithReplyToDuplicates.id})
waitsFor ->
DatabaseStore.persistModel.callCount > 0
runs ->
model = DatabaseStore.persistModel.mostRecentCall.args[0]
ccEmails = model.cc.map (cc) -> cc.email
expect(ccEmails.sort()).toEqual(['1@1.com', '2@2.com', '4@4.com'])
toEmails = model.to.map (to) -> to.email
expect(toEmails.sort()).toEqual(['reply-to@5.com'])
describe "onComposeReplyAll", ->
describe "when the message provided as context was sent by the current user", ->
it "addresses the draft to all of the last messages's recipients", ->

View file

@ -219,9 +219,12 @@ class Message extends Model
to = @replyTo
else
to = @from
cc = [].concat(@cc, @to).filter (p) ->
!_.contains(excluded, p.email)
cc = [].concat(@cc, @to)
cc = _.filter cc, (p) -> !_.contains(excluded, p.email)
to = _.uniq to, (p) -> p.email.toLowerCase().trim()
cc = _.uniq cc, (p) -> p.email.toLowerCase().trim()
{to, cc}
# Public: Returns a hash with `to` and `cc` keys for authoring a new draft in
@ -238,6 +241,7 @@ class Message extends Model
else
to = @from
to = _.uniq to, (p) -> p.email.toLowerCase().trim()
{to, cc}
# Public: Returns an {Array} of {File} IDs