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