mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
the online count on the footer uses the websockets now, it should also instantly update when people come online or go offline, #273
This commit is contained in:
71
src/user.js
71
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;
|
||||
|
||||
Reference in New Issue
Block a user