0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00
ghost/core/server/services/mega.js
Naz Gargol 74f2145e81
Added MEGA service (#11333)
no issue

- This services listens  to 'post.publish' event, assemples email data and calls bulk mailer
2019-11-04 14:38:40 +07:00

38 lines
908 B
JavaScript

const common = require('../lib/common');
const membersService = require('./members');
const bulkEmailService = require('./bulk-email');
const sendEmail = async (post) => {
const emailTmpl = {
subject: post.email_subject || post.title,
html: post.html
};
const {members} = await membersService.api.members.list();
const emails = members.map(m => m.email);
return bulkEmailService.send(emailTmpl, emails);
};
function listener(model, options) {
// CASE: do not ping slack if we import a database
// TODO: refactor post.published events to never fire on importing
if (options && options.importing) {
return;
}
if (!model.get('send_email_when_published')) {
return;
}
sendEmail(model.toJSON());
}
function listen() {
common.events.on('post.published', listener);
}
// Public API
module.exports = {
listen: listen
};