active users fix

v1.18.x
Baris Soner Usakli 11 years ago
parent fb691b23b4
commit 1b7f8cc5cb

@ -618,6 +618,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
]); ]);
socket.on('get_users_in_room', function(data) { socket.on('get_users_in_room', function(data) {
if(data && data.room.indexOf('topic') !== -1) { if(data && data.room.indexOf('topic') !== -1) {
var activeEl = $('li.post-bar[data-index="0"] .thread_active_users'); var activeEl = $('li.post-bar[data-index="0"] .thread_active_users');
@ -636,9 +637,9 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
// remove users that are no longer here // remove users that are no longer here
activeEl.find('a').each(function(index, element) { activeEl.find('a').each(function(index, element) {
if(element) { if(element) {
var uid = $(element).attr('data-uid'), var uid = $(element).attr('data-uid');
absent = data.users.every(function(aUid) { absent = data.users.every(function(user) {
return parseInt(aUid, 10) !== parseInt(uid, 10); return parseInt(user.uid, 10) !== parseInt(uid, 10);
}); });
if (absent) { if (absent) {

@ -131,6 +131,7 @@ Sockets.init = function(server) {
emitOnlineUserCount(); emitOnlineUserCount();
for(var roomName in io.sockets.manager.roomClients[socket.id]) { for(var roomName in io.sockets.manager.roomClients[socket.id]) {
console.log('disconnected from', roomName);
updateRoomBrowsingText(roomName.slice(1)); updateRoomBrowsingText(roomName.slice(1));
} }
}); });
@ -235,7 +236,11 @@ function isUserOnline(uid) {
Sockets.updateRoomBrowsingText = updateRoomBrowsingText; Sockets.updateRoomBrowsingText = updateRoomBrowsingText;
function updateRoomBrowsingText(roomName) { function updateRoomBrowsingText(roomName) {
function getUidsInRoom(room) { if (!roomName) {
return;
}
function getUidsInRoom() {
var uids = []; var uids = [];
var clients = io.sockets.clients(roomName); var clients = io.sockets.clients(roomName);
for(var i=0; i<clients.length; ++i) { for(var i=0; i<clients.length; ++i) {
@ -246,7 +251,7 @@ function updateRoomBrowsingText(roomName) {
return uids; return uids;
} }
function getAnonymousCount(roomName) { function getAnonymousCount() {
var clients = io.sockets.clients(roomName); var clients = io.sockets.clients(roomName);
var anonCount = 0; var anonCount = 0;
@ -258,15 +263,17 @@ function updateRoomBrowsingText(roomName) {
return anonCount; return anonCount;
} }
var uids = getUidsInRoom(roomName), var uids = getUidsInRoom(),
anonymousCount = getAnonymousCount(roomName); anonymousCount = getAnonymousCount();
user.getMultipleUserFields(uids, ['uid', 'username', 'userslug', 'picture', 'status'], function(err, users) { user.getMultipleUserFields(uids, ['uid', 'username', 'userslug', 'picture', 'status'], function(err, users) {
if(!err) { if(!err) {
users = users.filter(function(user) { users = users.filter(function(user) {
return user.status !== 'offline'; return user.status !== 'offline';
}); });
console.log('['+roomName+']', users.length, anonymousCount);
io.sockets.in(roomName).emit('get_users_in_room', { io.sockets.in(roomName).emit('get_users_in_room', {
users: users, users: users,
anonymousCount: anonymousCount, anonymousCount: anonymousCount,

@ -85,7 +85,7 @@ SocketMeta.rooms.enter = function(socket, data) {
socket.join(data.enter); socket.join(data.enter);
if (data.leave) { if (data.leave && data.leave !== data.enter) {
module.parent.exports.updateRoomBrowsingText(data.leave); module.parent.exports.updateRoomBrowsingText(data.leave);
} }

@ -135,13 +135,8 @@ SocketModules.composer.pingActive = function(socket, uuid) {
SocketModules.composer.getUsersByTid = function(socket, tid, callback) { SocketModules.composer.getUsersByTid = function(socket, tid, callback) {
// Return uids with active composers // Return uids with active composers
console.log(tid);
callback(null, _.filter(SocketModules.composer.replyHash, function(replyObj, uuid) { callback(null, _.filter(SocketModules.composer.replyHash, function(replyObj, uuid) {
if (parseInt(replyObj.tid, 10) === parseInt(tid, 10)) { return parseInt(replyObj.tid, 10) === parseInt(tid, 10);
return true;
} else {
return false;
}
}).map(function(replyObj) { }).map(function(replyObj) {
return replyObj.uid return replyObj.uid
})); }));

Loading…
Cancel
Save