Merge branch 'master' into docs

This commit is contained in:
Wyatt Johnson
2018-03-26 16:29:27 -06:00
committed by GitHub
3 changed files with 95 additions and 17 deletions
@@ -2,6 +2,12 @@ const { get } = require('lodash');
const path = require('path');
const handle = async (ctx, comment) => {
// Check to see if this reply is visible.
if (!comment.visible) {
ctx.log.info('comment was not visible, not sending notification');
return;
}
// Check to see if this is a reply to an existing comment.
const parentID = get(comment, 'parent_id', null);
if (parentID === null) {
@@ -90,12 +96,31 @@ const hydrate = async (ctx, category, context) => {
return [headline, replier, permalink];
};
const handler = {
handle,
category: 'reply',
event: 'commentAdded',
hydrate,
digestOrder: 30,
// commentAcceptedHandleAdapter will check to see if we need to send a
// notification for this comment if the comment has been recently approved but
// has not been approved before.
const commentAcceptedHandleAdapter = (ctx, comment) => {
// Don't send a notification for a non-visible comment.
if (!comment.visible) {
ctx.log.info('comment was not visible, not sending notification');
return;
}
// Don't send a notification if the comment was previously visible.
if (
// TODO: (wyattjoh) this check is quite brittle, replace with a more concrete check.
comment.status_history
.slice(0, comment.status_history.length - 1)
.some(({ type }) => ['ACCEPTED', 'NONE'].includes(type))
) {
ctx.log.info(
'comment was previously already visible, not sending another notification'
);
return;
}
// Delegate to the handle function.
return handle(ctx, comment);
};
module.exports = {
@@ -115,5 +140,20 @@ module.exports = {
},
},
translations: path.join(__dirname, 'translations.yml'),
notifications: [handler],
notifications: [
{
handle,
category: 'reply',
event: 'commentAdded',
hydrate,
digestOrder: 30,
},
{
handle: commentAcceptedHandleAdapter,
category: 'reply',
event: 'commentAccepted',
hydrate,
digestOrder: 30,
},
],
};
@@ -2,6 +2,11 @@ const { get } = require('lodash');
const path = require('path');
const handle = async (ctx, comment) => {
if (!comment.visible) {
ctx.log.info('comment was not visible, not sending notification');
return;
}
// Check to see if this is a reply to an existing comment.
const parentID = get(comment, 'parent_id', null);
if (parentID === null) {
@@ -111,13 +116,31 @@ const hydrate = async (ctx, category, context) => {
return [headline, replier, organizationName, permalink];
};
const handler = {
handle,
category: 'staff',
event: 'commentAdded',
hydrate,
supersedesCategories: ['reply'],
digestOrder: 20,
// commentAcceptedHandleAdapter will check to see if we need to send a
// notification for this comment if the comment has been recently approved but
// has not been approved before.
const commentAcceptedHandleAdapter = (ctx, comment) => {
// Don't send a notification for a non-visible comment.
if (!comment.visible) {
ctx.log.info('comment was not visible, not sending notification');
return;
}
// Don't send a notification if the comment was previously visible.
if (
// TODO: (wyattjoh) this check is quite brittle, replace with a more concrete check.
comment.status_history
.slice(0, comment.status_history.length - 1)
.some(({ type }) => ['ACCEPTED', 'NONE'].includes(type))
) {
ctx.log.info(
'comment was previously already visible, not sending another notification'
);
return;
}
// Delegate to the handle function.
return handle(ctx, comment);
};
module.exports = {
@@ -137,5 +160,22 @@ module.exports = {
},
},
translations: path.join(__dirname, 'translations.yml'),
notifications: [handler],
notifications: [
{
handle,
category: 'staff',
event: 'commentAdded',
hydrate,
supersedesCategories: ['reply'],
digestOrder: 20,
},
{
handle: commentAcceptedHandleAdapter,
category: 'staff',
event: 'commentAccepted',
hydrate,
supersedesCategories: ['reply'],
digestOrder: 20,
},
],
};
@@ -63,8 +63,6 @@ const sendNotificationsBatch = async (ctx, notifications) => {
return;
}
console.log(notifications);
return Promise.all(
map(
notifications,