Vulcan/packages/nova-comments/lib/callbacks/callbacks_other.js

27 lines
956 B
JavaScript

import Telescope from 'meteor/nova:lib';
import Posts from "meteor/nova:posts";
import Comments from '../collection.js';
import Users from 'meteor/nova:users';
import { Callbacks } from 'meteor/nova:core';
function UsersRemoveDeleteComments (user, options) {
if (options.deleteComments) {
var deletedComments = Comments.remove({userId: userId});
} else {
// not sure if anything should be done in that scenario yet
// Comments.update({userId: userId}, {$set: {author: "\[deleted\]"}}, {multi: true});
}
}
Callbacks.add("users.remove.async", UsersRemoveDeleteComments);
// Add to posts.single publication
function PostsSingleAddCommentsUsers (users, post) {
// get IDs from all commenters on the post
const comments = Comments.find({postId: post._id}).fetch();
if (comments.length) {
users = users.concat(_.pluck(comments, "userId"));
}
return users;
}
Callbacks.add("posts.single.getUsers", PostsSingleAddCommentsUsers);