Skip to content

Commit

Permalink
Added action for post email delievery
Browse files Browse the repository at this point in the history
no issue
  • Loading branch information
rishabhgrg committed Nov 4, 2019
1 parent fb88c54 commit 5b438d3
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions core/server/services/mega.js
@@ -1,6 +1,8 @@
const common = require('../lib/common');
const membersService = require('./members');
const bulkEmailService = require('./bulk-email');
const ghostBookshelf = require('../models/base');
const models = require('../models');

const sendEmail = async (post) => {
const emailTmpl = {
Expand All @@ -15,7 +17,7 @@ const sendEmail = async (post) => {
};

function listener(model, options) {
// CASE: do not ping slack if we import a database
// CASE: do not send email if we import a database
// TODO: refactor post.published events to never fire on importing
if (options && options.importing) {
return;
Expand All @@ -25,7 +27,23 @@ function listener(model, options) {
return;
}

sendEmail(model.toJSON());
sendEmail(model.toJSON()).then(() => {
let actor = {id: null, type: null};
if (options.context && options.context.user) {
actor = {
id: options.context.user,
type: 'user'
};
}
const action = {
event: 'delivered',
resource_id: model.id,
resource_type: 'post',
actor_id: actor.id,
actor_type: actor.type
};
models.Action.add(action, {context: {internal: true}});
});
}

function listen() {
Expand Down

0 comments on commit 5b438d3

Please sign in to comment.