Hi - i just noticed something when going one of my projects… T and (count) when logged are called twice? I figured it might have something to do with the multiple collection calls but not entirely sure.
A penny for your thoughts?
updateRoom: function(name, user){
if (! Meteor.userId()) {
throw new Meteor.Error("not-authorized");
}
check(name, String);
check(user, String);
var currentUser = Meteor.users.findOne({_id: Meteor.userId()});
console.log('t');
if(currentUser.admin){
if(name != null && name != undefined){
if(user != null && user != undefined){
var currentRoom = Rooms.findOne({roomname: name});
var count = Rooms.find({roomname: name, participants: user}).count();
console.log(count);
if(count === 0){
Rooms.update({ _id: currentRoom._id},{$push: { participants: user}});
Push.send({
from: '',
title: 'xxx',
text: 'xx: ' + name,
badge: 1,
sound: "default",
query: {userId: user}
});
}else if(check === 1){
//remove user
}
}
}
}else {
throw new Meteor.Error("not-authorized");
}
},
Template.userList.events({
"click .item": function(event, template){
Meteor.call('updateRoom', Session.get('roomname'), this._id);
template.$(event.currentTarget).toggleClass('active-target');
}
});