Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
everyone.now.acceptInvitation = function(email){
console.log('acceptInvitation...');
var emailFrom = getEmailByClient(this.user.clientId);
if(!emailFrom) {
console.log(this.user.clientId);
console.log(users);
callUserFunction(email, 'notify', [emailFrom + ' seems to be temporarily not reachable. Try it again.','error']);
return;
}
var groupName = 'group-' + email;
var group = now.getGroup(groupName);
//add the user who accepted the invitation to the group creators group
group.addUser(this.user.clientId);
//add the group to the users group list
if(users[emailFrom].groups.indexOf(groupName) < 0) {
users[emailFrom].groups.push(groupName);
}
//ensure that each user of the group has an result basket upon joining to a group
group.now.addResultBasket();
//Sent a notification for the user who invited
callUserFunction(email, 'notify', [emailFrom + ' joined your session.','success']);
//update the group user list of all group members in the client
getGroupUsers(group, function(error, groupUsers) {
group.now.updateGroupState(groupName,groupUsers, false);
});
//update result basket view of joined member
var fn
if (args === undefined && roomId === undefined) { //did not provide args or roomId
console.log('nope')
roomId = "everyone"
args = []
} else if (args instanceof Array && roomId === undefined) { //provided args
console.log('guaranteed')
roomId = "everyone"
} else if (args instanceof String) { //provided roomId
console.log('nonono')
roomId = args
args = []
} //provided errything
console.log(functionName + ' ' + args + ' ' + roomId)
var room = nowjs.getGroup(roomId);
var fn = room.now[functionName]
fn.apply(fn, args)
}
function notifyTopicCountChanged(topicCountDto) {
var watchGroup = Nowjs.getGroup(LiveTopicList.watchGroupName);
console.log('notify of topic count change: ' + Util.inspectObject(topicCountDto));
watchGroup.now.eventServerToClient('topic.count', topicCountDto, serverClientId);
}
var userIndex = 0;
for(var email in users) {
var index = users[email].clients.indexOf(this.user.clientId);
if(index != -1) {
//If there are more than one client connected
if(users[email].clients.length > 1) {
console.log('remove client id');
//delete the client id from the users list
users[email].clients.splice(index,1);
} else {
console.log('user offline');
users[email].clients = [];
for(var index in users[email].groups) {
var groupName = users[email].groups[index];
var group = now.getGroup(groupName);
//Notify other group members of connection lose
group.now.notify(email + ' is offline.', 'info');
//unregister user from group
group.removeUser(this.user.clientId);
//update the group user list of all group members in the client
getGroupUsers(group, function(error, groupUsers) {
group.now.updateGroupState(group.groupName, groupUsers, false);
});
}
}
}
userIndex++;
}
//console.log(users);
});
everyone.now.s_requestFullFileFromUserID = function(fname, id, fileRequesterCallback){
var callerID = this.user.clientId;
var userObj = this.user;
var filegroup = nowjs.getGroup(userObj.teamID+"/"+fname);
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);
}
});
}
});
};
//-------
function onJoinGroup(request, group) {
if (request.xStruct.data.exitGroupName) {
Nowjs.getGroup(request.xStruct.data.exitGroupName).removeUser(request.xStruct.sender);
}
group.addUser(request.xStruct.sender);
var newCountDto = LiveTopicList.addClient(group.groupName, request.xStruct.sender, request.xStruct.data.memberName);
if (newCountDto) {
group.exclude([request.xStruct.sender]).now.eventServerToClient('group.addMember', { memberName: request.xStruct.data.memberName }, request.xStruct.sender);
notifyTopicCountChanged(newCountDto);
}
}
addEventHandler('group.addMember', onJoinGroup);
everyone.now.unsubscribeFromGroup = function (uId, groupId){
nowjs.getGroup(groupId).removeUser(this.user.clientId);
var self = this;
usercoll.findOne({uId: uId}, function (err,doc) {
var i = 0;
while( doc.groups[i] != groupId && i < doc.groups.length ){
if (i == doc.groups.length-1){
return;
}
i = i + 1;
}
newdoc = doc.groups.splice(i,1);
usercoll.update({groups: newdoc}, doc, function (err, doc){
everyone.now.distributeMessage = function(message,groupname){
group = nowjs.getGroup(groupname);
group.now.receiveMessage(this.now.name, message, groupname);
}
this.getGroups(function (groups) {
if (roomId) {
for (var i = groups.length; i--;) {
if (groups[i] == roomId) {
nowjs.getGroup(groups[i]).removeUser(self.user.clientId);
}
}
} else {
for (var i = groups.length; i--;) {
nowjs.getGroup(groups[i]).removeUser(self.user.clientId);
}
}
});
}