feat(composer): don't prompt for attachment if in quoted text

Test Plan: edgehill --test

Reviewers: bengotow

Reviewed By: bengotow

Differential Revision: https://review.inboxapp.com/D1290
This commit is contained in:
Evan Morikawa 2015-03-13 15:55:52 -04:00
parent fa69b07eaa
commit 7c9797c706
6 changed files with 32 additions and 14 deletions

View file

@ -1,7 +1,8 @@
React = require 'react'
_ = require 'underscore-plus'
{Actions,
{Utils,
Actions,
UndoManager,
DraftStore,
FileUploadStore,
@ -306,7 +307,7 @@ ComposerView = React.createClass
warnings = []
if draft.subject.length is 0
warnings.push('without a subject line')
if (draft.files ? []).length is 0 and draft.body.toLowerCase().indexOf('attach') >= 0
if (draft.files ? []).length is 0 and @_hasAttachment(draft.body)
warnings.push('without an attachment')
if warnings.length > 0 and not options.force
@ -322,6 +323,16 @@ ComposerView = React.createClass
Actions.sendDraft(@props.localId)
_hasAttachment: (body) ->
body = body.toLowerCase().trim()
attachIndex = body.indexOf("attach")
if attachIndex >= 0
quotedTextIndex = Utils.quotedTextIndex(body)
if quotedTextIndex >= 0
return (attachIndex < quotedTextIndex)
else return true
else return false
_destroyDraft: ->
Actions.destroyDraft(@props.localId)

View file

@ -216,7 +216,7 @@ describe "populated composer", ->
expect(dialogArgs.buttons).toEqual ['Cancel', 'Send Anyway']
noWarn = (body) ->
useDraft.call @, subject: "Subject", to: [u1], body: "Sup yo"
useDraft.call @, subject: "Subject", to: [u1], body: body
makeComposer.call(@); @composer._sendDraft()
expect(Actions.sendDraft).toHaveBeenCalled()
expect(@dialog.showMessageBox).not.toHaveBeenCalled()
@ -224,9 +224,11 @@ describe "populated composer", ->
it "warns", -> warn.call(@, "Check out the attached file")
it "warns", -> warn.call(@, "I've added an attachment")
it "warns", -> warn.call(@, "I'm going to attach the file")
it "warns", -> warn.call(@, "Hey attach me <div class='gmail_quote'>sup</div>")
it "doesn't warn", -> noWarn.call(@, "sup yo")
it "doesn't warn", -> noWarn.call(@, "Look at the file")
it "doesn't warn", -> noWarn.call(@, "Hey there <div class='gmail_quote'>attach</div>")
it "doesn't show a warning if you've attached a file", ->
useDraft.call @,

View file

@ -170,7 +170,7 @@ EmailFrame = React.createClass
if @props.showQuotedText
email
else
Utils.withoutQuotedText(email)
Utils.stripQuotedText(email)
_onClick: (e) ->
e.preventDefault()

View file

@ -78,7 +78,7 @@ MessageItem = React.createClass
_quotedTextClasses: -> React.addons.classSet
"quoted-text-control": true
'no-quoted-text': !Utils.containsQuotedText(@props.message.body)
'no-quoted-text': (Utils.quotedTextIndex(@props.message.body).length is 0)
'show-quoted-text': @state.showQuotedText
_renderMessageActionsInline: ->

File diff suppressed because one or more lines are too long

View file

@ -103,7 +103,9 @@ Utils =
else
return "#{prefix} #{subject}"
containsQuotedText: (html) ->
# A wrapper around String#search(). Returns the index of the first match
# or returns -1 if there are no matches
quotedTextIndex: (html) ->
# I know this is gross - one day we'll replace it with a nice system.
return false unless html
@ -114,12 +116,15 @@ Utils =
/[\n|>]On .* wrote:[\n|<]/, #On ... wrote: on it's own line
/.gmail_quote/ # gmail quote class class
]
for regex in regexs
return true if html.match(regex)
return false
withoutQuotedText: (html) ->
return html unless Utils.containsQuotedText(html)
foundIndex = html.search(regex)
if foundIndex >= 0 then return foundIndex
return -1
stripQuotedText: (html) ->
return html if Utils.quotedTextIndex(html) is -1
# Split the email into lines and remove lines that begin with > or &gt;
lines = html.split(/(\n|<br[^>]*>)/)