mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-22 00:06:06 +08:00
fix(draft-store): Don't pop up a draft before it exists in the session
Summary: The composer wasn't popping out correctly because the session's draft was still null. This diff switches to using sessionForClientId(), even if the session already exists in _draftSessions, because sessionForClientId() won't create a new session if it doesn't need to, and will always return a promise that resolves once the session gets its draft. This promise will resolve immediately if the session already has a draft. Test Plan: tested locally Reviewers: evan, juan Reviewed By: juan Subscribers: juan, spang Differential Revision: https://phab.nylas.com/D3531
This commit is contained in:
parent
cb6f761df3
commit
2441db6546
|
@ -289,29 +289,20 @@ class DraftStore extends NylasStore {
|
|||
}
|
||||
NylasEnv.perf.start("Popout Draft");
|
||||
|
||||
let draftJSON = null;
|
||||
let save = Promise.resolve();
|
||||
if (this._draftSessions[draftClientId]) {
|
||||
save = this._draftSessions[draftClientId].changes.commit().then(() => {
|
||||
draftJSON = this._draftSessions[draftClientId].draft().toJSON();
|
||||
})
|
||||
} else {
|
||||
save = this.sessionForClientId(draftClientId).then((session) => {
|
||||
draftJSON = session.draft().toJSON();
|
||||
});
|
||||
}
|
||||
|
||||
const title = options.newDraft ? "New Message" : "Message";
|
||||
return save.then(() => {
|
||||
// Since we pass a windowKey, if the popout composer draft already
|
||||
// exists we'll simply show that one instead of spawning a whole new
|
||||
// window.
|
||||
NylasEnv.newWindow({
|
||||
title,
|
||||
hidden: true, // We manually show in ComposerWithWindowProps::onDraftReady
|
||||
windowKey: `composer-${draftClientId}`,
|
||||
windowType: "composer-preload",
|
||||
windowProps: _.extend(options, {draftClientId, draftJSON}),
|
||||
return this.sessionForClientId(draftClientId).then((session) => {
|
||||
return session.changes.commit().then(() => {
|
||||
const draftJSON = session.draft().toJSON();
|
||||
// Since we pass a windowKey, if the popout composer draft already
|
||||
// exists we'll simply show that one instead of spawning a whole new
|
||||
// window.
|
||||
NylasEnv.newWindow({
|
||||
title,
|
||||
hidden: true, // We manually show in ComposerWithWindowProps::onDraftReady
|
||||
windowKey: `composer-${draftClientId}`,
|
||||
windowType: "composer-preload",
|
||||
windowProps: _.extend(options, {draftClientId, draftJSON}),
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue