Ignored User Reply Notifications

This commit is contained in:
Wyatt Johnson
2018-04-10 17:33:56 -06:00
parent 46078117c8
commit 2e74f79b79
2 changed files with 17 additions and 4 deletions
+2 -2
View File
@@ -29,9 +29,9 @@ const User = {
return Comments.getByQuery(query);
},
ignoredUsers({ ignoresUsers }, args, { user, loaders: { Users } }) {
ignoredUsers({ ignoresUsers }, args, { loaders: { Users } }) {
// Return nothing if there is nothing to query for.
if (!user.ignoresUsers || user.ignoresUsers.length <= 0) {
if (!ignoresUsers || ignoresUsers.length <= 0) {
return [];
}
@@ -1,4 +1,4 @@
const { get } = require('lodash');
const { get, map } = require('lodash');
const path = require('path');
const handle = async (ctx, comment) => {
@@ -23,6 +23,9 @@ const handle = async (ctx, comment) => {
id
user {
id
ignoredUsers {
id
}
notificationSettings {
onReply
}
@@ -53,13 +56,23 @@ const handle = async (ctx, comment) => {
return;
}
// Pull out the author of the new comment.
const authorID = get(comment, 'author_id');
// Check to see if this is yourself replying to yourself, if that's the case
// don't send a notification.
if (userID === get(comment, 'author_id')) {
if (userID === authorID) {
ctx.log.info('user id of parent comment is the same as the new comment');
return;
}
// Check to see if this user is ignoring the user who replied to their
// comment.
if (map(get(comment, 'user.ignoredUsers', []), 'id').indexOf(authorID)) {
ctx.log.info('parent user has ignored the author of the new comment');
return;
}
// The user does have notifications for replied comments enabled, queue the
// notification to be sent.
return { userID, date: comment.created_at, context: comment.id };