From eab8cb9085a51caae0daf075d25829694d211030 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Tue, 10 May 2016 10:33:43 -0700 Subject: [PATCH] fix(draft-factory): ReplyTo takes precedence over "from me" #2175 --- spec/stores/draft-factory-spec.es6 | 27 +++++++++++++++++++++++++++ src/flux/models/message.es6 | 18 ++++++++---------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/spec/stores/draft-factory-spec.es6 b/spec/stores/draft-factory-spec.es6 index 99e688102..6acaddd1e 100644 --- a/spec/stores/draft-factory-spec.es6 +++ b/spec/stores/draft-factory-spec.es6 @@ -23,6 +23,7 @@ let fakeMessage2 = null; let msgWithReplyTo = null; let fakeMessageWithFiles = null; let msgWithReplyToDuplicates = null; +let msgWithReplyToFromMe = null; let account = null; describe('DraftFactory', function draftFactory() { @@ -104,6 +105,14 @@ describe('DraftFactory', function draftFactory() { date: new Date(1415814587), }); + msgWithReplyToFromMe = new Message({ + accountId: account.id, + threadId: 'fake-thread-id', + from: [account.me()], + to: [new Contact({email: 'tiffany@popular.com', name: 'Tiffany'})], + replyTo: [new Contact({email: 'danco@gmail.com', name: 'danco@gmail.com'})], + }) + msgWithReplyToDuplicates = new Message({ id: 'fake-message-reply-to-duplicates', accountId: account.id, @@ -246,6 +255,16 @@ describe('DraftFactory', function draftFactory() { }); }); }); + + it("addresses the draft to all of the message's 'ReplyTo' recipients, even if the message is 'From' you", () => { + waitsForPromise(() => { + return DraftFactory.createDraftForReply({thread: fakeThread, message: msgWithReplyToFromMe, type: 'reply'}).then((draft) => { + expect(draft.to).toEqual(msgWithReplyToFromMe.replyTo); + expect(draft.cc.length).toBe(0); + expect(draft.bcc.length).toBe(0); + }); + }); + }); }); describe("when the message provided as context was sent by the current user", () => { @@ -298,6 +317,14 @@ describe('DraftFactory', function draftFactory() { }); }); + it("addresses the draft to all of the message's 'ReplyTo' recipients, even if the message is 'From' you", () => { + waitsForPromise(() => { + return DraftFactory.createDraftForReply({thread: fakeThread, message: msgWithReplyToFromMe, type: 'reply-all'}).then((draft) => { + expect(draft.to).toEqual(msgWithReplyToFromMe.replyTo); + }); + }); + }); + it("should not include the message's 'From' recipient in any field", () => { waitsForPromise(() => { return DraftFactory.createDraftForReply({thread: fakeThread, message: msgWithReplyTo, type: 'reply-all'}).then((draft) => { diff --git a/src/flux/models/message.es6 b/src/flux/models/message.es6 index cce3b7118..3f9dd70b7 100644 --- a/src/flux/models/message.es6 +++ b/src/flux/models/message.es6 @@ -288,15 +288,14 @@ Message(date DESC) WHERE draft = 1`, let to = null let cc = null - if (this.isFromMe()) { + if (this.replyTo.length) { + to = this.replyTo + cc = excludeMeAndFroms([].concat(this.to, this.cc)) + } else if (this.isFromMe()) { to = this.to cc = excludeMeAndFroms(this.cc) } else { - if (this.replyTo.length) { - to = this.replyTo - } else { - to = this.from - } + to = this.from cc = excludeMeAndFroms([].concat(this.to, this.cc)) } @@ -312,10 +311,10 @@ Message(date DESC) WHERE draft = 1`, let to = [] const cc = [] - if (this.isFromMe()) { + if (this.replyTo.length) { + to = this.replyTo; + } else if (this.isFromMe()) { to = this.to - } else if (this.replyTo.length) { - to = this.replyTo } else { to = this.from } @@ -360,4 +359,3 @@ Message(date DESC) WHERE draft = 1`, return moment(this.date).format("MMM D YYYY, [at] h:mm a") } } -