mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-12-08 20:48:48 +00:00
Fix/total listeners disabled chat (#458)
* Testing some leavers * Logging before and after namechange * Testing callback even on chat disabled * Fixed issue with channels with disabled chat not adding to total listeners * Fixed potential issue with joining a channel with disabled chat broadcasts it
This commit is contained in:
committed by
GitHub
parent
b2e9050960
commit
03ca6a9f77
@@ -235,8 +235,9 @@ function checkIfChatEnabled(channel, socket, callback) {
|
|||||||
db.collection(channel + "_settings").find(function(err, docs){
|
db.collection(channel + "_settings").find(function(err, docs){
|
||||||
if(docs.length > 0 && (docs[0].hasOwnProperty("toggleChat") && !docs[0].toggleChat)) {
|
if(docs.length > 0 && (docs[0].hasOwnProperty("toggleChat") && !docs[0].toggleChat)) {
|
||||||
socket.emit('chat', {from: "System", msg: ": Chat for this channel has been disabled.", icon: "https://zoff.me/assets/images/favicon-32x32.png"});
|
socket.emit('chat', {from: "System", msg: ": Chat for this channel has been disabled.", icon: "https://zoff.me/assets/images/favicon-32x32.png"});
|
||||||
|
callback(false);
|
||||||
} else {
|
} else {
|
||||||
callback();
|
callback(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -257,7 +258,11 @@ function checkIfUserIsBanned(channel, socket, guid, callback, callback_error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function namechange(data, guid, socket, tried, callback) {
|
function namechange(data, guid, socket, tried, callback) {
|
||||||
checkIfChatEnabled(data.channel, socket, function() {
|
checkIfChatEnabled(data.channel, socket, function(enabled) {
|
||||||
|
if(!enabled) {
|
||||||
|
callback(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
checkIfUserIsBanned(data.channel, socket, guid, function() {
|
checkIfUserIsBanned(data.channel, socket, guid, function() {
|
||||||
var pw = "";
|
var pw = "";
|
||||||
var new_password;
|
var new_password;
|
||||||
@@ -271,7 +276,7 @@ function namechange(data, guid, socket, tried, callback) {
|
|||||||
data.password = pass;
|
data.password = pass;
|
||||||
new_password = false;
|
new_password = false;
|
||||||
if(name == "" || pass == "") {
|
if(name == "" || pass == "") {
|
||||||
if(typeof(callback) == "function") callback();
|
if(typeof(callback) == "function") callback(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fetched = true;
|
fetched = true;
|
||||||
@@ -294,7 +299,7 @@ function namechange(data, guid, socket, tried, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(name == "") {
|
if(name == "") {
|
||||||
if(typeof(callback) == "function") callback();
|
if(typeof(callback) == "function") callback(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,7 +309,7 @@ function namechange(data, guid, socket, tried, callback) {
|
|||||||
var icon = false;
|
var icon = false;
|
||||||
if(docs.length == 0) {
|
if(docs.length == 0) {
|
||||||
if(new_password) {
|
if(new_password) {
|
||||||
if(typeof(callback) == "function") callback();
|
if(typeof(callback) == "function") callback(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
accepted_password = true;
|
accepted_password = true;
|
||||||
@@ -353,7 +358,7 @@ function namechange(data, guid, socket, tried, callback) {
|
|||||||
io.sockets.emit('chat.all', {from: old_name , msg: " changed name to " + name, channel: data.channel});
|
io.sockets.emit('chat.all', {from: old_name , msg: " changed name to " + name, channel: data.channel});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(callback != undefined && typeof(callback) == "function") callback();
|
if(callback != undefined && typeof(callback) == "function") callback(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -378,7 +383,8 @@ function namechange(data, guid, socket, tried, callback) {
|
|||||||
|
|
||||||
function removename(guid, coll, socket) {
|
function removename(guid, coll, socket) {
|
||||||
//coll = coll.replace(/ /g,'');
|
//coll = coll.replace(/ /g,'');
|
||||||
checkIfChatEnabled(coll, socket, function() {
|
checkIfChatEnabled(coll, socket, function(enabled) {
|
||||||
|
if(enabled) return;
|
||||||
db.collection("user_names").find({"guid": guid}, function(err, docs) {
|
db.collection("user_names").find({"guid": guid}, function(err, docs) {
|
||||||
if(docs.length == 1) {
|
if(docs.length == 1) {
|
||||||
var old_name = docs[0].name;
|
var old_name = docs[0].name;
|
||||||
|
|||||||
@@ -138,13 +138,15 @@ function check_inlist(coll, guid, socket, offline, callback, double_check)
|
|||||||
} else {
|
} else {
|
||||||
io.to(coll).emit("viewers", new_doc[0].users.length);
|
io.to(coll).emit("viewers", new_doc[0].users.length);
|
||||||
}
|
}
|
||||||
Chat.namechange({initial: true, first:true, channel: coll}, guid, socket, false, function() {
|
Chat.namechange({initial: true, first:true, channel: coll}, guid, socket, false, function(enabled) {
|
||||||
db.collection("user_names").find({"guid": guid}, function(err, docs) {
|
db.collection("user_names").find({"guid": guid}, function(err, docs) {
|
||||||
if(docs.length == 1) {
|
if(docs.length == 1) {
|
||||||
var icon = "";
|
var icon = "";
|
||||||
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){});
|
||||||
|
if(enabled) {
|
||||||
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) {
|
} else if(docs.length == 0) {
|
||||||
//console.log("User doesn't have a name for some reason.");
|
//console.log("User doesn't have a name for some reason.");
|
||||||
//console.log("guid", guid);
|
//console.log("guid", guid);
|
||||||
|
|||||||
Reference in New Issue
Block a user