Vulcan/common/notifications.js

50 lines
1.1 KiB
JavaScript
Raw Normal View History

2012-10-04 15:26:59 +09:00
Meteor.methods({
notify: function(event, properties, userToNotify, userDoingAction){
2012-10-04 17:25:10 +09:00
// console.log('adding new notification for:'+getDisplayName(userToNotify)+', for event:'+event);
// console.log(userToNotify);
// console.log(userDoingAction);
// console.log(properties);
2012-10-04 15:26:59 +09:00
if(userToNotify._id!=userDoingAction._id){
// make sure we don't notify people of their own actions
var notification= {
timestamp: new Date().getTime(),
userId: userToNotify._id,
event: event,
properties: properties,
read: false
}
var newNotificationId=Notifications.insert(notification);
2012-10-04 15:26:59 +09:00
}
},
markNotificationAsRead: function(notificationId){
Notifications.update(
{_id: notificationId},
{
$set:{
read: true
}
},
function(error, result){
if(error){
console.log(error);
}
}
);
},
markAllNotificationsAsRead: function(user){
Notifications.update(
{userId: user._id},
{
$set:{
read: true
2012-10-04 15:26:59 +09:00
}
},
{multi: true},
2012-10-04 15:26:59 +09:00
function(error, result){
if(error){
console.log(error);
}
}
);
}
});