2015-05-20 07:06:59 +08:00
|
|
|
_ = require 'underscore'
|
2017-09-27 02:46:00 +08:00
|
|
|
MailspringStore = require 'mailspring-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,
|
2017-06-23 06:07:04 +08:00
|
|
|
TaskQueue,
|
2017-09-27 02:42:18 +08:00
|
|
|
FocusedPerspectiveStore} = require 'mailspring-exports'
|
2017-09-27 02:46:00 +08:00
|
|
|
{ListTabular} = require 'mailspring-component-kit'
|
2015-07-16 23:54:20 +08:00
|
|
|
|
2016-10-27 08:09:13 +08:00
|
|
|
ThreadListDataSource = require('./thread-list-data-source').default
|
2016-01-09 06:31:33 +08:00
|
|
|
|
2017-09-27 02:46:00 +08:00
|
|
|
class ThreadListStore extends MailspringStore
|
2015-07-16 23:54:20 +08:00
|
|
|
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-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()
|