Fix exception thrown when rapidly clicking Trash icon

This commit is contained in:
Ben Gotow 2017-11-07 02:04:26 +01:00
parent e0260c0f1a
commit 156b7cb615
2 changed files with 5 additions and 2 deletions

View file

@ -206,7 +206,7 @@ class DraftFactory
else if behavior is 'prefer-existing-if-pristine'
DraftStore ?= require('./draft-store').default
return Promise.all(candidateDrafts.map (candidateDraft) =>
DraftStore.sessionForId(candidateDraft.id)
DraftStore.sessionForClientId(candidateDraft.headerMessageId)
).then (sessions) =>
for session in sessions
if session.draft().pristine

View file

@ -107,6 +107,9 @@ class DraftStore extends MailspringStore {
// window.close() within on onbeforeunload could do weird things.
Object.values(this._draftSessions).forEach(session => {
const draft = session.draft();
if (!draft.id) {
return;
}
if (draft && draft.pristine) {
Actions.queueTask(
new DestroyDraftTask({
@ -228,7 +231,7 @@ class DraftStore extends MailspringStore {
queries.message = DatabaseStore.findAll(Message, { threadId: threadId || thread.id })
.order(Message.attributes.date.descending())
.include(Message.attributes.body)
.limit(5)
.limit(10)
.then(messages => messages.find(m => !m.isHidden()));
}