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 ) {
2013-11-18 11:30:58 +09:00
var event = notification . event ,
p = notification . properties ,
2014-08-03 11:50:10 +09:00
userToNotify = Meteor . users . findOne ( notification . userId ) ,
html
2013-11-18 11:30:58 +09:00
2013-01-19 18:24:18 +09:00
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>' ;
2013-11-18 11:30:58 +09:00
break ;
2013-01-19 18:24:18 +09:00
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 ;
2013-02-22 15:41:15 +09:00
2013-01-19 18:24:18 +09:00
default :
2014-08-03 11:50:10 +09:00
break ;
2013-11-18 11:30:58 +09:00
}
2014-08-03 11:50:10 +09:00
return html ;
2014-05-06 20:15:48 -07:00
} ;
2013-03-14 09:45:57 +11:00
Meteor . methods ( {
markAllNotificationsAsRead : function ( ) {
Notifications . update (
{ userId : Meteor . userId ( ) } ,
{
$set : {
read : true
}
} ,
{ multi : true }
) ;
}
} ) ;