|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
var user = require('../user'),
|
|
|
|
|
var async = require('async'),
|
|
|
|
|
user = require('../user'),
|
|
|
|
|
topics = require('../topics'),
|
|
|
|
|
|
|
|
|
|
SocketUser = {};
|
|
|
|
|
|
|
|
|
|
SocketUser.exists = function(socket, data, callback) {
|
|
|
|
@ -45,10 +45,30 @@ SocketUser.reset.commit = function(socket, data, callback) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SocketUser.isOnline = function(socket, uid, callback) {
|
|
|
|
|
callback(null, {
|
|
|
|
|
online: module.parent.exports.isUserOnline(uid),
|
|
|
|
|
uid: uid,
|
|
|
|
|
timestamp: Date.now()
|
|
|
|
|
user.getUserField(uid, 'status', function(err, status) {
|
|
|
|
|
if(err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!status) {
|
|
|
|
|
status = 'online';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var online = module.parent.exports.isUserOnline(uid);
|
|
|
|
|
if(!online) {
|
|
|
|
|
status = 'offline';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(status === 'offline') {
|
|
|
|
|
online = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback(null, {
|
|
|
|
|
online: online,
|
|
|
|
|
uid: uid,
|
|
|
|
|
timestamp: Date.now(),
|
|
|
|
|
status: status
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -121,19 +141,24 @@ SocketUser.saveSettings = function(socket, data, callback) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SocketUser.getOnlineUsers = function(socket, data, callback) {
|
|
|
|
|
var returnData = [];
|
|
|
|
|
if(data) {
|
|
|
|
|
for (var i = 0; i < data.length; ++i) {
|
|
|
|
|
var uid = data[i];
|
|
|
|
|
if (module.parent.exports.isUserOnline(uid)) {
|
|
|
|
|
returnData.push(uid);
|
|
|
|
|
} else {
|
|
|
|
|
returnData.push(0);
|
|
|
|
|
var returnData = {};
|
|
|
|
|
if(!data) {
|
|
|
|
|
return callback(new Error('invalid-data'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getUserStatus(uid, next) {
|
|
|
|
|
SocketUser.isOnline(socket, uid, function(err, data) {
|
|
|
|
|
if(err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
returnData[uid] = data;
|
|
|
|
|
next();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback(null, returnData);
|
|
|
|
|
async.each(data, getUserStatus, function(err) {
|
|
|
|
|
callback(err, returnData);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SocketUser.getOnlineAnonCount = function(socket, data, callback) {
|
|
|
|
@ -165,6 +190,15 @@ SocketUser.loadMore = function(socket, data, callback) {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SocketUser.setStatus = function(socket, status, callback) {
|
|
|
|
|
var server = require('./index');
|
|
|
|
|
user.setUserField(socket.uid, 'status', status, function(err) {
|
|
|
|
|
SocketUser.isOnline(socket, socket.uid, function(err, data) {
|
|
|
|
|
server.server.sockets.emit('user.isOnline', err, data);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Exports */
|
|
|
|
|
|
|
|
|
|
module.exports = SocketUser;
|