2015-05-20 07:06:59 +08:00
|
|
|
_ = require 'underscore'
|
2015-03-21 10:15:32 +08:00
|
|
|
Reflux = require 'reflux'
|
|
|
|
request = require 'request'
|
2015-04-29 10:23:28 +08:00
|
|
|
{FocusedContactsStore,
|
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
|
|
|
AccountStore,
|
2015-05-15 08:08:30 +08:00
|
|
|
PriorityUICoordinator} = require 'nylas-exports'
|
2015-03-21 10:15:32 +08:00
|
|
|
|
|
|
|
module.exports =
|
2015-04-29 10:23:28 +08:00
|
|
|
# The InternalAdminStore manages the data that backs the admin sidebar and emits
|
|
|
|
# a "trigger" event that the view listens to.
|
|
|
|
#
|
|
|
|
# If the Admin sidebar allowed you to take actions, like modifying someone's
|
2015-05-19 10:21:54 +08:00
|
|
|
# Nylas account, the InternalAdminStore would also listen for those user actions
|
2015-04-29 10:23:28 +08:00
|
|
|
# and perform business logic.
|
|
|
|
#
|
|
|
|
InternalAdminStore = Reflux.createStore
|
2015-03-21 10:15:32 +08:00
|
|
|
|
|
|
|
init: ->
|
|
|
|
@_accountCache = null
|
2015-03-22 02:59:47 +08:00
|
|
|
@_enabled = false
|
|
|
|
@_error = null
|
|
|
|
|
2015-04-29 10:23:28 +08:00
|
|
|
# Stores often listen to other stores to vend correct data to their views.
|
|
|
|
# Since we serve information about a contact we listen for changes to the
|
2015-05-15 08:08:30 +08:00
|
|
|
# focused contact. Since we only want to be enabled for @nylas.com emails,
|
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
|
|
|
# we listen for changes to available Accounts.
|
2015-03-21 10:15:32 +08:00
|
|
|
@listenTo FocusedContactsStore, @_onFocusedContacts
|
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
|
|
|
@listenTo AccountStore, @_onAccountChanged
|
2015-03-21 10:15:32 +08:00
|
|
|
|
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
|
|
|
@_onAccountChanged()
|
2015-03-21 10:15:32 +08:00
|
|
|
|
2015-04-29 10:23:28 +08:00
|
|
|
|
2015-03-21 10:15:32 +08:00
|
|
|
dataForFocusedContact: ->
|
2015-06-26 01:28:31 +08:00
|
|
|
return {loading: true} if @_accountCache is null
|
2015-03-21 10:15:32 +08:00
|
|
|
contact = FocusedContactsStore.focusedContact()
|
2015-03-21 10:18:05 +08:00
|
|
|
return {} unless contact
|
2015-04-29 10:23:28 +08:00
|
|
|
|
2015-03-21 10:15:32 +08:00
|
|
|
account = _.find @_accountCache, (account) -> account.email is contact.email
|
|
|
|
apps = undefined
|
2015-06-26 01:28:31 +08:00
|
|
|
apps = account.applications if account
|
2015-04-29 10:23:28 +08:00
|
|
|
|
|
|
|
# Coffeescript shorthand for {account: account, apps: apps}
|
2015-03-21 10:15:32 +08:00
|
|
|
{account, apps}
|
|
|
|
|
2015-03-22 02:59:47 +08:00
|
|
|
enabled: ->
|
|
|
|
@_enabled
|
|
|
|
|
|
|
|
error: ->
|
|
|
|
@_error
|
|
|
|
|
2015-03-21 10:15:32 +08:00
|
|
|
_onFocusedContacts: ->
|
2015-04-29 10:23:28 +08:00
|
|
|
# When the user focuses on a contact, we don't need to do any work because we
|
|
|
|
# cache everything. Just trigger so that our view updates and calls
|
|
|
|
# `dataForFocusedContact`.
|
2015-03-21 10:15:32 +08:00
|
|
|
@trigger(@)
|
|
|
|
|
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
|
|
|
_onAccountChanged: ->
|
2015-03-22 02:59:47 +08:00
|
|
|
clearInterval(@_fetchInterval) if @_fetchInterval
|
|
|
|
@_fetchInterval = null
|
|
|
|
|
2015-05-15 08:08:30 +08:00
|
|
|
# We only want to enable this package for users with nylas.com email addresses.
|
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
|
|
|
n = AccountStore.current()
|
2015-04-29 10:23:28 +08:00
|
|
|
if n and n.emailAddress.indexOf('@nylas.com') > 0
|
2015-03-22 02:59:47 +08:00
|
|
|
@_fetchInterval = setInterval(( => @_fetchAPIData()), 5 * 60 * 1000)
|
|
|
|
@_fetchAPIData()
|
|
|
|
@_enabled = true
|
|
|
|
else
|
|
|
|
@_accountCache = null
|
|
|
|
@_enabled = false
|
|
|
|
@trigger(@)
|
|
|
|
|
2015-03-21 10:15:32 +08:00
|
|
|
_fetchAPIData: ->
|
2015-04-29 10:23:28 +08:00
|
|
|
# Make a HTTP request to the Admin service using the `request` library. Using
|
|
|
|
# the priority UI coordinator ensures that the expensive JSON.parse operation
|
|
|
|
# doesn't happen while an animation is running.
|
2015-05-15 08:08:30 +08:00
|
|
|
request 'https://admin.nylas.com/api/status/accounts', (err, resp, data) =>
|
2015-03-31 09:08:38 +08:00
|
|
|
PriorityUICoordinator.settle.then =>
|
|
|
|
if err
|
2015-03-26 09:22:52 +08:00
|
|
|
@_error = err
|
2015-03-31 09:08:38 +08:00
|
|
|
else
|
|
|
|
@_error = null
|
|
|
|
try
|
|
|
|
@_accountCache = JSON.parse(data)
|
|
|
|
catch err
|
|
|
|
@_error = err
|
|
|
|
@_accountCache = null
|
|
|
|
@trigger(@)
|