mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-12-11 23:16:13 +08:00
Fixes T1743: Add replyTo field handling, tests to DraftStore
Summary: Fixed T1743. Adds the replyTo field to Message objects and handling to the DraftStore. Also adds specs to make sure we don't break it. Test Plan: Run 3 new tests Reviewers: evan Reviewed By: evan Maniphest Tasks: T1743 Differential Revision: https://phab.nylas.com/D1565
This commit is contained in:
parent
4d6235b006
commit
736275cee1
3 changed files with 83 additions and 22 deletions
|
|
@ -15,6 +15,7 @@ fakeThread = null
|
||||||
fakeMessage1 = null
|
fakeMessage1 = null
|
||||||
fakeMessage2 = null
|
fakeMessage2 = null
|
||||||
msgFromMe = null
|
msgFromMe = null
|
||||||
|
msgWithReplyTo = null
|
||||||
fakeMessages = null
|
fakeMessages = null
|
||||||
|
|
||||||
describe "DraftStore", ->
|
describe "DraftStore", ->
|
||||||
|
|
@ -55,10 +56,23 @@ describe "DraftStore", ->
|
||||||
subject: 'Re: Fake Subject'
|
subject: 'Re: Fake Subject'
|
||||||
date: new Date(1415814587)
|
date: new Date(1415814587)
|
||||||
|
|
||||||
|
msgWithReplyTo = new Message
|
||||||
|
id: 'fake-message-reply-to'
|
||||||
|
to: [new Contact(email: '1@1.com'), new Contact(email: '2@2.com')]
|
||||||
|
cc: [new Contact(email: '3@3.com'), new Contact(email: '4@4.com')]
|
||||||
|
bcc: [new Contact(email: '5@5.com'), new Contact(email: '6@6.com')]
|
||||||
|
replyTo: [new Contact(email: 'reply-to@5.com'), new Contact(email: 'reply-to@6.com')]
|
||||||
|
from: [new Contact(email: 'from@5.com')]
|
||||||
|
threadId: 'fake-thread-id'
|
||||||
|
body: 'Fake Message 2'
|
||||||
|
subject: 'Re: Fake Subject'
|
||||||
|
date: new Date(1415814587)
|
||||||
|
|
||||||
fakeMessages =
|
fakeMessages =
|
||||||
'fake-message-1': fakeMessage1
|
'fake-message-1': fakeMessage1
|
||||||
'fake-message-3': msgFromMe
|
'fake-message-3': msgFromMe
|
||||||
'fake-message-2': fakeMessage2
|
'fake-message-2': fakeMessage2
|
||||||
|
'fake-message-reply-to': msgWithReplyTo
|
||||||
|
|
||||||
spyOn(DatabaseStore, 'find').andCallFake (klass, id) ->
|
spyOn(DatabaseStore, 'find').andCallFake (klass, id) ->
|
||||||
query = new ModelQuery(klass, {id})
|
query = new ModelQuery(klass, {id})
|
||||||
|
|
@ -92,28 +106,31 @@ describe "DraftStore", ->
|
||||||
it "should set the replyToMessageId to the previous message's ids", ->
|
it "should set the replyToMessageId to the previous message's ids", ->
|
||||||
expect(@model.replyToMessageId).toEqual(fakeMessage1.id)
|
expect(@model.replyToMessageId).toEqual(fakeMessage1.id)
|
||||||
|
|
||||||
describe "when the reply-to address is you", ->
|
describe "onComposeReply", ->
|
||||||
it "on reply sends to all of the last messages's to recipients only", ->
|
describe "when the message provided as context has one or more 'ReplyTo' recipients", ->
|
||||||
runs ->
|
it "addresses the draft to all of the message's 'ReplyTo' recipients", ->
|
||||||
DraftStore._onComposeReply({threadId: fakeThread.id, messageId: msgFromMe.id})
|
runs ->
|
||||||
waitsFor ->
|
DraftStore._onComposeReply({threadId: fakeThread.id, messageId: msgWithReplyTo.id})
|
||||||
DatabaseStore.persistModel.callCount > 0
|
waitsFor ->
|
||||||
runs ->
|
DatabaseStore.persistModel.callCount > 0
|
||||||
@model = DatabaseStore.persistModel.mostRecentCall.args[0]
|
runs ->
|
||||||
expect(@model.to).toEqual(msgFromMe.to)
|
@model = DatabaseStore.persistModel.mostRecentCall.args[0]
|
||||||
expect(@model.cc.length).toBe 0
|
expect(@model.to).toEqual(msgWithReplyTo.replyTo)
|
||||||
expect(@model.bcc.length).toBe 0
|
expect(@model.cc.length).toBe 0
|
||||||
|
expect(@model.bcc.length).toBe 0
|
||||||
|
|
||||||
it "on reply-all sends to all of the last messages's recipients", ->
|
describe "onComposeReply", ->
|
||||||
runs ->
|
describe "when the message provided as context was sent by the current user", ->
|
||||||
DraftStore._onComposeReplyAll({threadId: fakeThread.id, messageId: msgFromMe.id})
|
it "addresses the draft to all of the last messages's 'To' recipients", ->
|
||||||
waitsFor ->
|
runs ->
|
||||||
DatabaseStore.persistModel.callCount > 0
|
DraftStore._onComposeReply({threadId: fakeThread.id, messageId: msgFromMe.id})
|
||||||
runs ->
|
waitsFor ->
|
||||||
@model = DatabaseStore.persistModel.mostRecentCall.args[0]
|
DatabaseStore.persistModel.callCount > 0
|
||||||
expect(@model.to).toEqual(msgFromMe.to)
|
runs ->
|
||||||
expect(@model.cc).toEqual(msgFromMe.cc)
|
@model = DatabaseStore.persistModel.mostRecentCall.args[0]
|
||||||
expect(@model.bcc.length).toBe 0
|
expect(@model.to).toEqual(msgFromMe.to)
|
||||||
|
expect(@model.cc.length).toBe 0
|
||||||
|
expect(@model.bcc.length).toBe 0
|
||||||
|
|
||||||
describe "onComposeReplyAll", ->
|
describe "onComposeReplyAll", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
|
@ -146,6 +163,37 @@ describe "DraftStore", ->
|
||||||
it "should set the replyToMessageId to the previous message's ids", ->
|
it "should set the replyToMessageId to the previous message's ids", ->
|
||||||
expect(@model.replyToMessageId).toEqual(fakeMessage1.id)
|
expect(@model.replyToMessageId).toEqual(fakeMessage1.id)
|
||||||
|
|
||||||
|
describe "onComposeReplyAll", ->
|
||||||
|
describe "when the message provided as context has one or more 'ReplyTo' recipients", ->
|
||||||
|
beforeEach ->
|
||||||
|
runs ->
|
||||||
|
DraftStore._onComposeReply({threadId: fakeThread.id, messageId: msgWithReplyTo.id})
|
||||||
|
waitsFor ->
|
||||||
|
DatabaseStore.persistModel.callCount > 0
|
||||||
|
runs ->
|
||||||
|
@model = DatabaseStore.persistModel.mostRecentCall.args[0]
|
||||||
|
|
||||||
|
it "addresses the draft to all of the message's 'ReplyTo' recipients", ->
|
||||||
|
expect(@model.to).toEqual(msgWithReplyTo.replyTo)
|
||||||
|
|
||||||
|
it "should not include the message's 'From' recipient in any field", ->
|
||||||
|
all = [].concat(@model.to, @model.cc, @model.bcc)
|
||||||
|
match = _.find all, (c) -> c.email is msgWithReplyTo.from[0].email
|
||||||
|
expect(match).toEqual(undefined)
|
||||||
|
|
||||||
|
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", ->
|
||||||
|
runs ->
|
||||||
|
DraftStore._onComposeReplyAll({threadId: fakeThread.id, messageId: msgFromMe.id})
|
||||||
|
waitsFor ->
|
||||||
|
DatabaseStore.persistModel.callCount > 0
|
||||||
|
runs ->
|
||||||
|
@model = DatabaseStore.persistModel.mostRecentCall.args[0]
|
||||||
|
expect(@model.to).toEqual(msgFromMe.to)
|
||||||
|
expect(@model.cc).toEqual(msgFromMe.cc)
|
||||||
|
expect(@model.bcc.length).toBe 0
|
||||||
|
|
||||||
describe "onComposeForward", ->
|
describe "onComposeForward", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
runs ->
|
runs ->
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@ All messages are part of a thread, even if that thread has only one message.
|
||||||
|
|
||||||
`from`: {AttributeCollection} A collection of {Contact} objects.
|
`from`: {AttributeCollection} A collection of {Contact} objects.
|
||||||
|
|
||||||
|
`replyTo`: {AttributeCollection} A collection of {Contact} objects.
|
||||||
|
|
||||||
`date`: {AttributeDateTime} When the message was delivered. Queryable.
|
`date`: {AttributeDateTime} When the message was delivered. Queryable.
|
||||||
|
|
||||||
`subject`: {AttributeString} The subject of the thread. Queryable.
|
`subject`: {AttributeString} The subject of the thread. Queryable.
|
||||||
|
|
@ -77,6 +79,11 @@ class Message extends Model
|
||||||
modelKey: 'from'
|
modelKey: 'from'
|
||||||
itemClass: Contact
|
itemClass: Contact
|
||||||
|
|
||||||
|
'replyTo': Attributes.Collection
|
||||||
|
modelKey: 'replyTo'
|
||||||
|
jsonKey: 'reply_to'
|
||||||
|
itemClass: Contact
|
||||||
|
|
||||||
'date': Attributes.DateTime
|
'date': Attributes.DateTime
|
||||||
queryable: true
|
queryable: true
|
||||||
modelKey: 'date'
|
modelKey: 'date'
|
||||||
|
|
@ -131,6 +138,7 @@ class Message extends Model
|
||||||
@to ||= []
|
@to ||= []
|
||||||
@cc ||= []
|
@cc ||= []
|
||||||
@bcc ||= []
|
@bcc ||= []
|
||||||
|
@replyTo ||= []
|
||||||
@
|
@
|
||||||
|
|
||||||
toJSON: ->
|
toJSON: ->
|
||||||
|
|
|
||||||
|
|
@ -170,6 +170,8 @@ class DraftStore
|
||||||
@_newMessageWithContext context, (thread, message) =>
|
@_newMessageWithContext context, (thread, message) =>
|
||||||
if @_isMe(message.from[0])
|
if @_isMe(message.from[0])
|
||||||
to = message.to
|
to = message.to
|
||||||
|
else if message.replyTo.length
|
||||||
|
to = message.replyTo
|
||||||
else
|
else
|
||||||
to = message.from
|
to = message.from
|
||||||
|
|
||||||
|
|
@ -186,7 +188,10 @@ class DraftStore
|
||||||
else
|
else
|
||||||
excluded = message.from.map (c) -> c.email
|
excluded = message.from.map (c) -> c.email
|
||||||
excluded.push(NamespaceStore.current().me().email)
|
excluded.push(NamespaceStore.current().me().email)
|
||||||
to = message.from
|
if message.replyTo.length
|
||||||
|
to = message.replyTo
|
||||||
|
else
|
||||||
|
to = message.from
|
||||||
cc = [].concat(message.cc, message.to).filter (p) ->
|
cc = [].concat(message.cc, message.to).filter (p) ->
|
||||||
!_.contains(excluded, p.email)
|
!_.contains(excluded, p.email)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue