From 424e3aea7cfd849e8b984c47b4021f54c5a56232 Mon Sep 17 00:00:00 2001 From: Rish Date: Mon, 4 Nov 2019 16:07:33 +0700 Subject: [PATCH] Added restriction to not send mail for published posts no issue --- core/server/services/mega.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/server/services/mega.js b/core/server/services/mega.js index 0f4ad3bdcf..57ac121ed3 100644 --- a/core/server/services/mega.js +++ b/core/server/services/mega.js @@ -1,7 +1,6 @@ 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) => { @@ -27,7 +26,13 @@ function listener(model, options) { return; } - sendEmail(model.toJSON()).then(() => { + sendEmail(model.toJSON()).then(async () => { + const deliveredEvents = await models.Action.findAll({ + filter: `event:delivered+resource_id:${model.id}` + }); + if (deliveredEvents && deliveredEvents.toJSON().length > 0) { + return; + } let actor = {id: null, type: null}; if (options.context && options.context.user) { actor = { @@ -42,7 +47,7 @@ function listener(model, options) { actor_id: actor.id, actor_type: actor.type }; - models.Action.add(action, {context: {internal: true}}); + return models.Action.add(action, {context: {internal: true}}); }); }