notifications.js 612 B

12345678910111213141516171819202122
  1. Notifications = new Mongo.Collection('notifications');
  2. Notifications.allow({
  3. update: function (userId, doc, fieldNames) {
  4. // Only allow post author to update, and only the "read" field.
  5. return ownsDocument(userId, doc) &&
  6. fieldNames.length === 1 && fieldNames[0] === 'read';
  7. }
  8. });
  9. createCommentNotification = function (comment) {
  10. var post = Posts.findOne(comment.postId);
  11. if (comment.userId !== post.userId) {
  12. Notifications.insert({
  13. userId: post.userId,
  14. postId: post._id,
  15. commentId: comment._id,
  16. commenterName: comment.author,
  17. read: false
  18. });
  19. }
  20. };