Updated so username won't overflow. Removing username on general leave

This commit is contained in:
Kasper Rynning-Tønnesen
2018-08-28 12:50:45 +02:00
parent f9a2169f51
commit 9852da491b

View File

@@ -752,7 +752,12 @@ function getNextSong(coll, socket, callback) {
} }
function left_channel(coll, guid, short_id, in_list, socket, change) { function left_channel(coll, guid, short_id, in_list, socket, change) {
if(!coll) return; if(!coll) {
if(!change) {
Functions.remove_name_from_db(guid, name);
}
return;
}
//coll = coll.replace(/ /g,''); //coll = coll.replace(/ /g,'');
db.collection("connected_users").update({"_id": coll}, {$pull: {users: guid}}, function(err, updated) { db.collection("connected_users").update({"_id": coll}, {$pull: {users: guid}}, function(err, updated) {
if(updated.nModified > 0) { if(updated.nModified > 0) {
@@ -767,10 +772,6 @@ function left_channel(coll, guid, short_id, in_list, socket, change) {
io.to(coll).emit("viewers", new_doc[0].users.length); io.to(coll).emit("viewers", new_doc[0].users.length);
socket.leave(coll); socket.leave(coll);
}); });
if(!change) {
Functions.remove_name_from_db(guid, name);
}
}); });
} else { } else {
@@ -781,6 +782,9 @@ function left_channel(coll, guid, short_id, in_list, socket, change) {
}); });
} }
if(!change) {
Functions.remove_name_from_db(guid, name);
}
}); });
Functions.remove_unique_id(short_id); Functions.remove_unique_id(short_id);
} }