Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var users = filegroup.getUsers(function (users) {
var foundUser = false;
for (var i = 0; i < users.length; i++){
if(users[i] != callerID){
// this looks like a valid user to get the file from. :)
console.log("Trying to get file from: " + users[i]);
nowjs.getClient(users[i], function(){
if(this.now === undefined){
console.log("Undefined clientId for requestFullFileFromUserID (using local) >> " + users[i]);
localFileFetch(userObj, fname, fileRequesterCallback);
}else{
this.now.c_userRequestedFullFile(fname, callerID, fileRequesterCallback);
}
});
foundUser = true;
break;
}
}
if(!foundUser){
console.log("Flagged as changed, but no user with file: "+userObj.teamID+" >> "+fname+" >> FETCHING last saved.");
localFileFetch(userObj, fname, fileRequesterCallback);
}
});
this.addUser = function(user) {
channelUsers.addUser(user);
if(!adminUser) {
adminUser = user;
user.setAdmin(true);
}
// Welcome the new member with the last few messages
nowjs.getClient(user.clientId, function() {
this.now.handleMessages(messages, true);
this.now.handleChannelMembers(channelUsers.clientId_user);
});
// and notify everyone in the channel of the new members list
that.getGroup().now.handleMemberJoin(user, channelUsers.clientId_user); //TODO
// Add this user to the underlying nodejs group...
that.getGroup().addUser(user.clientId);
};
this.removeUser = function(user) {
// be set without already having checked the validity of the room
var id = that.user.clientId;
var group = nowjs.getGroup(session.room);
group.addUser(id);
// If this is the presenter, set presenter on the group object
if (session.type == "presenter") {
group.presenter = id;
}
logger.debugPair(id + " entered", that.now.room);
logger.debugPair("[nowjs.on] connect now object", util.inspect(that.now));
// Connect Initialization Function to run.
nowjs.getClient(that.user.clientId, function(){
if(that.now.hasOwnProperty('initialize') ) that.now.initialize();
})
});
});
filegroup.hasClient(id, function (bool) {
if (bool) {
//console.log("requesting full file. valid filegroup. :)");
nowjs.getClient(id, function(){
if(this.now === undefined){
console.log("Undefined clientId for requestFullFileFromUserID >> " + id);
}else{
this.now.c_userRequestedFullFile(fname, callerID, fileRequesterCallback);
}
});
}
});
};
var callUserFunction = function(email, func, args) {
var func = func || '';
var user = getUser(email || '');
if(!user) {
return {'error' : 'User not online'};
}
if(user && everyone.now[func]) {
for(var index in user.clients) {
var clientId = user.clients[index];
//console.log('execute ' + func + ' with args "' + args[0] + '" for user ' + email + ' with id ' + clientId);
//Call the function for a specific user
now.getClient(clientId, function() {
this.now[func].apply(this, args);
});
};
return {'success' : true};
} else {
return {'error' : 'User function is unknown.'};
}
};