From 789a3cc1e764322e836a01a253e7e8e1d48b205e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Rynning-T=C3=B8nnesen?= Date: Tue, 21 Nov 2017 11:27:01 +0100 Subject: [PATCH] Fixed issue with viewercounter being below 0 --- server/handlers/io.js | 2 +- server/handlers/list.js | 8 ++++---- server/handlers/list_change.js | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/server/handlers/io.js b/server/handlers/io.js index b416ccfc..a55f9261 100644 --- a/server/handlers/io.js +++ b/server/handlers/io.js @@ -124,7 +124,7 @@ module.exports = function() { }, function(err, updated) { if(updated.nModified > 0) { io.to(coll).emit("viewers", updated.users); - db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: -1}}, function(err, docs){ + db.collection("connected_users").update({"_id": "total_users", total_users: {$gt: 0}}, {$inc: {total_users: -1}}, function(err, docs){ db.collection("connected_users").update({"_id": "offline_users"}, {$addToSet: {users: guid}}, function(err, docs) { if(docs.nModified == 1) { db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: 1}}, function(err, docs) {}); diff --git a/server/handlers/list.js b/server/handlers/list.js index 1e5b8a0d..7902903a 100644 --- a/server/handlers/list.js +++ b/server/handlers/list.js @@ -184,7 +184,7 @@ function change_song(coll, error, id) { if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id; List.change_song_post(coll, next_song); io.to(coll).emit("channel", {type: "deleted", value: now_playing_doc[0].id, removed: true}); - db.collection("frontpage_lists").update({_id: coll}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){}); + db.collection("frontpage_lists").update({_id: coll, count: {$gt: 0}}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){}); }); } else { if((docs[0].skipped_time != undefined && docs[0].skipped_time != Functions.get_time()) || docs[0].skipped_time == undefined) { @@ -211,7 +211,7 @@ function change_song(coll, error, id) { if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id; List.change_song_post(coll, next_song); io.to(coll).emit("channel", {type: "deleted", value: now_playing_doc[0].id, removed: true}); - db.collection("frontpage_lists").update({_id: coll}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){}); + db.collection("frontpage_lists").update({_id: coll, count: {$gt: 0}}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){}); }); } else { if((docs[0].skipped_time != undefined && docs[0].skipped_time != Functions.get_time()) || docs[0].skipped_time == undefined) { @@ -404,7 +404,7 @@ function end(obj, coll, guid, offline, socket) { { db.collection(coll).remove({now_playing:true}, function(err, docs){ List.change_song_post(coll); - db.collection("frontpage_lists").update({_id:coll}, {$inc:{count:-1}, $set:{accessed: Functions.get_time()}}, {upsert:true}, function(err, docs){}); + db.collection("frontpage_lists").update({_id:coll, count: {$gt: 0}}, {$inc:{count:-1}, $set:{accessed: Functions.get_time()}}, {upsert:true}, function(err, docs){}); }); }else{ if(startTime+parseInt(np[0].duration)<=Functions.get_time()+5) @@ -499,7 +499,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); }); - db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: -1}}, function(err, updated){}); + db.collection("connected_users").update({"_id": "total_users", total_users: {$gt: 0}}, {$inc: {total_users: -1}}, function(err, updated){}); if(!change) { Functions.remove_name_from_db(guid, name); diff --git a/server/handlers/list_change.js b/server/handlers/list_change.js index 47008ae5..0fd44013 100644 --- a/server/handlers/list_change.js +++ b/server/handlers/list_change.js @@ -258,7 +258,7 @@ function del(params, socket, socketid) { db.collection(coll).remove({id:params.id}, function(err, docs){ socket.emit("toast", "deletesong"); io.to(coll).emit("channel", {type:"deleted", value: params.id}); - if(dont_increment) db.collection("frontpage_lists").update({_id: coll}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){}); + if(dont_increment) db.collection("frontpage_lists").update({_id: coll, count: {$gt: 0}}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){}); }); } });