Vulcan/collections/notifications.js

66 lines
1.6 KiB
JavaScript
Raw Normal View History

2013-04-13 15:05:18 +09:00
Notifications = new Meteor.Collection('notifications');
2014-05-10 16:57:17 +09:00
// Notifications = new Meteor.Collection("notifications", {
// schema: new SimpleSchema({
// properties: {
// type: Object
// },
// event: {
// type: String
// },
// read: {
// type: Boolean
// },
// createdAt: {
// type: Date
// },
// userId: {
// type: "???"
// }
// })
// });
2013-07-04 12:51:26 +09:00
Notifications.allow({
insert: function(userId, doc){
// new notifications can only be created via a Meteor method
return false;
}
, update: canEditById
, remove: canEditById
});
2014-08-03 11:50:10 +09:00
buildSiteNotification = function(notification){
var event = notification.event,
p = notification.properties,
2014-08-03 11:50:10 +09:00
userToNotify = Meteor.users.findOne(notification.userId),
html
switch(event){
case 'newReply':
2014-08-03 11:50:10 +09:00
html = '<p><a href="'+getProfileUrlById(p.commentAuthorId)+'">'+p.commentAuthorName+'</a> has replied to your comment on "<a href="'+getPostCommentUrl(p.postId, p.commentId)+'" class="action-link">'+p.postTitle+'</a>"</p>';
break;
case 'newComment':
2014-08-03 11:50:10 +09:00
html = '<p><a href="'+getProfileUrlById(p.commentAuthorId)+'">'+p.commentAuthorName+'</a> left a new comment on your post "<a href="'+getPostCommentUrl(p.postId, p.commentId)+'" class="action-link">'+p.postTitle+'</a>"</p>';
break;
default:
2014-08-03 11:50:10 +09:00
break;
}
2014-08-03 11:50:10 +09:00
return html;
};
2013-03-14 09:45:57 +11:00
Meteor.methods({
markAllNotificationsAsRead: function() {
Notifications.update(
{userId: Meteor.userId()},
{
$set:{
read: true
}
},
{multi: true}
);
}
});