0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Added MEGA service (#11333)

no issue

- This services listens  to 'post.publish' event, assemples email data and calls bulk mailer
This commit is contained in:
Naz Gargol 2019-11-04 14:38:40 +07:00 committed by GitHub
parent 82e022b582
commit 74f2145e81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 1 deletions

View file

@ -28,6 +28,7 @@ function initialiseServices() {
apps = require('./services/apps'),
xmlrpc = require('./services/xmlrpc'),
slack = require('./services/slack'),
mega = require('./services/mega'),
webhooks = require('./services/webhooks'),
scheduling = require('./adapters/scheduling');
@ -38,6 +39,7 @@ function initialiseServices() {
permissions.init(),
xmlrpc.listen(),
slack.listen(),
mega.listen(),
webhooks.listen(),
apps.init(),
scheduling.init({
@ -50,7 +52,7 @@ function initialiseServices() {
contentPath: config.getContentPath('scheduling')
})
).then(function () {
debug('XMLRPC, Slack, Webhooks, Apps, Scheduling, Permissions done');
debug('XMLRPC, Slack, MEGA, Webhooks, Apps, Scheduling, Permissions done');
// Initialise analytics events
if (config.get('segment:key')) {

View file

@ -0,0 +1,38 @@
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
};