mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-12 20:44:30 +08:00
f8c5f7b967
Summary: Major ID refactor Test Plan: edgehill --test Reviewers: bengotow, dillon Differential Revision: https://phab.nylas.com/D1946
56 lines
1.3 KiB
CoffeeScript
56 lines
1.3 KiB
CoffeeScript
Reflux = require 'reflux'
|
|
_ = require 'underscore'
|
|
{Message,
|
|
Actions,
|
|
DatabaseStore,
|
|
AccountStore,
|
|
FocusedContentStore,
|
|
DestroyDraftTask,
|
|
DatabaseView} = require 'nylas-exports'
|
|
|
|
module.exports =
|
|
DraftListStore = Reflux.createStore
|
|
init: ->
|
|
@listenTo DatabaseStore, @_onDataChanged
|
|
@listenTo AccountStore, @_onAccountChanged
|
|
@listenTo Actions.deleteSelection, @_onDeleteSelection
|
|
@_createView()
|
|
|
|
view: ->
|
|
@_view
|
|
|
|
_createView: ->
|
|
account = AccountStore.current()
|
|
|
|
if @unlisten
|
|
@unlisten()
|
|
@_view = null
|
|
|
|
return unless account
|
|
|
|
@_view = new DatabaseView Message,
|
|
matchers: [
|
|
Message.attributes.accountId.equal(account.id)
|
|
Message.attributes.draft.equal(true)
|
|
],
|
|
includes: [Message.attributes.body]
|
|
orders: [Message.attributes.date.descending()]
|
|
|
|
@unlisten = @_view.listen => @trigger({})
|
|
|
|
_onAccountChanged: ->
|
|
@_createView()
|
|
|
|
_onDataChanged: (change) ->
|
|
return unless change.objectClass is Message.name
|
|
containsDraft = _.some(change.objects, (msg) -> msg.draft)
|
|
return unless containsDraft
|
|
@_view.invalidate()
|
|
|
|
_onDeleteSelection: ->
|
|
selected = @_view.selection.items()
|
|
|
|
for item in selected
|
|
Actions.queueTask(new DestroyDraftTask(draftClientId: item.clientId))
|
|
|
|
@_view.selection.clear()
|