From e17d3a5bf3240a35504c6573cc0e6e15d5d9398c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Rynning-T=C3=B8nnesen?= Date: Fri, 21 Sep 2018 15:52:52 +0200 Subject: [PATCH] Fixed issue with names on leave remaining for some reason and trying fix for users without name --- server/handlers/functions.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/server/handlers/functions.js b/server/handlers/functions.js index 8d9f7586..eb553de3 100644 --- a/server/handlers/functions.js +++ b/server/handlers/functions.js @@ -142,6 +142,12 @@ function check_inlist(coll, guid, socket, offline, callback) if(docs[0].icon != undefined) icon = docs[0].icon; db.collection("user_names").update({"guid": guid}, {$addToSet:{channels: coll}}, function(err, doc){}); socket.broadcast.to(coll).emit('chat', {from: docs[0].name, icon: icon, msg: " joined"}); + } else if(docs.length == 0) { + console.log("User doesn't have a name for some reason."); + console.log("guid", guid); + console.log("channel", coll); + console.log("Trying to get a chat-name"); + Chat.get_name(guid, {announce: false, socket: socket, channel: coll}); } }); db.collection("connected_users").update({"_id": "total_users"}, {$addToSet: {total_users: guid + coll}}, function(err, docs){ @@ -371,10 +377,17 @@ function removeSessionAdminPass(id, channel, callback) { }); } +function remove_from_chat_channel(coll, guid) { + db.collection("user_names").update({"guid": guid}, {$pull: {channels: coll}}, function(err, docs) { + }); +} + function left_channel(coll, guid, short_id, in_list, socket, change) { if(!coll) { if(!change) { remove_name_from_db(guid, coll); + } else { + remove_from_chat_channel(coll, guid); } return; } @@ -395,6 +408,8 @@ function left_channel(coll, guid, short_id, in_list, socket, change) { socket.leave(coll); if(!change) { remove_name_from_db(guid, coll); + } else { + remove_from_chat_channel(coll, guid); } }); }); @@ -405,6 +420,8 @@ function left_channel(coll, guid, short_id, in_list, socket, change) { db.collection("connected_users").update({"_id": "total_users"}, {$pull: {total_users: guid + coll}}, function(err, updated){}); if(!change) { remove_name_from_db(guid, coll); + } else { + remove_from_chat_channel(coll, guid); } //} });