2015-05-20 07:06:59 +08:00
|
|
|
_ = require 'underscore'
|
2015-07-16 23:54:20 +08:00
|
|
|
NylasStore = require 'nylas-store'
|
2015-04-01 08:19:17 +08:00
|
|
|
|
2015-07-16 23:54:20 +08:00
|
|
|
{Thread,
|
|
|
|
Message,
|
|
|
|
Actions,
|
2015-04-23 07:41:29 +08:00
|
|
|
SearchView,
|
2015-07-16 23:54:20 +08:00
|
|
|
DatabaseView,
|
|
|
|
DatabaseStore,
|
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-04-01 08:19:17 +08:00
|
|
|
WorkspaceStore,
|
2015-04-09 10:25:00 +08:00
|
|
|
FocusedContentStore,
|
feat(work): Create the "Work" window, move TaskQueue, Nylas sync workers
Summary:
Move sync workers and Edgehill token checks to work window
Move the task queue and database setup to the work window
Move ContactStore background refresh to work window
Store the task queue in the database
WIP
The TaskQueue now puts tasks in the database instead of in a file, which also means it can be observed
Move all delta sync and initial sync to a package, make NylasSyncStore which exposes read-only sync state
DraftStore no longer reads task status. Once you set the "sending" bit on a draft, it never gets unset. But that's fine actually.
If your package lists windowTypes, you *only* get loaded in those windowTypes. If you specify no windowTypes, you get loaded in the root window.
This means that onboarding, worker-ui, worker-sync, etc. no longer get loaded into the main window
ActivitySidebar has a special little store that observes the task queue since it's no longer in the window
Move "toggle component regions" / "toggle react remote" to the Developer menu
Move sync worker specs, update draft store specs to not rely on TaskQueue at all
Test Plan: Run existing tests, all pass
Reviewers: dillon, evan
Reviewed By: evan
Differential Revision: https://phab.nylas.com/D1936
2015-08-28 07:39:40 +08:00
|
|
|
TaskQueueStatusStore,
|
2015-09-05 03:23:15 +08:00
|
|
|
FocusedMailViewStore} = require 'nylas-exports'
|
2015-07-16 23:54:20 +08:00
|
|
|
|
|
|
|
# Public: A mutable text container with undo/redo support and the ability
|
|
|
|
# to annotate logical regions in the text.
|
|
|
|
class ThreadListStore extends NylasStore
|
|
|
|
constructor: ->
|
2015-04-01 08:19:17 +08:00
|
|
|
@_resetInstanceVars()
|
|
|
|
|
|
|
|
@listenTo DatabaseStore, @_onDataChanged
|
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-09-05 03:23:15 +08:00
|
|
|
@listenTo FocusedMailViewStore, @_onMailViewChanged
|
2015-12-12 04:15:34 +08:00
|
|
|
@createView()
|
2015-04-01 08:19:17 +08:00
|
|
|
|
2015-11-12 02:25:11 +08:00
|
|
|
NylasEnv.commands.add "body",
|
feat(selection): add selection of read, unread, starred, etc
Summary:
Can select all, deselect-all, read, unread, starred, unstarred.
Yes, it's not REALLY select "all", but it uses the items in the current
`retainedRange`. This is actually similar to what gmail does (only selects
on the first page of a 100).
Test Plan: new test
Reviewers: juan, bengotow
Reviewed By: bengotow
Differential Revision: https://phab.nylas.com/D2241
2015-11-09 23:03:55 +08:00
|
|
|
'thread-list:select-read' : @_onSelectRead
|
|
|
|
'thread-list:select-unread' : @_onSelectUnread
|
|
|
|
'thread-list:select-starred' : @_onSelectStarred
|
|
|
|
'thread-list:select-unstarred': @_onSelectUnstarred
|
|
|
|
|
2015-07-16 23:54:20 +08:00
|
|
|
# We can't create a @view on construction because the CategoryStore
|
|
|
|
# has hot yet been populated from the database with the list of
|
|
|
|
# categories and their corresponding ids. Once that is ready, the
|
|
|
|
# CategoryStore will trigger, which will update the
|
2015-09-05 03:23:15 +08:00
|
|
|
# FocusedMailViewStore, which will cause us to create a new
|
2015-07-16 23:54:20 +08:00
|
|
|
# @view.
|
2015-05-22 09:08:29 +08:00
|
|
|
|
2015-04-01 08:19:17 +08:00
|
|
|
_resetInstanceVars: ->
|
2015-04-07 02:46:20 +08:00
|
|
|
@_lastQuery = null
|
2015-04-01 08:19:17 +08:00
|
|
|
|
2015-04-07 02:46:20 +08:00
|
|
|
view: ->
|
|
|
|
@_view
|
|
|
|
|
|
|
|
setView: (view) ->
|
|
|
|
@_viewUnlisten() if @_viewUnlisten
|
|
|
|
@_view = view
|
2015-04-01 08:19:17 +08:00
|
|
|
|
2015-04-09 10:25:00 +08:00
|
|
|
@_viewUnlisten = view.listen ->
|
2015-04-07 02:46:20 +08:00
|
|
|
@trigger(@)
|
|
|
|
,@
|
|
|
|
|
2015-11-19 04:28:54 +08:00
|
|
|
# Set up a one-time listener to focus an item in the new view
|
|
|
|
if WorkspaceStore.layoutMode() is 'split'
|
|
|
|
unlisten = view.listen ->
|
|
|
|
if view.loaded()
|
|
|
|
Actions.setFocus(collection: 'thread', item: view.get(0))
|
|
|
|
unlisten()
|
|
|
|
|
2015-04-07 02:46:20 +08:00
|
|
|
@trigger(@)
|
|
|
|
|
|
|
|
createView: ->
|
2015-09-05 03:23:15 +08:00
|
|
|
mailViewFilter = FocusedMailViewStore.mailView()
|
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
|
|
|
account = AccountStore.current()
|
2015-09-05 06:31:03 +08:00
|
|
|
return unless account and mailViewFilter
|
2015-04-07 02:46:20 +08:00
|
|
|
|
2015-09-05 06:31:03 +08:00
|
|
|
if mailViewFilter.searchQuery
|
|
|
|
@setView(new SearchView(mailViewFilter.searchQuery, account.id))
|
|
|
|
else
|
2015-04-07 02:46:20 +08:00
|
|
|
matchers = []
|
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
|
|
|
matchers.push Thread.attributes.accountId.equal(account.id)
|
2015-09-05 03:23:15 +08:00
|
|
|
matchers = matchers.concat(mailViewFilter.matchers())
|
2015-07-16 23:54:20 +08:00
|
|
|
|
perf(thread-list): Tailored SQLite indexes, ListTabular / ScrollRegion optimizations galore
Summary:
Allow Database models to create indexes, but don't autocreate bad ones
fix minor bug in error-reporter
Fix index on message list to make thread list lookups use proper index
Developer bar ignores state changes unless it's open
DatabaseView now asks for metadata for a set of items rather than calling a function for every item. Promise.props was cute but we really needed to make a single database query for all message metadata.
New "in" matcher so you can say `thread_id IN (1,2,3)`
Add .scroll-region-content-inner which is larger than the viewport by 1 page size, and uses transform(0,0,0) trick
ScrollRegion exposes `onScrollEnd` so listTabular, et al don't need to re-implement it with more timers. Also removing requestAnimationFrame which was causing us to request scrollTop when it was not ready, and caching the values of...
...clientHeight/scrollHeight while scrolling is in-flight
Updating rendered content 10 rows at a time (RangeChunkSize) was a bad idea. Instead, add every row in a render: pass as it comes in (less work all the time vs more work intermittently). Also remove bad requestAnimationFrame, and prevent calls to...
...updateRangeState from triggering additional calls to updateRangeState by removing `componentDidUpdate => updateRangeState `
Turning off hover (pointer-events:none) is now standard in ScrollRegion
Loading text in the scroll tooltip, instead of random date shown
Handle query parse errors by catching error and throwing a better more explanatory error
Replace "quick action" retina images with background images to make React render easier
Replace hasTagId with a faster implementation which doesn't call functions and doesn't build a temporary array
Print query durations when printing to console instead of only in metadata
Remove headers from support from ListTabular, we'll never use it
Making columns part of state was a good idea but changing the array causes the entire ListTabular to re-render. To avoid this, be smarter about updating columns. This logic could potentially go in `componentDidReceiveProps` too.
Fix specs and add 6 more for new database store functionality
Test Plan: Run 6 new specs. More in the works?
Reviewers: evan
Reviewed By: evan
Differential Revision: https://phab.nylas.com/D1651
2015-06-18 11:12:48 +08:00
|
|
|
view = new DatabaseView Thread, {matchers}, (ids) =>
|
2015-08-27 05:10:28 +08:00
|
|
|
DatabaseStore.findAll(Message)
|
|
|
|
.where(Message.attributes.threadId.in(ids))
|
|
|
|
.where(Message.attributes.accountId.equal(account.id))
|
|
|
|
.then (messages) ->
|
perf(thread-list): Tailored SQLite indexes, ListTabular / ScrollRegion optimizations galore
Summary:
Allow Database models to create indexes, but don't autocreate bad ones
fix minor bug in error-reporter
Fix index on message list to make thread list lookups use proper index
Developer bar ignores state changes unless it's open
DatabaseView now asks for metadata for a set of items rather than calling a function for every item. Promise.props was cute but we really needed to make a single database query for all message metadata.
New "in" matcher so you can say `thread_id IN (1,2,3)`
Add .scroll-region-content-inner which is larger than the viewport by 1 page size, and uses transform(0,0,0) trick
ScrollRegion exposes `onScrollEnd` so listTabular, et al don't need to re-implement it with more timers. Also removing requestAnimationFrame which was causing us to request scrollTop when it was not ready, and caching the values of...
...clientHeight/scrollHeight while scrolling is in-flight
Updating rendered content 10 rows at a time (RangeChunkSize) was a bad idea. Instead, add every row in a render: pass as it comes in (less work all the time vs more work intermittently). Also remove bad requestAnimationFrame, and prevent calls to...
...updateRangeState from triggering additional calls to updateRangeState by removing `componentDidUpdate => updateRangeState `
Turning off hover (pointer-events:none) is now standard in ScrollRegion
Loading text in the scroll tooltip, instead of random date shown
Handle query parse errors by catching error and throwing a better more explanatory error
Replace "quick action" retina images with background images to make React render easier
Replace hasTagId with a faster implementation which doesn't call functions and doesn't build a temporary array
Print query durations when printing to console instead of only in metadata
Remove headers from support from ListTabular, we'll never use it
Making columns part of state was a good idea but changing the array causes the entire ListTabular to re-render. To avoid this, be smarter about updating columns. This logic could potentially go in `componentDidReceiveProps` too.
Fix specs and add 6 more for new database store functionality
Test Plan: Run 6 new specs. More in the works?
Reviewers: evan
Reviewed By: evan
Differential Revision: https://phab.nylas.com/D1651
2015-06-18 11:12:48 +08:00
|
|
|
messagesByThread = {}
|
|
|
|
for id in ids
|
|
|
|
messagesByThread[id] = []
|
|
|
|
for message in messages
|
|
|
|
messagesByThread[message.threadId].push message
|
|
|
|
messagesByThread
|
|
|
|
@setView(view)
|
2015-04-07 02:46:20 +08:00
|
|
|
|
2015-06-12 09:00:40 +08:00
|
|
|
Actions.setFocus(collection: 'thread', item: null)
|
2015-04-01 08:19:17 +08:00
|
|
|
|
feat(selection): add selection of read, unread, starred, etc
Summary:
Can select all, deselect-all, read, unread, starred, unstarred.
Yes, it's not REALLY select "all", but it uses the items in the current
`retainedRange`. This is actually similar to what gmail does (only selects
on the first page of a 100).
Test Plan: new test
Reviewers: juan, bengotow
Reviewed By: bengotow
Differential Revision: https://phab.nylas.com/D2241
2015-11-09 23:03:55 +08:00
|
|
|
_onSelectRead: =>
|
|
|
|
items = @_view.itemsCurrentlyInViewMatching (item) -> not item.unread
|
|
|
|
@_view.selection.set(items)
|
|
|
|
|
|
|
|
_onSelectUnread: =>
|
|
|
|
items = @_view.itemsCurrentlyInViewMatching (item) -> item.unread
|
|
|
|
@_view.selection.set(items)
|
|
|
|
|
|
|
|
_onSelectStarred: =>
|
|
|
|
items = @_view.itemsCurrentlyInViewMatching (item) -> item.starred
|
|
|
|
@_view.selection.set(items)
|
|
|
|
|
|
|
|
_onSelectUnstarred: =>
|
|
|
|
items = @_view.itemsCurrentlyInViewMatching (item) -> not item.starred
|
|
|
|
@_view.selection.set(items)
|
|
|
|
|
2015-04-01 08:19:17 +08:00
|
|
|
# Inbound Events
|
|
|
|
|
2015-09-05 03:23:15 +08:00
|
|
|
_onMailViewChanged: ->
|
2015-06-27 07:15:21 +08:00
|
|
|
@createView()
|
|
|
|
|
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: ->
|
|
|
|
accountId = AccountStore.current()?.id
|
|
|
|
accountMatcher = (m) ->
|
|
|
|
m.attribute() is Thread.attributes.accountId and m.value() is accountId
|
2015-05-22 09:08:29 +08:00
|
|
|
|
2015-12-10 04:35:40 +08:00
|
|
|
return if @_view and _.find(@_view.matchers(), accountMatcher)
|
2015-05-22 09:08:29 +08:00
|
|
|
@createView()
|
2015-04-01 08:19:17 +08:00
|
|
|
|
|
|
|
_onDataChanged: (change) ->
|
2015-07-16 23:54:20 +08:00
|
|
|
return unless @_view
|
|
|
|
|
2015-04-01 08:19:17 +08:00
|
|
|
if change.objectClass is Thread.name
|
2015-10-22 01:38:00 +08:00
|
|
|
focusedId = FocusedContentStore.focusedId('thread')
|
|
|
|
keyboardId = FocusedContentStore.keyboardCursorId('thread')
|
|
|
|
viewModeAutofocuses = WorkspaceStore.layoutMode() is 'split' or WorkspaceStore.topSheet().root is true
|
2015-04-01 08:19:17 +08:00
|
|
|
|
2015-10-22 01:38:00 +08:00
|
|
|
focusedIndex = @_view.indexOfId(focusedId)
|
|
|
|
keyboardIndex = @_view.indexOfId(keyboardId)
|
2015-06-09 08:02:50 +08:00
|
|
|
|
2015-10-22 01:38:00 +08:00
|
|
|
shiftIndex = (i) =>
|
|
|
|
if i > 0 and (@_view.get(i - 1)?.unread or i >= @_view.count())
|
|
|
|
return i - 1
|
|
|
|
else
|
|
|
|
return i
|
2015-06-09 08:02:50 +08:00
|
|
|
|
2015-10-22 01:38:00 +08:00
|
|
|
@_view.invalidate({change: change, shallow: true})
|
2015-09-16 07:49:16 +08:00
|
|
|
|
2015-10-22 01:38:00 +08:00
|
|
|
focusedLost = focusedIndex >= 0 and @_view.indexOfId(focusedId) is -1
|
|
|
|
keyboardLost = keyboardIndex >= 0 and @_view.indexOfId(keyboardId) is -1
|
2015-04-01 08:19:17 +08:00
|
|
|
|
2015-10-22 01:38:00 +08:00
|
|
|
if viewModeAutofocuses and focusedLost
|
|
|
|
Actions.setFocus(collection: 'thread', item: @_view.get(shiftIndex(focusedIndex)))
|
2015-07-22 05:16:11 +08:00
|
|
|
|
2015-10-22 01:38:00 +08:00
|
|
|
if keyboardLost
|
|
|
|
Actions.setCursorPosition(collection: 'thread', item: @_view.get(shiftIndex(keyboardIndex)))
|
2015-07-22 05:16:11 +08:00
|
|
|
|
2015-10-22 01:38:00 +08:00
|
|
|
if change.objectClass is Message.name
|
|
|
|
# Important: Until we optimize this so that it detects the set change
|
|
|
|
# and avoids a query, this should be defered since it's very unimportant
|
|
|
|
_.defer =>
|
|
|
|
threadIds = _.uniq _.map change.objects, (m) -> m.threadId
|
|
|
|
@_view.invalidateMetadataFor(threadIds)
|
2015-07-22 05:16:11 +08:00
|
|
|
|
2015-04-01 08:19:17 +08:00
|
|
|
|
2015-07-16 23:54:20 +08:00
|
|
|
module.exports = new ThreadListStore()
|