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
|
|
|
|
2016-03-18 00:50:30 +08:00
|
|
|
{Rx,
|
|
|
|
Thread,
|
2015-07-16 23:54:20 +08:00
|
|
|
Message,
|
|
|
|
Actions,
|
|
|
|
DatabaseStore,
|
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,
|
2016-01-09 06:58:31 +08:00
|
|
|
FocusedPerspectiveStore} = require 'nylas-exports'
|
2016-01-26 08:36:56 +08:00
|
|
|
{ListTabular} = require 'nylas-component-kit'
|
2015-07-16 23:54:20 +08:00
|
|
|
|
2016-01-16 06:26:07 +08:00
|
|
|
ThreadListDataSource = require './thread-list-data-source'
|
2016-01-09 06:31:33 +08:00
|
|
|
|
2015-07-16 23:54:20 +08:00
|
|
|
class ThreadListStore extends NylasStore
|
|
|
|
constructor: ->
|
2016-01-13 01:49:49 +08:00
|
|
|
@listenTo FocusedPerspectiveStore, @_onPerspectiveChanged
|
2016-01-15 07:04:17 +08:00
|
|
|
@createListDataSource()
|
2015-05-22 09:08:29 +08:00
|
|
|
|
2016-01-16 06:26:07 +08:00
|
|
|
dataSource: =>
|
2016-01-15 07:04:17 +08:00
|
|
|
@_dataSource
|
2015-04-01 08:19:17 +08:00
|
|
|
|
2016-01-16 06:26:07 +08:00
|
|
|
createListDataSource: =>
|
|
|
|
@_dataSourceUnlisten?()
|
2016-01-26 08:36:56 +08:00
|
|
|
@_dataSource = null
|
|
|
|
|
|
|
|
threadsSubscription = FocusedPerspectiveStore.current().threads()
|
|
|
|
if threadsSubscription
|
|
|
|
@_dataSource = new ThreadListDataSource(threadsSubscription)
|
|
|
|
@_dataSourceUnlisten = @_dataSource.listen(@_onDataChanged, @)
|
|
|
|
|
|
|
|
else
|
|
|
|
@_dataSource = new ListTabular.DataSource.Empty()
|
2015-11-19 04:28:54 +08:00
|
|
|
|
2015-04-07 02:46:20 +08:00
|
|
|
@trigger(@)
|
2016-01-15 07:04:17 +08:00
|
|
|
Actions.setFocus(collection: 'thread', item: null)
|
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
|
|
|
|
2016-03-18 00:50:30 +08:00
|
|
|
selectionObservable: =>
|
|
|
|
return Rx.Observable.fromListSelection(@)
|
|
|
|
|
2015-04-01 08:19:17 +08:00
|
|
|
# Inbound Events
|
|
|
|
|
2016-01-16 06:26:07 +08:00
|
|
|
_onPerspectiveChanged: =>
|
2016-03-25 06:39:30 +08:00
|
|
|
if FocusedPerspectiveStore.current().searchQuery is undefined
|
|
|
|
Actions.dismissNotificationsMatching({tag: 'search-error'})
|
2016-01-15 07:04:17 +08:00
|
|
|
@createListDataSource()
|
2015-06-27 07:15:21 +08:00
|
|
|
|
2016-01-15 07:04:17 +08:00
|
|
|
_onDataChanged: ({previous, next} = {}) =>
|
2016-01-30 04:34:58 +08:00
|
|
|
# This code keeps the focus and keyboard cursor in sync with the thread list.
|
|
|
|
# When the thread list changes, it looks to see if the focused thread is gone,
|
|
|
|
# or no longer matches the query criteria and advances the focus to the next
|
|
|
|
# thread.
|
|
|
|
|
|
|
|
# This means that removing a thread from view in any way causes selection
|
|
|
|
# to advance to the adjacent thread. Nice and declarative.
|
|
|
|
|
2016-01-09 06:31:33 +08:00
|
|
|
if previous and next
|
2016-01-30 04:34:58 +08:00
|
|
|
focused = FocusedContentStore.focused('thread')
|
|
|
|
keyboard = FocusedContentStore.keyboardCursor('thread')
|
2015-10-22 01:38:00 +08:00
|
|
|
viewModeAutofocuses = WorkspaceStore.layoutMode() is 'split' or WorkspaceStore.topSheet().root is true
|
2016-01-30 04:34:58 +08:00
|
|
|
matchers = next.query()?.matchers()
|
2015-04-01 08:19:17 +08:00
|
|
|
|
2016-01-30 04:34:58 +08:00
|
|
|
focusedIndex = if focused then previous.offsetOfId(focused.id) else -1
|
|
|
|
keyboardIndex = if keyboard then previous.offsetOfId(keyboard.id) else -1
|
2015-06-09 08:02:50 +08:00
|
|
|
|
2016-01-30 04:34:58 +08:00
|
|
|
nextItemFromIndex = (i) =>
|
2016-01-09 06:31:33 +08:00
|
|
|
if i > 0 and (next.modelAtOffset(i - 1)?.unread or i >= next.count())
|
2016-01-30 04:34:58 +08:00
|
|
|
nextIndex = i - 1
|
2015-10-22 01:38:00 +08:00
|
|
|
else
|
2016-01-30 04:34:58 +08:00
|
|
|
nextIndex = i
|
2015-06-09 08:02:50 +08:00
|
|
|
|
2016-01-30 04:34:58 +08:00
|
|
|
# May return null if no thread is loaded at the next index
|
|
|
|
next.modelAtOffset(nextIndex)
|
|
|
|
|
|
|
|
notInSet = (model) ->
|
|
|
|
if matchers
|
|
|
|
return model.matches(matchers) is false
|
|
|
|
else
|
|
|
|
return next.offsetOfId(model.id) is -1
|
2015-04-01 08:19:17 +08:00
|
|
|
|
2016-01-30 04:34:58 +08:00
|
|
|
if viewModeAutofocuses and focused and notInSet(focused)
|
|
|
|
Actions.setFocus(collection: 'thread', item: nextItemFromIndex(focusedIndex))
|
2015-07-22 05:16:11 +08:00
|
|
|
|
2016-01-30 04:34:58 +08:00
|
|
|
if keyboard and notInSet(keyboard)
|
|
|
|
Actions.setCursorPosition(collection: 'thread', item: nextItemFromIndex(keyboardIndex))
|
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()
|