2015-06-23 06:49:52 +08:00
|
|
|
React = require 'react'
|
2015-11-24 14:09:17 +08:00
|
|
|
{remote} = require 'electron'
|
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
|
|
|
{Actions, NylasAPI, 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}
|
|
|
|
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: =>
|
|
|
|
Actions.composeReply(thread: @props.thread, message: @props.message)
|
|
|
|
|
|
|
|
_onReplyAll: =>
|
|
|
|
Actions.composeReplyAll(thread: @props.thread, message: @props.message)
|
|
|
|
|
|
|
|
_onForward: =>
|
|
|
|
Actions.composeForward(thread: @props.thread, message: @props.message)
|
|
|
|
|
|
|
|
_replyType: =>
|
2015-06-27 07:45:05 +08:00
|
|
|
emails = @props.message.to.map (item) -> item.email.toLowerCase().trim()
|
2016-01-09 01:31:24 +08:00
|
|
|
myEmail = @_account()?.me().email.toLowerCase().trim()
|
2015-06-27 07:45:05 +08:00
|
|
|
if @props.message.cc.length is 0 and @props.message.to.length is 1 and emails[0] is myEmail
|
2015-06-23 06:49:52 +08:00
|
|
|
return "reply"
|
|
|
|
else return "reply-all"
|
|
|
|
|
2015-07-09 00:51:33 +08:00
|
|
|
_onShowActionsMenu: =>
|
|
|
|
remote = require('remote')
|
2015-09-04 07:29:33 +08:00
|
|
|
SystemMenu = remote.require('menu')
|
|
|
|
SystemMenuItem = remote.require('menu-item')
|
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()
|
|
|
|
menu.append(new SystemMenuItem({ label: 'Report Issue: Quoted Text', click: => @_onReport('Quoted Text')}))
|
|
|
|
menu.append(new SystemMenuItem({ label: 'Report Issue: Rendering', click: => @_onReport('Rendering')}))
|
|
|
|
menu.append(new SystemMenuItem({ type: 'separator'}))
|
|
|
|
menu.append(new SystemMenuItem({ label: 'Show Original', click: => @_onShowOriginal()}))
|
|
|
|
menu.append(new SystemMenuItem({ label: 'Log Data', click: => @_onLogData()}))
|
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()]
|
2015-07-09 00:51:33 +08:00
|
|
|
to: [new Contact(name: "Nylas Team", email: "feedback@nylas.com")]
|
|
|
|
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)
|
|
|
|
|
|
|
|
dialog = remote.require('dialog')
|
|
|
|
dialog.showMessageBox remote.getCurrentWindow(), {
|
|
|
|
type: 'warning'
|
|
|
|
buttons: ['OK'],
|
|
|
|
message: "Thank you."
|
2015-09-30 00:45:02 +08:00
|
|
|
detail: "The contents of this message have been sent to the N1 team and we 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'
|
|
|
|
BrowserWindow = remote.require('browser-window')
|
|
|
|
app = remote.require('app')
|
|
|
|
tmpfile = path.join(app.getPath('temp'), @props.message.id)
|
|
|
|
|
|
|
|
NylasAPI.makeRequest
|
|
|
|
headers:
|
|
|
|
Accept: 'message/rfc822'
|
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
|
|
|
path: "/messages/#{@props.message.id}"
|
|
|
|
accountId: @props.message.accountId
|
2015-07-09 00:51:33 +08:00
|
|
|
json:false
|
|
|
|
success: (body) =>
|
|
|
|
fs.writeFile tmpfile, body, =>
|
|
|
|
window = new BrowserWindow(width: 800, height: 600, title: "#{@props.message.subject} - RFC822")
|
2015-11-24 14:09:17 +08:00
|
|
|
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
|
|
|
|
2015-06-23 06:49:52 +08:00
|
|
|
module.exports = MessageControls
|