diff --git a/public/src/forum/footer.js b/public/src/forum/footer.js index f9fd1115cf..f1d0c8da9c 100644 --- a/public/src/forum/footer.js +++ b/public/src/forum/footer.js @@ -19,7 +19,7 @@ socket.emit('api:user.active.get'); socket.on('api:user.active.get', function(data) { - stats_online.innerHTML = data.users + data.anon; + stats_online.innerHTML = data.users; }); socket.emit('api:updateHeader', { fields: ['username', 'picture', 'userslug'] }); diff --git a/src/user.js b/src/user.js index 49bc63cce8..ce03af3527 100644 --- a/src/user.js +++ b/src/user.js @@ -911,77 +911,6 @@ var utils = require('./../public/src/utils.js'), } }; - User.active = { - get_record : function(socket) { - RDB.mget(['global:active_user_record', 'global:active_user_record_date'], function(err, data) { - RDB.handle(err); - socket.emit('api:user.active.get_record', { record: data[0], timestamp: data[1] }); - }); - }, - - get: function(callback) { - function user_record(total) { - RDB.get('global:active_user_record', function(err, record) { - RDB.handle(err); - - if (total > record) { - RDB.set('global:active_user_record', total); - RDB.set('global:active_user_record_date', Date.now()); - } - }); - } - - RDB.keys('active:*', function(err, active) { - RDB.handle(err); - - var returnObj = { - users: 0, - anon: 0, - uids: [] - }, - keys = []; - - if (active.length > 0) { - for(var a in active) { - keys.push('sess:' + active[a].split(':')[1] + ':uid'); - } - - RDB.mget(keys, function(err, uids) { - RDB.handle(err); - - for(var u in uids) { - if (uids[u] !== null) { - if (returnObj.uids.indexOf(uids[u]) === -1) { - returnObj.users++; - returnObj.uids.push(uids[u]); - } - } else { - returnObj.anon++; - } - } - - user_record(returnObj.anon + returnObj.users); - - if (callback === undefined) { - io.sockets.emit('api:user.active.get', returnObj) - } else { - callback(returnObj); - } - }); - } else { - io.sockets.emit('api:user.active.get', returnObj) - } - }); - }, - register: function(sessionID) { - // Active state persists for 10 minutes - var active_session = 'active:' + sessionID; - RDB.set(active_session, ''); - RDB.expire(active_session, 60*10) - this.get(); - } - } - User.notifications = { get: function(uid, callback) { var maxNotifs = 15; diff --git a/src/webserver.js b/src/webserver.js index c04b59fb20..f8ec7d047a 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -99,9 +99,6 @@ var express = require('express'), user.session_ping(req.sessionID, req.user.uid); } - // (Re-)register the session as active - user.active.register(req.sessionID); - next(); }); diff --git a/src/websockets.js b/src/websockets.js index 54f1356a90..bc6b3eae47 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -76,6 +76,7 @@ var SocketIO = require('socket.io').listen(global.server, { if(userSockets[uid].length === 0) { delete users[sessionID]; + emitOnlineUserCount(); if(uid) { io.sockets.in('global').emit('api:user.isOnline', isUserOnline(uid)); } @@ -410,8 +411,17 @@ var SocketIO = require('socket.io').listen(global.server, { }); }); + function emitOnlineUserCount() { + var online = Object.keys(users); + + var returnObj = { + users: online.length + }; + io.sockets.emit('api:user.active.get', returnObj) + } + socket.on('api:user.active.get', function() { - user.active.get(); + emitOnlineUserCount(); }); socket.on('api:posts.favourite', function(data) { @@ -422,10 +432,6 @@ var SocketIO = require('socket.io').listen(global.server, { favourites.unfavourite(data.pid, data.room_id, uid, socket); }); - socket.on('api:user.active.get_record', function() { - user.active.get_record(socket); - }); - socket.on('api:topic.delete', function(data) { threadTools.delete(data.tid, uid, function(err) { if (!err) {