mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 18:11:40 -05:00
33 lines
1.2 KiB
JavaScript
33 lines
1.2 KiB
JavaScript
import Telescope from 'meteor/nova:lib';
|
|
import Posts from "meteor/nova:posts";
|
|
import Users from 'meteor/nova:users';
|
|
|
|
// Notify users subscribed to the thread
|
|
|
|
function SubscribedCommentsNotifications (comment) {
|
|
if (typeof Telescope.notifications !== "undefined") {
|
|
// note: dummy content has disableNotifications set to true
|
|
if(Meteor.isServer && !comment.disableNotifications){
|
|
|
|
const post = Posts.findOne(comment.postId);
|
|
|
|
let userIdsNotified = [],
|
|
notificationData = {
|
|
comment: _.pick(comment, '_id', 'userId', 'author', 'htmlBody', 'postId'),
|
|
post: _.pick(post, '_id', 'userId', 'title', 'url')
|
|
};
|
|
|
|
if (!!post.subscribers) {
|
|
// remove userIds of users that have already been notified
|
|
// and of comment author (they could be replying in a thread they're subscribed to)
|
|
let subscriberIdsToNotify = _.difference(post.subscribers, userIdsNotified, [comment.userId]);
|
|
Telescope.notifications.create(subscriberIdsToNotify, 'newCommentSubscribed', notificationData);
|
|
|
|
userIdsNotified = userIdsNotified.concat(subscriberIdsToNotify);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
Telescope.callbacks.add("comments.new.async", SubscribedCommentsNotifications);
|