2012-10-04 15:26:59 +09:00
|
|
|
Meteor.methods({
|
|
|
|
addNotification: 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
|
|
|
|
Meteor.users.update(
|
|
|
|
{_id: userToNotify._id},
|
|
|
|
{$push:
|
|
|
|
{
|
2012-10-04 17:25:10 +09:00
|
|
|
'notifications': {
|
2012-10-04 15:26:59 +09:00
|
|
|
timestamp: new Date().getTime(),
|
|
|
|
event: event,
|
|
|
|
properties: properties,
|
|
|
|
read: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
function(error, result){
|
|
|
|
if(error){
|
|
|
|
console.log(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
clearNotifications: function(user){
|
|
|
|
Meteor.users.update(
|
|
|
|
{_id: user._id},
|
|
|
|
{$pull:
|
|
|
|
{
|
2012-10-04 17:25:10 +09:00
|
|
|
'notifications': {}
|
2012-10-04 15:26:59 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
function(error, result){
|
|
|
|
if(error){
|
|
|
|
console.log(error);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|