update online users regardless of status

v1.18.x
barisusakli 10 years ago
parent 17d7916fe9
commit 0c5881b51f

@ -42,8 +42,9 @@ middleware.applyCSRF = csrf();
middleware.ensureLoggedIn = ensureLoggedIn.ensureLoggedIn();
middleware.updateLastOnlineTime = function(req, res, next) {
if(req.user) {
if (req.user) {
user.updateLastOnlineTime(req.user.uid);
user.updateOnlineUsers(req.user.uid);
}
db.sortedSetScore('ip:recent', req.ip, function(err, score) {

@ -138,16 +138,25 @@ var async = require('async'),
callback = callback || function() {};
User.getUserFields(uid, ['status', 'lastonline'], function(err, userData) {
var now = Date.now();
if(err || userData.status === 'offline' || now - parseInt(userData.lastonline, 10) < 300000) {
if (err || userData.status === 'offline' || now - parseInt(userData.lastonline, 10) < 300000) {
return callback(err);
}
db.sortedSetAdd('users:online', now, uid);
User.setUserField(uid, 'lastonline', now, callback);
});
};
User.updateOnlineUsers = function(uid, callback) {
callback = callback || function() {};
db.sortedSetScore('users:online', uid, function(err, score) {
var now = Date.now();
if (err || now - parseInt(score, 10) < 300000) {
return callback(err);
}
db.sortedSetAdd('users:online', now, uid, callback);
});
}
User.setUserField = function(uid, field, value, callback) {
plugins.fireHook('action:user.set', {field: field, value: value, type: 'set'});
db.setObjectField('user:' + uid, field, value, callback);

Loading…
Cancel
Save