Skip to content
This repository has been archived by the owner on Oct 1, 2019. It is now read-only.

Commit

Permalink
Fix new comment notifications not being sent (#626)
Browse files Browse the repository at this point in the history
And again, the bookshelf visibility plugin stripped out user emails.
  • Loading branch information
voidxnull committed Sep 4, 2016
1 parent 7bac4a1 commit 47ffb34
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions tasks.js
Expand Up @@ -78,16 +78,18 @@ queue.process('on-comment', async function(job, done) {
.fetch({ require: true, withRelated: ['user', 'post', 'post.user'] });
const commentAuthor = comment.related('user');
const post = comment.related('post');
const subscribers = await post.related('subscribers').fetch();
const subscribers = (await post.related('subscribers').fetch())
.map(subscriber => subscriber.attributes);


if (subscribers.length > 0) {
queue.create('new-comment-email', {
comment: comment.attributes,
commentAuthor: commentAuthor.attributes,
post: post.attributes,
subscribers: subscribers.toJSON()
}).save();
for (const subscriber of subscribers) {
if (!subscriber.more.mute_all_posts && commentAuthor.id !== subscriber.id) {
queue.create('new-comment-email', {
comment: comment.attributes,
commentAuthor: commentAuthor.attributes,
post: post.attributes,
subscriber
}).priority('medium').save();
}
}

done();
Expand All @@ -102,15 +104,11 @@ queue.process('new-comment-email', async function(job, done) {
comment,
commentAuthor,
post,
subscribers
subscriber
} = job.data;

for (const subscriber of subscribers) {
if (!commentAuthor.more.mute_all_posts && commentAuthor.id !== subscriber.id) {
const html = await renderNewCommentTemplate(comment, commentAuthor, post, subscriber);
await sendEmail('New Comment on LibertySoil.org', html, subscriber.email);
}
}
const html = await renderNewCommentTemplate(comment, commentAuthor, post, subscriber);
await sendEmail('New Comment on LibertySoil.org', html, subscriber.email);

done();
} catch (e) {
Expand Down

0 comments on commit 47ffb34

Please sign in to comment.