Fixed issue with names on leave remaining for some reason and trying fix for users without name

This commit is contained in:
Kasper Rynning-Tønnesen
2018-09-21 15:52:52 +02:00
parent c26c490e4e
commit fbecb2ccd2

View File

@@ -142,6 +142,12 @@ function check_inlist(coll, guid, socket, offline, callback)
if(docs[0].icon != undefined) icon = docs[0].icon; if(docs[0].icon != undefined) icon = docs[0].icon;
db.collection("user_names").update({"guid": guid}, {$addToSet:{channels: coll}}, function(err, doc){}); 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"}); 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){ 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) { function left_channel(coll, guid, short_id, in_list, socket, change) {
if(!coll) { if(!coll) {
if(!change) { if(!change) {
remove_name_from_db(guid, coll); remove_name_from_db(guid, coll);
} else {
remove_from_chat_channel(coll, guid);
} }
return; return;
} }
@@ -395,6 +408,8 @@ function left_channel(coll, guid, short_id, in_list, socket, change) {
socket.leave(coll); socket.leave(coll);
if(!change) { if(!change) {
remove_name_from_db(guid, coll); 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){}); db.collection("connected_users").update({"_id": "total_users"}, {$pull: {total_users: guid + coll}}, function(err, updated){});
if(!change) { if(!change) {
remove_name_from_db(guid, coll); remove_name_from_db(guid, coll);
} else {
remove_from_chat_channel(coll, guid);
} }
//} //}
}); });