Correctly remove name from users online on leave

This commit is contained in:
Kasper Rynning-Tønnesen
2018-08-30 14:54:46 +02:00
parent 2fe0410645
commit 327e69076c
2 changed files with 12 additions and 5 deletions

View File

@@ -45,8 +45,12 @@ function remove_name_from_db(guid, name) {
db.collection("connected_users").find({"_id": "total_users"}, function(err, all_users) {
var hasOne = all_users[0].total_users.some(function(v){ return v.indexOf(guid)>=0 });
if(!hasOne) {
db.collection("user_names").update({"_id": "all_names"}, {$pull: {names: name}}, function(err, updated) {
db.collection("user_names").remove({"guid": guid}, function(err, removed) { });
db.collection("user_names").find({"guid": guid}, function(err, user){
if(user.length == 1){
db.collection("user_names").update({"_id": "all_names"}, {$pull: {names: user[0].name}}, function(err, updated) {
db.collection("user_names").remove({"guid": guid}, function(err, removed) { });
});
}
});
}
});