Mailspring/internal_packages/thread-list/lib/draft-list-store.coffee
Juan Tejada 9f998d1964 refactor(rip-current-account): Rips out AccountStore.current
Summary:
- WIP: Need to fix tests and some errors!
- Refactors Category class to hold information about its type
- Refactors CategoryStore to rely on observables instead of local caches
- Adds and updates Observables and helpers
- Refactors ContactStore to hold entire cache of contacts instead of per
  current account
  - Same for ContactRankingStore and other stores
- Refactors method names for AccountStore + some helpers
- Updates MailViewFilter to hold an account
  - Adds basic Unified filter
- Replaces AccountStore.current calls with either:
  - The account of the currently focused MailViewFilter
  - The account associated with a thread, message, file, etc...
  - A parameter to be passed in
  - Arbitrarily, the first account in the AccountsStore

Test Plan: - Unit tests

Reviewers: evan, bengotow

Differential Revision: https://phab.nylas.com/D2423
2016-01-08 14:22:13 -08:00

55 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 = FocusedMailViewStore.mailView()?.account
if @unlisten
@unlisten()
@_view = null
matchers = [
Message.attributes.draft.equal(true)
]
if account?
matchers.push(Message.attributes.accountId.equal(account.id))
@_view = new DatabaseView Message,
matchers: matchers,
includes: [Message.attributes.body]
orders: [Message.attributes.date.descending()]
@unlisten = @_view.listen => @trigger({})
_onAccountChanged: =>
@_createView()
_onDataChanged: (change) =>
return unless change.objectClass is Message.name
return unless @_view
@_view.invalidate({change: change, shallow: true})
module.exports = new DraftListStore()