the online count on the footer uses the websockets now, it should also instantly update when people come online or go offline, #273

v1.18.x
Baris Usakli 12 years ago
parent ae6f9fc87c
commit be51025048

@ -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'] });

@ -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;

@ -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();
});

@ -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) {

Loading…
Cancel
Save