2015-06-23 06:49:52 +08:00
|
|
|
React = require 'react'
|
2015-11-24 14:09:17 +08:00
|
|
|
{remote} = require 'electron'
|
2016-11-30 04:29:28 +08:00
|
|
|
{Actions, NylasAPI, NylasAPIRequest, AccountStore} = require 'nylas-exports'
|
2015-07-22 04:52:59 +08:00
|
|
|
{RetinaImg, ButtonDropdown, Menu} = require 'nylas-component-kit'
|
2015-06-23 06:49:52 +08:00
|
|
|
|
|
|
|
class MessageControls extends React.Component
|
|
|
|
@displayName: "MessageControls"
|
|
|
|
@propTypes:
|
|
|
|
thread: React.PropTypes.object.isRequired
|
|
|
|
message: React.PropTypes.object.isRequired
|
|
|
|
|
|
|
|
constructor: (@props) ->
|
|
|
|
|
|
|
|
render: =>
|
2015-08-15 06:40:11 +08:00
|
|
|
items = @_items()
|
|
|
|
|
2015-06-23 06:49:52 +08:00
|
|
|
<div className="message-actions-wrap">
|
2015-07-22 04:52:59 +08:00
|
|
|
<ButtonDropdown
|
2015-08-15 06:40:11 +08:00
|
|
|
primaryItem={<RetinaImg name={items[0].image} mode={RetinaImg.Mode.ContentIsMask}/>}
|
2015-10-22 02:03:27 +08:00
|
|
|
primaryTitle={items[0].name}
|
2015-08-15 06:40:11 +08:00
|
|
|
primaryClick={items[0].select}
|
2016-03-23 06:47:51 +08:00
|
|
|
closeOnMenuClick={true}
|
2015-08-15 06:40:11 +08:00
|
|
|
menu={@_dropdownMenu(items[1..-1])}/>
|
2015-08-05 10:35:56 +08:00
|
|
|
<div className="message-actions-ellipsis" onClick={@_onShowActionsMenu}>
|
|
|
|
<RetinaImg name={"message-actions-ellipsis.png"} mode={RetinaImg.Mode.ContentIsMask}/>
|
|
|
|
</div>
|
2015-06-23 06:49:52 +08:00
|
|
|
</div>
|
|
|
|
|
2015-08-15 06:40:11 +08:00
|
|
|
_items: ->
|
|
|
|
reply =
|
|
|
|
name: 'Reply',
|
|
|
|
image: 'ic-dropdown-reply.png'
|
|
|
|
select: @_onReply
|
|
|
|
replyAll =
|
2015-07-22 04:52:59 +08:00
|
|
|
name: 'Reply All',
|
|
|
|
image: 'ic-dropdown-replyall.png'
|
|
|
|
select: @_onReplyAll
|
2015-08-15 06:40:11 +08:00
|
|
|
forward =
|
2015-07-22 04:52:59 +08:00
|
|
|
name: 'Forward',
|
|
|
|
image: 'ic-dropdown-forward.png'
|
|
|
|
select: @_onForward
|
|
|
|
|
2015-09-15 04:18:55 +08:00
|
|
|
if @props.message.canReplyAll()
|
2015-11-12 02:25:11 +08:00
|
|
|
defaultReplyType = NylasEnv.config.get('core.sending.defaultReplyType')
|
2015-09-15 04:18:55 +08:00
|
|
|
if defaultReplyType is 'reply-all'
|
|
|
|
return [replyAll, reply, forward]
|
|
|
|
else
|
|
|
|
return [reply, replyAll, forward]
|
2015-08-15 06:40:11 +08:00
|
|
|
else
|
2015-09-15 04:18:55 +08:00
|
|
|
return [reply, forward]
|
2015-08-15 06:40:11 +08:00
|
|
|
|
2016-01-09 01:31:24 +08:00
|
|
|
_account: =>
|
|
|
|
AccountStore.accountForId(@props.message.accountId)
|
|
|
|
|
2015-08-15 06:40:11 +08:00
|
|
|
_dropdownMenu: (items) ->
|
2015-07-22 04:52:59 +08:00
|
|
|
itemContent = (item) ->
|
|
|
|
<span>
|
|
|
|
<RetinaImg name={item.image} mode={RetinaImg.Mode.ContentIsMask}/>
|
|
|
|
{item.name}
|
|
|
|
</span>
|
|
|
|
|
|
|
|
<Menu items={items}
|
|
|
|
itemKey={ (item) -> item.name }
|
|
|
|
itemContent={itemContent}
|
|
|
|
onSelect={ (item) => item.select() }
|
|
|
|
/>
|
2015-06-23 06:49:52 +08:00
|
|
|
|
|
|
|
_onReply: =>
|
2016-03-23 06:47:51 +08:00
|
|
|
{thread, message} = @props
|
|
|
|
Actions.composeReply({thread, message, type: 'reply', behavior: 'prefer-existing-if-pristine'})
|
2015-06-23 06:49:52 +08:00
|
|
|
|
|
|
|
_onReplyAll: =>
|
2016-03-23 06:47:51 +08:00
|
|
|
{thread, message} = @props
|
|
|
|
Actions.composeReply({thread, message, type: 'reply-all', behavior: 'prefer-existing-if-pristine'})
|
2015-06-23 06:49:52 +08:00
|
|
|
|
|
|
|
_onForward: =>
|
2017-03-10 16:09:01 +08:00
|
|
|
{thread, message} = @props
|
|
|
|
Actions.composeForward({thread, message})
|
2015-06-23 06:49:52 +08:00
|
|
|
|
2015-07-09 00:51:33 +08:00
|
|
|
_onShowActionsMenu: =>
|
2016-05-13 04:59:20 +08:00
|
|
|
SystemMenu = remote.Menu
|
|
|
|
SystemMenuItem = remote.MenuItem
|
2015-07-09 00:51:33 +08:00
|
|
|
|
|
|
|
# Todo: refactor this so that message actions are provided
|
|
|
|
# dynamically. Waiting to see if this will be used often.
|
2015-09-04 07:29:33 +08:00
|
|
|
menu = new SystemMenu()
|
2016-03-08 10:24:31 +08:00
|
|
|
menu.append(new SystemMenuItem({ label: 'Log Data', click: => @_onLogData()}))
|
2015-09-04 07:29:33 +08:00
|
|
|
menu.append(new SystemMenuItem({ label: 'Show Original', click: => @_onShowOriginal()}))
|
2016-02-27 04:26:20 +08:00
|
|
|
menu.append(new SystemMenuItem({ label: 'Copy Debug Info to Clipboard', click: => @_onCopyToClipboard()}))
|
2016-03-08 10:24:31 +08:00
|
|
|
menu.append(new SystemMenuItem({ type: 'separator'}))
|
|
|
|
menu.append(new SystemMenuItem({ label: 'Report Issue: Quoted Text', click: => @_onReport('Quoted Text')}))
|
|
|
|
menu.append(new SystemMenuItem({ label: 'Report Issue: Rendering', click: => @_onReport('Rendering')}))
|
2015-07-09 00:51:33 +08:00
|
|
|
menu.popup(remote.getCurrentWindow())
|
|
|
|
|
|
|
|
_onReport: (issueType) =>
|
feat(accounts): Kill namespaces, long live accounts
Summary:
This diff replaces the Namespace object with the Account object, and changes all references to namespace_id => account_id, etc. The endpoints are now `/threads` instead of `/n/<id>/threads`.
This diff also adds preliminary support for multiple accounts. When you log in, we now log you in to all the attached accounts on edgehill server. From the preferences panel, you can auth with / unlink additional accounts. Shockingly, this all seems to pretty much work.
When replying to a thread, you cannot switch from addresses. However, when creating a new message in a popout composer, you can change the from address and the SaveDraftTask will delete/re-root the draft on the new account.
Search bar doesn't need to do full refresh on clear if it never committed
Allow drafts to be switched to a different account when not in reply to an existing thread
Fix edge case where ChangeMailTask throws exception if no models are modified during performLocal
Show many dots for many accounts in long polling status bar
add/remove accounts from prefs
Spec fixes!
Test Plan: Run tests, none broken!
Reviewers: evan, dillon
Reviewed By: evan, dillon
Differential Revision: https://phab.nylas.com/D1928
2015-08-22 06:29:58 +08:00
|
|
|
{Contact, Message, DatabaseStore, AccountStore} = require 'nylas-exports'
|
2015-07-09 00:51:33 +08:00
|
|
|
|
|
|
|
draft = new Message
|
2016-01-09 01:31:24 +08:00
|
|
|
from: [@_account().me()]
|
2016-02-27 04:29:11 +08:00
|
|
|
to: [new Contact(name: "Nylas Team", email: "n1-support@nylas.com")]
|
2015-07-09 00:51:33 +08:00
|
|
|
date: (new Date)
|
|
|
|
draft: true
|
|
|
|
subject: "Feedback - Message Display Issue (#{issueType})"
|
2016-01-09 01:31:24 +08:00
|
|
|
accountId: @_account().id
|
2015-07-09 00:51:33 +08:00
|
|
|
body: @props.message.body
|
|
|
|
|
2015-12-18 03:46:05 +08:00
|
|
|
DatabaseStore.inTransaction (t) =>
|
|
|
|
t.persistModel(draft)
|
|
|
|
.then =>
|
2015-08-29 02:12:53 +08:00
|
|
|
Actions.sendDraft(draft.clientId)
|
|
|
|
|
2016-05-13 04:59:20 +08:00
|
|
|
dialog = remote.dialog
|
2015-08-29 02:12:53 +08:00
|
|
|
dialog.showMessageBox remote.getCurrentWindow(), {
|
|
|
|
type: 'warning'
|
|
|
|
buttons: ['OK'],
|
|
|
|
message: "Thank you."
|
2016-03-08 10:24:31 +08:00
|
|
|
detail: "The contents of this message have been sent to the N1 team and will be added to a test suite."
|
2015-08-29 02:12:53 +08:00
|
|
|
}
|
2015-07-09 00:51:33 +08:00
|
|
|
|
|
|
|
_onShowOriginal: =>
|
|
|
|
fs = require 'fs'
|
|
|
|
path = require 'path'
|
2016-05-13 04:59:20 +08:00
|
|
|
BrowserWindow = remote.BrowserWindow
|
|
|
|
app = remote.app
|
2015-07-09 00:51:33 +08:00
|
|
|
tmpfile = path.join(app.getPath('temp'), @props.message.id)
|
|
|
|
|
2016-11-30 04:29:28 +08:00
|
|
|
request = new NylasAPIRequest
|
|
|
|
api: NylasAPI
|
|
|
|
options:
|
|
|
|
headers:
|
|
|
|
Accept: 'message/rfc822'
|
|
|
|
path: "/messages/#{@props.message.id}"
|
|
|
|
accountId: @props.message.accountId
|
|
|
|
json:false
|
|
|
|
request.run()
|
:art: Fix unhandled api rejections/Prefer promises over `success` option for api requests
Summary:
This commit modifies the api of NylasAPIRequest to /not/ take `success`
or `error` callback options at all, and only returns a Promise which you
can `then` and `catch` to handle the api response.
The fact that it returned a promise, and /also/ took `success` and
`error` callback options made it really confusing to use.
Additionaly, when using the callbacks intead of a promise, any errors
would be unhandled and reported to Sentry because even though the `error`
callback was being passed, the promise returned by `run()` still rejected and
no one was handling that reject, so it reached the `unhandledRejection` event
listener. This is undesirable because if you passed an `error` callback, it
means that you intended to handle it.
An example of this is calling the clearbit API, which will more often than
not return a 404, and even though we had an error handler which ignored the 404,
it still unecessarilly reported to Sentry, flooding it with events
Test Plan: manually check all updated codepaths still work
Reviewers: halla, spang, evan
Reviewed By: evan
Differential Revision: https://phab.nylas.com/D3869
2017-02-10 01:19:41 +08:00
|
|
|
.then((body) =>
|
|
|
|
fs.writeFile tmpfile, body, =>
|
|
|
|
window = new BrowserWindow(width: 800, height: 600, title: "#{@props.message.subject} - RFC822")
|
|
|
|
window.loadURL('file://'+tmpfile)
|
|
|
|
)
|
2015-07-09 00:51:33 +08:00
|
|
|
|
2015-09-03 09:26:58 +08:00
|
|
|
_onLogData: =>
|
|
|
|
console.log @props.message
|
|
|
|
window.__message = @props.message
|
|
|
|
window.__thread = @props.thread
|
|
|
|
console.log "Also now available in window.__message and window.__thread"
|
2015-07-09 00:51:33 +08:00
|
|
|
|
2016-02-27 04:26:20 +08:00
|
|
|
_onCopyToClipboard: =>
|
|
|
|
clipboard = require('electron').clipboard
|
2016-02-27 07:13:33 +08:00
|
|
|
data = "AccountID: #{@props.message.accountId}\n"+
|
|
|
|
"Message ID: #{@props.message.serverId}\n"+
|
|
|
|
"Message Metadata: #{JSON.stringify(@props.message.pluginMetadata, null, ' ')}\n"+
|
|
|
|
"Thread ID: #{@props.thread.serverId}\n"+
|
|
|
|
"Thread Metadata: #{JSON.stringify(@props.thread.pluginMetadata, null, ' ')}\n"
|
2016-02-27 04:26:20 +08:00
|
|
|
|
|
|
|
clipboard.writeText(data)
|
|
|
|
|
2015-06-23 06:49:52 +08:00
|
|
|
module.exports = MessageControls
|