Mailspring/internal_packages/composer-signature/lib/signature-store.es6
Ben Gotow 94badcda15 es6(*): convert 20+ source files used in example packages to ES2016
There could be a few lurking bugs. Please test!
2016-02-29 18:47:22 -08:00

29 lines
849 B
JavaScript

import {DraftStore, AccountStore, Actions} from 'nylas-exports';
import SignatureUtils from './signature-utils';
export default class SignatureStore {
constructor() {
this.unsubscribe = ()=> {};
}
activate() {
this.unsubscribe = Actions.draftParticipantsChanged.listen(this.onParticipantsChanged);
}
onParticipantsChanged(draftClientId, changes) {
if (!changes.from) { return; }
DraftStore.sessionForClientId(draftClientId).then((session)=> {
const draft = session.draft();
const {accountId} = AccountStore.accountForEmail(changes.from[0].email);
const signature = NylasEnv.config.get(`nylas.account-${accountId}.signature`) || "";
const body = SignatureUtils.applySignature(draft.body, signature);
session.changes.add({body});
});
}
deactivate() {
this.unsubscribe();
}
}