mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-12-27 02:23:28 +08:00
Fix for sending drafts twice due to back-to-back saves
This commit is contained in:
parent
ad970a7997
commit
3767d056ef
1 changed files with 11 additions and 17 deletions
|
@ -1,7 +1,7 @@
|
|||
import {
|
||||
ComponentRegistry,
|
||||
DatabaseStore,
|
||||
SyncbackMetadataTask,
|
||||
DraftStore,
|
||||
Message,
|
||||
SendActionsStore,
|
||||
Actions,
|
||||
|
@ -24,31 +24,25 @@ function handleMetadataExpiration(change) {
|
|||
if (change.type !== 'metadata-expiration' || change.objectClass !== Message.name) {
|
||||
return;
|
||||
}
|
||||
for (const message of change.objects) {
|
||||
|
||||
change.objects.forEach(async message => {
|
||||
const metadata = message.metadataForPluginId(PLUGIN_ID);
|
||||
if (!metadata || !metadata.expiration || metadata.expiration > new Date()) {
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
if (!message.draft) {
|
||||
return;
|
||||
}
|
||||
|
||||
// clear the metadata
|
||||
Actions.queueTask(
|
||||
SyncbackMetadataTask.forSaving({
|
||||
model: message,
|
||||
pluginId: PLUGIN_ID,
|
||||
value: {
|
||||
expiration: null,
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
if (!message.draft) {
|
||||
continue;
|
||||
}
|
||||
const session = await DraftStore.sessionForClientId(message.headerMessageId);
|
||||
session.changes.addPluginMetadata(PLUGIN_ID, { expiration: null });
|
||||
session.changes.commit();
|
||||
|
||||
// send the draft
|
||||
const actionKey = metadata.actionKey || SendActionsStore.DefaultSendActionKey;
|
||||
Actions.sendDraft(message.headerMessageId, { actionKey, delay: 0 });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function activate() {
|
||||
|
|
Loading…
Reference in a new issue