2015-09-09 09:38:45 +08:00
|
|
|
NylasStore = require 'nylas-store'
|
2015-05-20 07:06:59 +08:00
|
|
|
_ = require 'underscore'
|
2016-12-16 04:32:34 +08:00
|
|
|
{Rx,
|
|
|
|
Message,
|
2016-02-05 06:14:24 +08:00
|
|
|
OutboxStore,
|
2016-04-20 08:41:57 +08:00
|
|
|
AccountStore,
|
2016-02-05 06:14:24 +08:00
|
|
|
MutableQueryResultSet,
|
2016-01-09 06:31:33 +08:00
|
|
|
MutableQuerySubscription,
|
2016-01-15 04:26:54 +08:00
|
|
|
ObservableListDataSource,
|
2016-01-12 03:39:14 +08:00
|
|
|
FocusedPerspectiveStore,
|
2016-01-09 06:31:33 +08:00
|
|
|
DatabaseStore} = require 'nylas-exports'
|
2016-01-26 08:36:56 +08:00
|
|
|
{ListTabular} = require 'nylas-component-kit'
|
2015-04-09 10:25:00 +08:00
|
|
|
|
2015-09-09 09:38:45 +08:00
|
|
|
class DraftListStore extends NylasStore
|
|
|
|
constructor: ->
|
2016-01-26 08:36:56 +08:00
|
|
|
@listenTo FocusedPerspectiveStore, @_onPerspectiveChanged
|
|
|
|
@_createListDataSource()
|
fix(draft-list): draft list removes draft when the message sends
Summary:
This started when I noticed that drafts weren't dissapearing from the
draft list after send. This was a pretty big bug because if you ever
clicked on one again and tried to re-send it would throw a 400 error
saying the draft id doesn't exist.
This uncovered a few fundamental issues with the DB.
First of all, the reason the draft list wasn't updating was because the DB
trigger that happened when we got in a new message, was being ignored
since the diff contained no drafts (it's now a message).
The bigger issue was that if you had a draft with only a clientId, gave it
a serverId, and tried to call "save", the REPLACE INTO method would not
update the old object, but rather create a second duplicate. This is
because the `id` field was being used as the PRIMARY KEY, and in this
case, that `id` field changed! The fix was to change the PRIMARY KEY to be
the `cilent_id` instead of the `id` and use that as the REPLACE INTO
index.
We still need the `id` field; however, because all of our reads depend on
that field usually being the serverId
Fixes T3507
Test Plan: See new and updated tests
Reviewers: dillon, bengotow
Reviewed By: bengotow
Maniphest Tasks: T3507
Differential Revision: https://phab.nylas.com/D1992
2015-09-09 04:11:34 +08:00
|
|
|
|
2016-01-26 08:36:56 +08:00
|
|
|
dataSource: =>
|
|
|
|
@_dataSource
|
2016-01-09 06:31:33 +08:00
|
|
|
|
2016-03-18 00:50:30 +08:00
|
|
|
selectionObservable: =>
|
|
|
|
return Rx.Observable.fromListSelection(@)
|
|
|
|
|
2016-01-26 08:36:56 +08:00
|
|
|
# Inbound Events
|
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
|
|
|
|
2016-01-26 08:36:56 +08:00
|
|
|
_onPerspectiveChanged: =>
|
|
|
|
@_createListDataSource()
|
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
|
|
|
|
2016-01-26 08:36:56 +08:00
|
|
|
# Internal
|
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
|
|
|
|
2016-01-26 08:36:56 +08:00
|
|
|
_createListDataSource: =>
|
|
|
|
mailboxPerspective = FocusedPerspectiveStore.current()
|
2015-04-09 10:25:00 +08:00
|
|
|
|
2016-01-26 08:36:56 +08:00
|
|
|
if mailboxPerspective.drafts
|
|
|
|
query = DatabaseStore.findAll(Message)
|
|
|
|
.include(Message.attributes.body)
|
|
|
|
.order(Message.attributes.date.descending())
|
2016-04-20 08:41:57 +08:00
|
|
|
.where(draft: true)
|
2016-01-26 08:36:56 +08:00
|
|
|
.page(0, 1)
|
2015-04-09 10:25:00 +08:00
|
|
|
|
2016-04-20 08:41:57 +08:00
|
|
|
# Adding a "account_id IN (a,b,c)" clause to our query can result in a full
|
|
|
|
# table scan. Don't add the where clause if we know we want results from all.
|
|
|
|
if mailboxPerspective.accountIds.length < AccountStore.accounts().length
|
|
|
|
query.where(accountId: mailboxPerspective.accountIds)
|
|
|
|
|
2016-04-20 02:32:33 +08:00
|
|
|
subscription = new MutableQuerySubscription(query, {emitResultSet: true})
|
2016-02-05 06:14:24 +08:00
|
|
|
$resultSet = Rx.Observable.fromNamedQuerySubscription('draft-list', subscription)
|
|
|
|
$resultSet = Rx.Observable.combineLatest [
|
|
|
|
$resultSet,
|
|
|
|
Rx.Observable.fromStore(OutboxStore)
|
|
|
|
], (resultSet, outbox) =>
|
|
|
|
|
|
|
|
# Generate a new result set that includes additional information on
|
|
|
|
# the draft objects. This is similar to what we do in the thread-list,
|
2016-10-14 00:43:20 +08:00
|
|
|
# where we set thread.__messages to the message array.
|
2016-02-05 06:14:24 +08:00
|
|
|
resultSetWithTasks = new MutableQueryResultSet(resultSet)
|
|
|
|
|
|
|
|
mailboxPerspective.accountIds.forEach (aid) =>
|
|
|
|
OutboxStore.itemsForAccount(aid).forEach (task) =>
|
2016-03-17 10:27:12 +08:00
|
|
|
draft = resultSet.modelWithId(task.draftClientId)
|
2016-02-05 06:14:24 +08:00
|
|
|
if draft
|
|
|
|
draft = draft.clone()
|
|
|
|
draft.uploadTaskId = task.id
|
|
|
|
draft.uploadProgress = task.progress
|
2016-05-04 05:01:03 +08:00
|
|
|
resultSetWithTasks.updateModel(draft)
|
2016-02-05 06:14:24 +08:00
|
|
|
|
|
|
|
return resultSetWithTasks.immutableClone()
|
|
|
|
|
2016-01-26 08:36:56 +08:00
|
|
|
@_dataSource = new ObservableListDataSource($resultSet, subscription.replaceRange)
|
|
|
|
else
|
|
|
|
@_dataSource = new ListTabular.DataSource.Empty()
|
|
|
|
|
|
|
|
@trigger(@)
|
2015-07-10 04:28:02 +08:00
|
|
|
|
2015-09-09 09:38:45 +08:00
|
|
|
module.exports = new DraftListStore()
|