|
@@ -0,0 +1,32 @@
|
|
|
|
+/**
|
|
|
|
+ * @file
|
|
|
|
+ *
|
|
|
|
+ *
|
|
|
|
+ * User: marand
|
|
|
|
+ * Date: 07/09/15
|
|
|
|
+ * Time: 18:48
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+// Notifications are sent to a post author when someone comments on their post.
|
|
|
|
+Notifications = new Mongo.Collection('notifications');
|
|
|
|
+
|
|
|
|
+Notifications.allow({
|
|
|
|
+ 'update': function (userId, doc, fieldNames) {
|
|
|
|
+ // Only allow post author to update, and only the "read" field.
|
|
|
|
+ return ownsDocument(userId, doc) &&
|
|
|
|
+ fieldNames.length === 1 && fieldNames[0] === 'read';
|
|
|
|
+ }
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+createCommentNotification = function (comment) {
|
|
|
|
+ var post = Posts.findOne(comment.postId);
|
|
|
|
+ if (comment.userId !== post.userId) {
|
|
|
|
+ Notification.insert({
|
|
|
|
+ userId: post.userId,
|
|
|
|
+ postId: post._id,
|
|
|
|
+ commentId: comment._id,
|
|
|
|
+ commenterName: comment.author,
|
|
|
|
+ read: false
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+};
|