mirror of
https://github.com/KevinMidboe/zoff.git
synced 2026-01-01 07:06:17 +00:00
Fixing issue with too many total viewers
This commit is contained in:
@@ -1266,14 +1266,12 @@ function send_ping() {
|
|||||||
function left_channel(coll, guid, name, short_id, in_list, socket, change)
|
function left_channel(coll, guid, name, short_id, in_list, socket, change)
|
||||||
{
|
{
|
||||||
if(!coll) return;
|
if(!coll) return;
|
||||||
db.collection("connected_users").findAndModify({
|
db.collection("connected_users").update({"_id": coll}, {$pull: {users: guid}}, function(err, updated) {
|
||||||
query: {"_id": coll},
|
if(updated.nModified > 0) {
|
||||||
update: {$pull: {users: guid}},
|
db.collection("connected_users").find({"_id": coll}, function(err, new_doc){
|
||||||
upsert: true }, function(err, updated, lastErr){
|
|
||||||
if(updated.users.indexOf(guid) > -1) {
|
|
||||||
db.collection("frontpage_lists").update({"_id": coll, viewers: {$gt: 0}}, {$inc: {viewers: -1}}, function(err, doc) {
|
db.collection("frontpage_lists").update({"_id": coll, viewers: {$gt: 0}}, {$inc: {viewers: -1}}, function(err, doc) {
|
||||||
socket.leave(coll);
|
socket.leave(coll);
|
||||||
io.to(coll).emit("viewers", updated.users.length);
|
io.to(coll).emit("viewers", new_doc[0].users.length);
|
||||||
io.to(coll).emit('chat', {from: name, msg: " left"});
|
io.to(coll).emit('chat', {from: name, msg: " left"});
|
||||||
});
|
});
|
||||||
db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: -1}}, function(err, updated){});
|
db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: -1}}, function(err, updated){});
|
||||||
@@ -1282,8 +1280,8 @@ function left_channel(coll, guid, name, short_id, in_list, socket, change)
|
|||||||
remove_from_array(names.names, name);
|
remove_from_array(names.names, name);
|
||||||
delete names[guid];
|
delete names[guid];
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
db.collection("connected_users").update({"_id": "offline_users"}, {$pull: {users: guid}}, function(err, updated){});
|
|
||||||
});
|
});
|
||||||
/*
|
/*
|
||||||
if(lists[coll] !== undefined && contains(lists[coll], guid))
|
if(lists[coll] !== undefined && contains(lists[coll], guid))
|
||||||
@@ -1389,19 +1387,19 @@ function del(params, socket, socketid) {
|
|||||||
function check_inlist(coll, guid, socket, name, offline)
|
function check_inlist(coll, guid, socket, name, offline)
|
||||||
{
|
{
|
||||||
if(!offline && coll != undefined){
|
if(!offline && coll != undefined){
|
||||||
db.collection("connected_users").findAndModify({
|
db.collection("connected_users").update({"_id": coll}, {$addToSet:{users: guid}}, {upsert: true}, function(err, updated) {
|
||||||
query: {"_id": coll},
|
if(updated.nModified > 0) {
|
||||||
update: {$addToSet: {users: guid}},
|
db.collection("connected_users").find({"_id": coll}, function(err, new_doc) {
|
||||||
upsert: true,
|
db.collection("frontpage_lists").update({"_id": coll}, {$set: {"viewers": new_doc[0].users.length}}, function(){
|
||||||
new: true,
|
io.to(coll).emit("viewers", new_doc[0].users.length);
|
||||||
}, function(err, conn_users, objectTwo) {
|
|
||||||
db.collection("frontpage_lists").update({"_id": coll}, {$set: {"viewers": conn_users.users.length}}, function(){
|
|
||||||
io.to(coll).emit("viewers", conn_users.users.length);
|
|
||||||
socket.broadcast.to(coll).emit('chat', {from: name, msg: " joined"});
|
socket.broadcast.to(coll).emit('chat', {from: name, msg: " joined"});
|
||||||
|
|
||||||
db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: 1}}, function(err, docs){});
|
db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: 1}}, function(err, docs){});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if(lists[coll] === undefined)
|
if(lists[coll] === undefined)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user