mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-25 00:25:03 +08:00
Remove more draft syncback code
This commit is contained in:
parent
b3394d54fd
commit
8afda8e3d4
5 changed files with 14 additions and 50 deletions
|
@ -2,7 +2,6 @@ import {
|
|||
Actions,
|
||||
Message,
|
||||
DraftHelpers,
|
||||
DatabaseStore,
|
||||
} from 'nylas-exports';
|
||||
|
||||
import InlineStyleTransformer from '../../src/services/inline-style-transformer'
|
||||
|
|
|
@ -324,7 +324,7 @@ xdescribe('DraftStore', function draftStore() {
|
|||
|
||||
DraftStore._draftSessions[this.draft.clientId] = session;
|
||||
spyOn(DraftStore, "_doneWithSession").andCallThrough();
|
||||
spyOn(DraftHelpers, "prepareDraftForSyncback").andReturn(Promise.resolve());
|
||||
spyOn(DraftHelpers, "draftPreparedForSyncback").andReturn(Promise.resolve());
|
||||
spyOn(DraftStore, "trigger");
|
||||
spyOn(SoundRegistry, "playSound");
|
||||
spyOn(Actions, "queueTask");
|
||||
|
|
|
@ -405,7 +405,6 @@ class Actions {
|
|||
static ensureMessageInSentSuccess = ActionScopeGlobal;
|
||||
|
||||
static sendManyDrafts = ActionScopeWindow;
|
||||
static ensureDraftSynced = ActionScopeWindow;
|
||||
|
||||
/*
|
||||
Public: Destroys the draft with the given ID. This Action is handled by the {DraftStore},
|
||||
|
|
|
@ -66,34 +66,12 @@ class DraftHelpers {
|
|||
return (cleaned.indexOf("attach") >= 0);
|
||||
}
|
||||
|
||||
async refreshDraftReference(id) {
|
||||
const message = await DatabaseStore
|
||||
.findBy(Message, {id: id})
|
||||
.include(Message.attributes.body)
|
||||
|
||||
if (!message || !message.draft) {
|
||||
throw new this.DraftNotFoundError()
|
||||
}
|
||||
|
||||
return message
|
||||
}
|
||||
|
||||
async pruneRemovedInlineFiles(draft) {
|
||||
if (!(draft.files instanceof Array) || draft.files.length === 0) {
|
||||
// The async keyword makes it so this is returned as a promise, which
|
||||
// allows us to always treat the return value of this function as a
|
||||
// promise-like object.
|
||||
return draft;
|
||||
}
|
||||
return DatabaseStore.inTransaction(async (t) => {
|
||||
// Inline files that are no longer referenced in the body are stale
|
||||
draft.files = draft.files.filter(f => {
|
||||
return !(f.contentId && !draft.body.includes(`cid:${f.id}`))
|
||||
});
|
||||
|
||||
await t.persistModel(draft);
|
||||
return draft;
|
||||
draft.files = draft.files.filter(f => {
|
||||
return !(f.contentId && !draft.body.includes(`cid:${f.id}`))
|
||||
});
|
||||
|
||||
return draft;
|
||||
}
|
||||
|
||||
appendQuotedTextToDraft(draft) {
|
||||
|
@ -144,17 +122,15 @@ class DraftHelpers {
|
|||
});
|
||||
}
|
||||
|
||||
async prepareDraftForSyncback(session) {
|
||||
async draftPreparedForSyncback(session) {
|
||||
await session.ensureCorrectAccount({noSyncback: true})
|
||||
const transformed = await this.applyExtensionTransforms(session.draft())
|
||||
let draft;
|
||||
if (!transformed.replyToMessageId || !this.shouldAppendQuotedText(transformed)) {
|
||||
draft = transformed;
|
||||
} else {
|
||||
draft = await this.appendQuotedTextToDraft(transformed);
|
||||
}
|
||||
let draft = session.draft();
|
||||
|
||||
draft = await this.applyExtensionTransforms(draft)
|
||||
draft = await this.pruneRemovedInlineFiles(draft);
|
||||
await DatabaseStore.inTransaction((t) => t.persistModel(draft))
|
||||
if (draft.replyToMessageId && this.shouldAppendQuotedText(draft)) {
|
||||
draft = await this.appendQuotedTextToDraft(draft);
|
||||
}
|
||||
return draft;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,6 @@ class DraftStore extends NylasStore {
|
|||
// Remember that these two actions only fire in the current window and
|
||||
// are picked up by the instance of the DraftStore in the current
|
||||
// window.
|
||||
this.listenTo(Actions.ensureDraftSynced, this._onEnsureDraftSynced);
|
||||
this.listenTo(Actions.sendDraft, this._onSendDraft);
|
||||
this.listenTo(Actions.destroyDraft, this._onDestroyDraft);
|
||||
|
||||
|
@ -361,15 +360,6 @@ class DraftStore extends NylasStore {
|
|||
}
|
||||
}
|
||||
|
||||
_onEnsureDraftSynced = (headerMessageId) => {
|
||||
return this.sessionForClientId(headerMessageId).then((session) => {
|
||||
return DraftHelpers.prepareDraftForSyncback(session)
|
||||
.then(() => {
|
||||
Actions.queueTask(new SyncbackDraftTask(headerMessageId));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
_onSendDraft = async (headerMessageId, sendActionKey = DefaultSendActionKey) => {
|
||||
this._draftsSending[headerMessageId] = true;
|
||||
|
||||
|
@ -383,8 +373,8 @@ class DraftStore extends NylasStore {
|
|||
}
|
||||
|
||||
const session = await this.sessionForClientId(headerMessageId);
|
||||
await DraftHelpers.prepareDraftForSyncback(session)
|
||||
await sendAction.performSendAction({draft: session.draft()});
|
||||
const draft = await DraftHelpers.draftPreparedForSyncback(session);
|
||||
await sendAction.performSendAction({draft});
|
||||
this._doneWithSession(session);
|
||||
|
||||
if (NylasEnv.isComposerWindow()) {
|
||||
|
|
Loading…
Reference in a new issue