mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-24 17:26:06 +08:00
34 lines
865 B
Plaintext
34 lines
865 B
Plaintext
|
import {DraftStore, AccountStore, Actions} from 'nylas-exports';
|
||
|
import SignatureUtils from './signature-utils';
|
||
|
|
||
|
|
||
|
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()
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
export default SignatureStore;
|