mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-23 00:36:50 +08:00
552b66fbaf
Summary: This diff replaces "finalizeSessionBeforeSending" with a plugin hook that is bidirectional and allows us to put the draft in the "ready to send" state every time we save it, and restore it to the "ready to edit" state every time a draft session is created to edit it. This diff also significantly restructures the draft tasks: 1. SyncbackDraftUploadsTask: - ensures that `uploads` are converted to `files` and that any existing files on the draft are part of the correct account. 1. SyncbackDraftTask: - saves the draft, nothing else. 3. SendDraftTask - sends the draft, nothing else. - deletes the entire uploads directory for the draft Test Plan: WIP Reviewers: juan, evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D2753
68 lines
2.1 KiB
CoffeeScript
68 lines
2.1 KiB
CoffeeScript
NylasStore = require 'nylas-store'
|
|
Rx = require 'rx-lite'
|
|
_ = require 'underscore'
|
|
{Message,
|
|
OutboxStore,
|
|
MutableQueryResultSet,
|
|
MutableQuerySubscription,
|
|
ObservableListDataSource,
|
|
FocusedPerspectiveStore,
|
|
DatabaseStore} = require 'nylas-exports'
|
|
{ListTabular} = require 'nylas-component-kit'
|
|
|
|
class DraftListStore extends NylasStore
|
|
constructor: ->
|
|
@listenTo FocusedPerspectiveStore, @_onPerspectiveChanged
|
|
@_createListDataSource()
|
|
|
|
dataSource: =>
|
|
@_dataSource
|
|
|
|
# Inbound Events
|
|
|
|
_onPerspectiveChanged: =>
|
|
@_createListDataSource()
|
|
|
|
# Internal
|
|
|
|
_createListDataSource: =>
|
|
mailboxPerspective = FocusedPerspectiveStore.current()
|
|
|
|
if mailboxPerspective.drafts
|
|
query = DatabaseStore.findAll(Message)
|
|
.include(Message.attributes.body)
|
|
.order(Message.attributes.date.descending())
|
|
.where(draft: true, accountId: mailboxPerspective.accountIds)
|
|
.page(0, 1)
|
|
|
|
subscription = new MutableQuerySubscription(query, {asResultSet: true})
|
|
$resultSet = Rx.Observable.fromNamedQuerySubscription('draft-list', subscription)
|
|
$resultSet = Rx.Observable.combineLatest [
|
|
$resultSet,
|
|
Rx.Observable.fromStore(OutboxStore)
|
|
], (resultSet, outbox) =>
|
|
|
|
# Generate a new result set that includes additional information on
|
|
# the draft objects. This is similar to what we do in the thread-list,
|
|
# where we set thread.metadata to the message array.
|
|
resultSetWithTasks = new MutableQueryResultSet(resultSet)
|
|
|
|
mailboxPerspective.accountIds.forEach (aid) =>
|
|
OutboxStore.itemsForAccount(aid).forEach (task) =>
|
|
draft = resultSet.modelWithId(task.draftClientId)
|
|
if draft
|
|
draft = draft.clone()
|
|
draft.uploadTaskId = task.id
|
|
draft.uploadProgress = task.progress
|
|
resultSetWithTasks.replaceModel(draft)
|
|
|
|
return resultSetWithTasks.immutableClone()
|
|
|
|
@_dataSource = new ObservableListDataSource($resultSet, subscription.replaceRange)
|
|
else
|
|
@_dataSource = new ListTabular.DataSource.Empty()
|
|
|
|
@trigger(@)
|
|
|
|
module.exports = new DraftListStore()
|