2016-03-01 10:47:22 +08:00
|
|
|
import {ComposerExtension} from 'nylas-exports';
|
|
|
|
import SignatureUtils from './signature-utils';
|
2016-03-15 08:04:40 +08:00
|
|
|
import SignatureStore from './signature-store';
|
2016-03-01 10:47:22 +08:00
|
|
|
|
|
|
|
export default class SignatureComposerExtension extends ComposerExtension {
|
2016-03-15 08:04:40 +08:00
|
|
|
static prepareNewDraft = ({draft}) => {
|
2016-03-01 10:47:22 +08:00
|
|
|
const accountId = draft.accountId;
|
2016-03-15 08:04:40 +08:00
|
|
|
const signature = SignatureStore.signatureForAccountId(accountId);
|
2016-03-01 10:47:22 +08:00
|
|
|
if (!signature) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
draft.body = SignatureUtils.applySignature(draft.body, signature);
|
|
|
|
}
|
2016-03-18 04:11:00 +08:00
|
|
|
|
|
|
|
static finalizeSessionBeforeSending = ({session}) => {
|
|
|
|
// remove the <signature> element from the DOM,
|
|
|
|
// essentially unwraps the signature
|
|
|
|
const body = session.draft().body;
|
|
|
|
const changed = body.replace(/<\/?signature>/g, '');
|
|
|
|
if (body !== changed) {
|
|
|
|
session.changes.add({body: changed})
|
|
|
|
}
|
|
|
|
}
|
2016-03-01 10:47:22 +08:00
|
|
|
}
|