Mailspring/internal_packages/message-list/lib/message-controls.cjsx
Ben Gotow 607ca3bf10 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-21 15:29:58 -07:00

134 lines
4.5 KiB
CoffeeScript

remote = require 'remote'
React = require 'react'
{Actions, NylasAPI, AccountStore} = require 'nylas-exports'
{RetinaImg, ButtonDropdown, Menu} = require 'nylas-component-kit'
class MessageControls extends React.Component
@displayName: "MessageControls"
@propTypes:
thread: React.PropTypes.object.isRequired
message: React.PropTypes.object.isRequired
constructor: (@props) ->
render: =>
items = @_items()
<div className="message-actions-wrap">
<ButtonDropdown
primaryItem={<RetinaImg name={items[0].image} mode={RetinaImg.Mode.ContentIsMask}/>}
primaryClick={items[0].select}
menu={@_dropdownMenu(items[1..-1])}/>
<div className="message-actions-ellipsis" onClick={@_onShowActionsMenu}>
<RetinaImg name={"message-actions-ellipsis.png"} mode={RetinaImg.Mode.ContentIsMask}/>
</div>
</div>
_items: ->
reply =
name: 'Reply',
image: 'ic-dropdown-reply.png'
select: @_onReply
replyAll =
name: 'Reply All',
image: 'ic-dropdown-replyall.png'
select: @_onReplyAll
forward =
name: 'Forward',
image: 'ic-dropdown-forward.png'
select: @_onForward
defaultReplyType = atom.config.get('core.sending.defaultReplyType')
if @props.message.canReplyAll() and defaultReplyType is 'reply-all'
return [replyAll, reply, forward]
else
return [reply, replyAll, forward]
_dropdownMenu: (items) ->
itemContent = (item) ->
<span>
<RetinaImg name={item.image} mode={RetinaImg.Mode.ContentIsMask}/>
&nbsp;&nbsp;{item.name}
</span>
<Menu items={items}
itemKey={ (item) -> item.name }
itemContent={itemContent}
onSelect={ (item) => item.select() }
/>
_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: =>
emails = @props.message.to.map (item) -> item.email.toLowerCase().trim()
myEmail = AccountStore.current()?.me().email.toLowerCase().trim()
if @props.message.cc.length is 0 and @props.message.to.length is 1 and emails[0] is myEmail
return "reply"
else return "reply-all"
_onShowActionsMenu: =>
remote = require('remote')
Menu = remote.require('menu')
MenuItem = remote.require('menu-item')
# Todo: refactor this so that message actions are provided
# dynamically. Waiting to see if this will be used often.
menu = new Menu()
menu.append(new MenuItem({ label: 'Report Issue: Quoted Text', click: => @_onReport('Quoted Text')}))
menu.append(new MenuItem({ label: 'Report Issue: Rendering', click: => @_onReport('Rendering')}))
menu.append(new MenuItem({ type: 'separator'}))
menu.append(new MenuItem({ label: 'Show Original', click: => @_onShowOriginal()}))
menu.popup(remote.getCurrentWindow())
_onReport: (issueType) =>
{Contact, Message, DatabaseStore, AccountStore} = require 'nylas-exports'
draft = new Message
from: [AccountStore.current().me()]
to: [new Contact(name: "Nylas Team", email: "feedback@nylas.com")]
date: (new Date)
draft: true
subject: "Feedback - Message Display Issue (#{issueType})"
accountId: AccountStore.current().id
body: @props.message.body
DatabaseStore.persistModel(draft).then =>
DatabaseStore.localIdForModel(draft).then (localId) =>
Actions.sendDraft(localId)
dialog = remote.require('dialog')
dialog.showMessageBox remote.getCurrentWindow(), {
type: 'warning'
buttons: ['OK'],
message: "Thank you."
detail: "The contents of this message have been sent to the Edgehill team and we added to a test suite."
}
_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'
path: "/messages/#{@props.message.id}"
accountId: @props.message.accountId
json:false
success: (body) =>
fs.writeFile tmpfile, body, =>
window = new BrowserWindow(width: 800, height: 600, title: "#{@props.message.subject} - RFC822")
window.loadUrl('file://'+tmpfile)
module.exports = MessageControls