From 9ed627f6b029a6416e83d9e410ff88abcc3bb828 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Wed, 28 Jun 2017 13:59:50 -0700 Subject: [PATCH] Remove PerformSendActionTask in favor of immediate local execution --- .../composer/lib/send-action-button.jsx | 2 +- .../lib/sidebar/activity-sidebar.cjsx | 3 +- .../src/flux/stores/draft-store.es6 | 50 ++++++----------- .../flux/tasks/perform-send-action-task.es6 | 56 ------------------- .../client-app/src/global/nylas-exports.es6 | 1 - 5 files changed, 19 insertions(+), 93 deletions(-) delete mode 100644 packages/client-app/src/flux/tasks/perform-send-action-task.es6 diff --git a/packages/client-app/internal_packages/composer/lib/send-action-button.jsx b/packages/client-app/internal_packages/composer/lib/send-action-button.jsx index 52ba45073..5ebe6ba6c 100644 --- a/packages/client-app/internal_packages/composer/lib/send-action-button.jsx +++ b/packages/client-app/internal_packages/composer/lib/send-action-button.jsx @@ -28,7 +28,7 @@ class SendActionButton extends React.Component { _onSendWithAction = (sendAction) => { const {isValidDraft, draft} = this.props if (isValidDraft()) { - Actions.sendDraft(draft.id, sendAction.configKey) + Actions.sendDraft(draft.headerMessageId, sendAction.configKey) } } diff --git a/packages/client-app/internal_packages/notifications/lib/sidebar/activity-sidebar.cjsx b/packages/client-app/internal_packages/notifications/lib/sidebar/activity-sidebar.cjsx index 3abf1b6ea..1f9b15314 100644 --- a/packages/client-app/internal_packages/notifications/lib/sidebar/activity-sidebar.cjsx +++ b/packages/client-app/internal_packages/notifications/lib/sidebar/activity-sidebar.cjsx @@ -13,10 +13,9 @@ SyncbackActivity = require("./syncback-activity").default AccountStore, FolderSyncProgressStore, TaskQueue, - PerformSendActionTask, SendDraftTask} = require 'nylas-exports' -SEND_TASK_CLASSES = [PerformSendActionTask, SendDraftTask] +SEND_TASK_CLASSES = [SendDraftTask] class ActivitySidebar extends React.Component @displayName: 'ActivitySidebar' diff --git a/packages/client-app/src/flux/stores/draft-store.es6 b/packages/client-app/src/flux/stores/draft-store.es6 index 68f257257..083b45115 100644 --- a/packages/client-app/src/flux/stores/draft-store.es6 +++ b/packages/client-app/src/flux/stores/draft-store.es6 @@ -8,7 +8,6 @@ import DatabaseStore from './database-store'; import SendActionsStore from './send-actions-store'; import FocusedContentStore from './focused-content-store'; import BaseDraftTask from '../tasks/base-draft-task'; -import PerformSendActionTask from '../tasks/perform-send-action-task'; import SyncbackDraftTask from '../tasks/syncback-draft-task'; import DestroyDraftTask from '../tasks/destroy-draft-task'; import Thread from '../models/thread'; @@ -58,7 +57,6 @@ class DraftStore extends NylasStore { this.listenTo(Actions.ensureDraftSynced, this._onEnsureDraftSynced); this.listenTo(Actions.sendDraft, this._onSendDraft); this.listenTo(Actions.destroyDraft, this._onDestroyDraft); - this.listenTo(Actions.removeFile, this._onRemoveFile); NylasEnv.onBeforeUnload(this._onBeforeUnload); @@ -369,40 +367,26 @@ class DraftStore extends NylasStore { }); } - _onSendDraft = (headerMessageId, sendActionKey = DefaultSendActionKey) => { + _onSendDraft = async (headerMessageId, sendActionKey = DefaultSendActionKey) => { this._draftsSending[headerMessageId] = true; - return this.sessionForClientId(headerMessageId).then((session) => { - return DraftHelpers.prepareDraftForSyncback(session) - .then(() => { - Actions.queueTask(new PerformSendActionTask(headerMessageId, sendActionKey)); - this._doneWithSession(session); - if (NylasEnv.config.get("core.sending.sounds")) { - SoundRegistry.playSound('hit-send'); - } - if (NylasEnv.isComposerWindow()) { - NylasEnv.close(); - } - }); - }); - } - __testExtensionTransforms() { - const headerMessageId = NylasEnv.getWindowProps().headerMessageId; - return this.sessionForClientId(headerMessageId).then((session) => { - return this._prepareForSyncback(session).then(() => { - window.__draft = session.draft(); - console.log("Done transforming draft. Available at window.__draft"); - }); - }); - } + const sendAction = SendActionsStore.sendActionForKey(sendActionKey) + if (!sendAction) { + throw new Error(`Cant find send action ${sendActionKey} `); + } - _onRemoveFile = ({file, headerMessageId}) => { - return this.sessionForClientId(headerMessageId).then((session) => { - let files = _.clone(session.draft().files) || []; - files = _.reject(files, (f) => f.id === file.id); - session.changes.add({files}); - return session.changes.commit(); - }); + if (NylasEnv.config.get("core.sending.sounds")) { + SoundRegistry.playSound('hit-send'); + } + + const session = await this.sessionForClientId(headerMessageId); + await DraftHelpers.prepareDraftForSyncback(session) + await sendAction.performSendAction({draft: session.draft()}); + this._doneWithSession(session); + + if (NylasEnv.isComposerWindow()) { + NylasEnv.close(); + } } _onDidCancelSendAction = ({headerMessageId}) => { diff --git a/packages/client-app/src/flux/tasks/perform-send-action-task.es6 b/packages/client-app/src/flux/tasks/perform-send-action-task.es6 deleted file mode 100644 index 5395c5d6a..000000000 --- a/packages/client-app/src/flux/tasks/perform-send-action-task.es6 +++ /dev/null @@ -1,56 +0,0 @@ -import Task from './task'; -import Actions from '../actions'; -import BaseDraftTask from './base-draft-task'; -import TaskQueue from '../stores/task-queue'; -import SendActionsStore from '../stores/send-actions-store'; - - -class PerformSendActionTask extends BaseDraftTask { - - constructor(headerMessageId, sendActionKey) { - super(headerMessageId) - this._sendActionKey = sendActionKey - this._sendTimer = null - this._taskResolve = () => {} - } - - label() { - return "Sending message"; - } - - shouldDequeueOtherTask(otherTask) { - return ( - otherTask instanceof PerformSendActionTask && - this.headerMessageId === otherTask.headerMessageId - ) - } - - performLocal() { - if (!this.headerMessageId) { - const errMsg = `Attempt to call ${this.constructor.name}.performLocal without a headerMessageId`; - return Promise.reject(new Error(errMsg)); - } - return Promise.resolve() - } - - cancel() { - const {id: taskId, headerMessageId} = this - clearTimeout(this._sendTimer) - Actions.didCancelSendAction({taskId, headerMessageId}) - this._taskResolve(Task.Status.Continue) - } - - _performSendAction() { - return this.refreshDraftReference() - .then((draft) => { - const sendAction = SendActionsStore.sendActionForKey(this._sendActionKey) - if (!sendAction) { - return Promise.reject(new Error(`Cant find send action ${this._sendActionKey} `)) - } - const {performSendAction} = sendAction - return performSendAction({draft}) - }) - } -} - -export default PerformSendActionTask diff --git a/packages/client-app/src/global/nylas-exports.es6 b/packages/client-app/src/global/nylas-exports.es6 index c51b23dbf..cbb643693 100644 --- a/packages/client-app/src/global/nylas-exports.es6 +++ b/packages/client-app/src/global/nylas-exports.es6 @@ -115,7 +115,6 @@ lazyLoadAndRegisterTask(`SyncbackEventTask`, 'syncback-event-task'); lazyLoadAndRegisterTask(`DestroyCategoryTask`, 'destroy-category-task'); lazyLoadAndRegisterTask(`SyncbackCategoryTask`, 'syncback-category-task'); lazyLoadAndRegisterTask(`SyncbackMetadataTask`, 'syncback-metadata-task'); -lazyLoadAndRegisterTask(`PerformSendActionTask`, 'perform-send-action-task'); lazyLoadAndRegisterTask(`ReprocessMailRulesTask`, 'reprocess-mail-rules-task'); lazyLoadAndRegisterTask(`SendFeatureUsageEventTask`, 'send-feature-usage-event-task'); lazyLoadAndRegisterTask(`EnsureMessageInSentFolderTask`, 'ensure-message-in-sent-folder-task');