mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-23 00:36:50 +08:00
65 lines
1.7 KiB
JavaScript
65 lines
1.7 KiB
JavaScript
import {
|
|
ComponentRegistry,
|
|
DatabaseStore,
|
|
SyncbackMetadataTask,
|
|
Message,
|
|
SendActionsStore,
|
|
Actions,
|
|
} from 'nylas-exports';
|
|
import { HasTutorialTip } from 'nylas-component-kit';
|
|
|
|
import SendLaterButton from './send-later-button';
|
|
import SendLaterStatus from './send-later-status';
|
|
import { PLUGIN_ID } from './send-later-constants';
|
|
|
|
const SendLaterButtonWithTip = HasTutorialTip(SendLaterButton, {
|
|
title: 'Send on your own schedule',
|
|
instructions:
|
|
'Schedule this message to send at the ideal time. N1 makes it easy to control the fabric of spacetime!',
|
|
});
|
|
|
|
let unlisten = null;
|
|
|
|
export function activate() {
|
|
ComponentRegistry.register(SendLaterButtonWithTip, { role: 'Composer:ActionButton' });
|
|
ComponentRegistry.register(SendLaterStatus, { role: 'DraftList:DraftStatus' });
|
|
|
|
unlisten = DatabaseStore.listen(change => {
|
|
if (change.type !== 'metadata-expiration' || change.objectClass !== Message.name) {
|
|
return;
|
|
}
|
|
for (const message of change.objects) {
|
|
const metadata = message.metadataForPluginId(PLUGIN_ID);
|
|
if (!metadata || !metadata.expiration || metadata.expiration > new Date()) {
|
|
continue;
|
|
}
|
|
|
|
// clear the metadata
|
|
Actions.queueTask(
|
|
new SyncbackMetadataTask({
|
|
model: message,
|
|
pluginId: PLUGIN_ID,
|
|
value: {
|
|
expiration: null,
|
|
},
|
|
})
|
|
);
|
|
|
|
if (!message.draft) {
|
|
continue;
|
|
}
|
|
|
|
// send the draft
|
|
Actions.sendDraft(message.headerMessageId, SendActionsStore.DefaultSendActionKey);
|
|
}
|
|
});
|
|
}
|
|
|
|
export function deactivate() {
|
|
ComponentRegistry.unregister(SendLaterButtonWithTip);
|
|
ComponentRegistry.unregister(SendLaterStatus);
|
|
unlisten();
|
|
}
|
|
|
|
export function serialize() {}
|