Mailspring/internal_packages/thread-list/lib/draft-list-store.coffee
Ben Gotow 4f34c8403f feat(trash): Trash for Gmail, and architectural changes for common tasks
Summary:
This diff centralizes logic for creating common tasks for things like moving to trash, archive, etc. TaskFactory exposes a set of convenience methods and hides the whole "and also remove the current label" business from the user.

This diff also formally separates the concept of "moving to trash" and "archiving" so that "remove" isn't used in an unclear way.

I also refactored where selection is managed. Previously you'd fire some action like archiveSelection and it'd clear the selection, but if you selected some items and used another method to archive a few, they were still selected. The selection is now bound to the ModelView as intended, so if items are removed from the modelView, they are removed from it's attached selection. This means that it shouldn't /technically/ be possible to have selected items which are not in view.

I haven't refactored the tests yet. They are likely broken...

Fix next/prev logic

Test Plan: Run tests

Reviewers: evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D2157
2015-10-21 10:38:00 -07:00

54 lines
1.4 KiB
CoffeeScript

NylasStore = require 'nylas-store'
Reflux = require 'reflux'
_ = require 'underscore'
{Message,
Actions,
DatabaseStore,
AccountStore,
FocusedContentStore,
DestroyDraftTask,
DatabaseView} = require 'nylas-exports'
class DraftListStore extends NylasStore
constructor: ->
@listenTo DatabaseStore, @_onDataChanged
@listenTo AccountStore, @_onAccountChanged
# It's important to listen to sendDraftSuccess because the
# _onDataChanged method will ignore our newly created draft because it
# has its draft bit set to false (since it's now a message)!
@listenTo Actions.sendDraftSuccess, => @_view.invalidate()
@_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 and @_view
@_view.invalidate()
module.exports = new DraftListStore()