mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
Merge pull request #392 from zoff-music/feature/who-chat
Feature of /who and seeing the people in the channel
This commit is contained in:
@@ -89,7 +89,13 @@ function chat(msg, guid, offline, socket) {
|
||||
var data = msg.data;
|
||||
|
||||
Functions.check_inlist(coll, guid, socket, offline, function() {
|
||||
if(data !== "" && data !== undefined && data !== null &&
|
||||
if(data == "/who") {
|
||||
db.collection("user_names").distinct("name", {channels: coll}, function(err, docs) {
|
||||
var userAdd = "s";
|
||||
if(docs.length == 1) userAdd = "";
|
||||
socket.emit('chat', {from: "System", msg: ": User" + userAdd + " in channel are: " + docs.join(", "), icon: "https://zoff.me/assets/images/favicon-32x32.png"});
|
||||
});
|
||||
} else if(data !== "" && data !== undefined && data !== null &&
|
||||
data.length < 151 && data.replace(/\s/g, '').length){
|
||||
db.collection("user_names").find({"guid": guid}, function(err, docs) {
|
||||
if(docs.length == 1) {
|
||||
@@ -230,7 +236,11 @@ function namechange(data, guid, socket, tried, callback) {
|
||||
var old_name = names[0].name;
|
||||
db.collection("user_names").update({"_id": "all_names"}, {$pull: {names: old_name}}, function() {});
|
||||
}
|
||||
db.collection("user_names").update({"guid": guid}, {$set: {name: name, icon: icon}}, {upsert: true}, function(err, docs) {
|
||||
var updateElement = {$set: {name: name, icon: icon}};
|
||||
if(data.hasOwnProperty("channel") && data.channel != "") {
|
||||
updateElement["$addToSet"] = {channels: data.channel};
|
||||
}
|
||||
db.collection("user_names").update({"guid": guid}, updateElement, {upsert: true}, function(err, docs) {
|
||||
db.collection("user_names").update({"_id": "all_names"}, {$addToSet: {names: name}}, function(err, docs) {
|
||||
//socket.emit('name', {type: "name", accepted: true});
|
||||
if(old_name != name && !first && !no_name) {
|
||||
@@ -276,14 +286,18 @@ function removename(guid, coll, socket) {
|
||||
});
|
||||
}
|
||||
|
||||
function generate_name(guid, announce_payload, second, round) {
|
||||
function generate_name(guid, announce_payload, second, round, channel) {
|
||||
if(round == undefined) round = 0;
|
||||
var tmp_name = Functions.rndName(second ? second : guid, Math.floor(8 + round));
|
||||
db.collection("registered_users").find({"_id": tmp_name}, function(err, docs) {
|
||||
if(docs.length == 0) {
|
||||
db.collection("user_names").update({"_id": "all_names"}, {$addToSet: {names: tmp_name}}, {upsert: true}, function(err, updated) {
|
||||
if(updated.nModified == 1 || (updated.hasOwnProperty("upserted") && updated.hasOwnProperty("n") && updated.n == 1)) {
|
||||
db.collection("user_names").update({"guid": guid}, {$set: {name: tmp_name, icon: false}}, {upsert: true}, function(err, update){
|
||||
var updateElement = {$set: {name: tmp_name, icon: false}};
|
||||
if(channel != undefined && channel != "") {
|
||||
updateElement["$addToSet"] = {channels: channel};
|
||||
}
|
||||
db.collection("user_names").update({"guid": guid}, updateElement, {upsert: true}, function(err, update){
|
||||
name = tmp_name;
|
||||
if(announce_payload.announce) {
|
||||
io.to(announce_payload.channel).emit('chat', {from: announce_payload.old_name, msg: " changed name to " + name});
|
||||
@@ -295,11 +309,11 @@ function generate_name(guid, announce_payload, second, round) {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
generate_name(guid, announce_payload, tmp_name, round + 0.25);
|
||||
generate_name(guid, announce_payload, tmp_name, round + 0.25, channel);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
generate_name(guid, announce_payload, tmp_name, round + 0.25);
|
||||
generate_name(guid, announce_payload, tmp_name, round + 0.25, channel);
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -308,7 +322,7 @@ function get_name(guid, announce_payload, first) {
|
||||
if(!announce_payload.announce && announce_payload.hasOwnProperty("socket")) {
|
||||
Functions.getSessionChatPass(Functions.getSession(announce_payload.socket), function(name, pass) {
|
||||
if(name == "" || pass == "") {
|
||||
get_name_generate(guid, announce_payload, first);
|
||||
get_name_generate(guid, announce_payload, first, announce_payload.channel);
|
||||
return;
|
||||
}
|
||||
db.collection("registered_users").find({"_id": name.toLowerCase()}, function(err, docs) {
|
||||
@@ -328,14 +342,14 @@ function get_name(guid, announce_payload, first) {
|
||||
});
|
||||
});
|
||||
} else {
|
||||
get_name_generate(guid, announce_payload, first);
|
||||
get_name_generate(guid, announce_payload, first, announce_payload.channel);
|
||||
}
|
||||
}
|
||||
|
||||
function get_name_generate(guid, announce_payload, first) {
|
||||
function get_name_generate(guid, announce_payload, first, channel) {
|
||||
db.collection("user_names").find({"guid": guid}, function(err, docs) {
|
||||
if(docs.length == 0) {
|
||||
generate_name(guid, announce_payload);
|
||||
generate_name(guid, announce_payload, channel);
|
||||
} else {
|
||||
name = docs[0].name;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ function remove_unique_id(short_id) {
|
||||
db.collection("unique_ids").update({"_id": "unique_ids"}, {$pull: {unique_ids: short_id}}, function(err, docs) {});
|
||||
}
|
||||
|
||||
function remove_name_from_db(guid) {
|
||||
function remove_name_from_db(guid, channel) {
|
||||
// Use temporary, with caution. Can bottleneck in large quantity of users.
|
||||
//
|
||||
// Find a way of indexing users in lists in a clever way, to avoid the search here
|
||||
@@ -52,6 +52,11 @@ function remove_name_from_db(guid) {
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if(channel == undefined || channel == "") return;
|
||||
db.collection("user_names").update({"guid": guid}, {$pull: {channels: channel}}, function(err, docs) {
|
||||
//console.log("Pulled user from current channel");
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -135,6 +140,7 @@ function check_inlist(coll, guid, socket, offline, callback)
|
||||
if(docs.length == 1) {
|
||||
var icon = "";
|
||||
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"});
|
||||
}
|
||||
});
|
||||
@@ -368,7 +374,7 @@ function removeSessionAdminPass(id, channel, callback) {
|
||||
function left_channel(coll, guid, short_id, in_list, socket, change) {
|
||||
if(!coll) {
|
||||
if(!change) {
|
||||
remove_name_from_db(guid);
|
||||
remove_name_from_db(guid, coll);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -388,7 +394,7 @@ function left_channel(coll, guid, short_id, in_list, socket, change) {
|
||||
io.to(coll).emit("viewers", new_doc[0].users.length);
|
||||
socket.leave(coll);
|
||||
if(!change) {
|
||||
remove_name_from_db(guid);
|
||||
remove_name_from_db(guid, coll);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -398,7 +404,7 @@ function left_channel(coll, guid, short_id, in_list, socket, change) {
|
||||
//if(updated.nModified > 0) {
|
||||
db.collection("connected_users").update({"_id": "total_users"}, {$pull: {total_users: guid + coll}}, function(err, updated){});
|
||||
if(!change) {
|
||||
remove_name_from_db(guid);
|
||||
remove_name_from_db(guid, coll);
|
||||
}
|
||||
//}
|
||||
});
|
||||
|
||||
@@ -273,7 +273,7 @@ module.exports = function() {
|
||||
});
|
||||
});
|
||||
}
|
||||
Functions.remove_name_from_db(guid);
|
||||
Functions.remove_name_from_db(guid, coll);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -3651,6 +3651,7 @@ nav ul li:hover, nav ul li.active {
|
||||
overflow: auto;
|
||||
opacity: 1;
|
||||
overflow:hidden;
|
||||
padding-right: .5rem !important;
|
||||
}
|
||||
|
||||
#playlist{
|
||||
@@ -3658,6 +3659,7 @@ nav ul li:hover, nav ul li.active {
|
||||
height: 90%;
|
||||
height: calc(100vh - 64px);
|
||||
overflow: hidden;
|
||||
padding-right: 0px;
|
||||
/*padding-right: 0px;*/
|
||||
/*padding:0px 0px 0px 0px;*/
|
||||
}
|
||||
|
||||
@@ -3,9 +3,10 @@ var Chat = {
|
||||
channel_received: 0,
|
||||
all_received: 0,
|
||||
chat_help: [
|
||||
"/name <new name> <password> to register and save a password for a nickname, or to log in with a password on a name.",
|
||||
"/name <new name> <new_password> <old_password> to change the password on a nickname",
|
||||
"/removename to logout"
|
||||
"/login <new name> <password> to register and save a password for a nickname, or to log in with a password on a name.",
|
||||
"/login <name> <new_password> <old_password> to change the password on a nickname",
|
||||
"/logout to logout",
|
||||
"/who to see the names of the people in the channel"
|
||||
],
|
||||
|
||||
namechange: function(data, first, initial) {
|
||||
@@ -43,8 +44,8 @@ var Chat = {
|
||||
|
||||
chat: function(data) {
|
||||
if(data.value.length > 150) return;
|
||||
if(data.value.startsWith("/name ")){
|
||||
Chat.namechange(data.value.substring(6), false);
|
||||
if(data.value.startsWith("/login ")){
|
||||
Chat.namechange(data.value.substring(7), false);
|
||||
} else if(data.value.startsWith("/help")) {
|
||||
var add = "";
|
||||
if(document.querySelector(".chat-tab-li a.active").getAttribute("href") == "#all_chat"){
|
||||
@@ -75,7 +76,7 @@ var Chat = {
|
||||
document.querySelector("#" + add).children[document.querySelector("#" + add).children.length - 1].appendChild(in_text);
|
||||
document.getElementById("" + add).scrollTop = document.getElementById("" + add).scrollHeight;
|
||||
}
|
||||
} else if(data.value.startsWith("/removename")) {
|
||||
} else if(data.value.startsWith("/logout")) {
|
||||
Chat.removename();
|
||||
} else if(document.querySelector(".chat-tab-li a.active").getAttribute("href") == "#all_chat") {
|
||||
socket.emit("all,chat", {channel: chan.toLowerCase(), data: data.value});
|
||||
|
||||
Reference in New Issue
Block a user