update online users regardless of status

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

@ -44,6 +44,7 @@ middleware.ensureLoggedIn = ensureLoggedIn.ensureLoggedIn();
middleware.updateLastOnlineTime = function(req, res, next) {
if (req.user) {
user.updateLastOnlineTime(req.user.uid);
user.updateOnlineUsers(req.user.uid);
}
db.sortedSetScore('ip:recent', req.ip, function(err, score) {

@ -142,12 +142,21 @@ var async = require('async'),
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