mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-31 04:19:15 +08:00
feat(reply): don't reply to yourself
Summary: If the last message was sent by you, and you reply to it, you probably want to talk to you the most recent people you tried to email. Now with test coverage :) Test Plan: edgehill --test Reviewers: bengotow Reviewed By: bengotow Differential Revision: https://review.inboxapp.com/D1356
This commit is contained in:
parent
1c56e5c15b
commit
cdfaf5cf77
2 changed files with 65 additions and 12 deletions
|
@ -13,6 +13,7 @@ _ = require 'underscore-plus'
|
|||
fakeThread = null
|
||||
fakeMessage1 = null
|
||||
fakeMessage2 = null
|
||||
msgFromMe = null
|
||||
fakeMessages = null
|
||||
|
||||
describe "DraftStore", ->
|
||||
|
@ -42,8 +43,20 @@ describe "DraftStore", ->
|
|||
subject: 'Re: Fake Subject'
|
||||
date: new Date(1415814587)
|
||||
|
||||
msgFromMe = new Message
|
||||
id: 'fake-message-3'
|
||||
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')]
|
||||
from: [new Contact(email: NamespaceStore.current().me().email)]
|
||||
threadId: 'fake-thread-id'
|
||||
body: 'Fake Message 2'
|
||||
subject: 'Re: Fake Subject'
|
||||
date: new Date(1415814587)
|
||||
|
||||
fakeMessages =
|
||||
'fake-message-1': fakeMessage1
|
||||
'fake-message-3': msgFromMe
|
||||
'fake-message-2': fakeMessage2
|
||||
|
||||
spyOn(DatabaseStore, 'find').andCallFake (klass, id) ->
|
||||
|
@ -78,6 +91,29 @@ describe "DraftStore", ->
|
|||
it "should set the replyToMessageId to the previous message's ids", ->
|
||||
expect(@model.replyToMessageId).toEqual(fakeMessage1.id)
|
||||
|
||||
describe "when the reply-to address is you", ->
|
||||
it "on reply sends to all of the last messages's to recipients only", ->
|
||||
runs ->
|
||||
DraftStore._onComposeReply({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.length).toBe 0
|
||||
expect(@model.bcc.length).toBe 0
|
||||
|
||||
it "on reply-all sends 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 "onComposeReplyAll", ->
|
||||
beforeEach ->
|
||||
runs ->
|
||||
|
@ -104,8 +140,7 @@ describe "DraftStore", ->
|
|||
|
||||
it "should not include you when you were cc'd on the previous message", ->
|
||||
ccEmails = @model.cc.map (cc) -> cc.email
|
||||
myEmail = NamespaceStore.current().me().email
|
||||
expect(ccEmails.indexOf(myEmail)).toEqual(-1)
|
||||
expect(ccEmails.indexOf(NamespaceStore.current().me().email)).toEqual(-1)
|
||||
|
||||
it "should set the replyToMessageId to the previous message's ids", ->
|
||||
expect(@model.replyToMessageId).toEqual(fakeMessage1.id)
|
||||
|
|
|
@ -131,20 +131,38 @@ DraftStore = Reflux.createStore
|
|||
@_drafts = drafts
|
||||
@trigger(change)
|
||||
|
||||
_isMe: (contact={}) ->
|
||||
contact.email is NamespaceStore.current().me().email
|
||||
|
||||
_onComposeReply: (context) ->
|
||||
@_newMessageWithContext context, (thread, message) ->
|
||||
replyToMessage: message
|
||||
to: message.from
|
||||
@_newMessageWithContext context, (thread, message) =>
|
||||
if @_isMe(message.from[0])
|
||||
to = message.to
|
||||
else
|
||||
to = message.from
|
||||
|
||||
return {
|
||||
replyToMessage: message
|
||||
to: to
|
||||
}
|
||||
|
||||
_onComposeReplyAll: (context) ->
|
||||
@_newMessageWithContext context, (thread, message) ->
|
||||
excluded = message.from.map (c) -> c.email
|
||||
excluded.push(NamespaceStore.current().me().email)
|
||||
@_newMessageWithContext context, (thread, message) =>
|
||||
if @_isMe(message.from[0])
|
||||
to = message.to
|
||||
cc = message.cc
|
||||
else
|
||||
excluded = message.from.map (c) -> c.email
|
||||
excluded.push(NamespaceStore.current().me().email)
|
||||
to = message.from
|
||||
cc = [].concat(message.cc, message.to).filter (p) ->
|
||||
!_.contains(excluded, p.email)
|
||||
|
||||
replyToMessage: message
|
||||
to: message.from
|
||||
cc: [].concat(message.cc, message.to).filter (p) ->
|
||||
!_.contains(excluded, p.email)
|
||||
return {
|
||||
replyToMessage: message
|
||||
to: to
|
||||
cc: cc
|
||||
}
|
||||
|
||||
_onComposeForward: (context) ->
|
||||
@_newMessageWithContext context, (thread, message) ->
|
||||
|
|
Loading…
Reference in a new issue