fixed anon bug in users browsing this thread code, simplified the logic as well, fixed language

v1.18.x
psychobunny 12 years ago
parent 4a1dc28a26
commit ecf3ffa170

@ -61,7 +61,7 @@ socket.on('api:get_users_in_room', function(users) {
+ ((usercount === 2 && anonymous === 0) ? usernames[0] + ' and ' + usernames[1] : '') + ((usercount === 2 && anonymous === 0) ? usernames[0] + ' and ' + usernames[1] : '')
+ ((usercount > 2 && anonymous === 0) ? usernames.join(', ').replace(/,([^,]*)$/, ", and$1") : '') + ((usercount > 2 && anonymous === 0) ? usernames.join(', ').replace(/,([^,]*)$/, ", and$1") : '')
+ (usercount > 1 && anonymous > 0 ? usernames.join(', ') : '') + (usercount > 1 && anonymous > 0 ? usernames.join(', ') : '')
+ ((anonymous > 0) ? (usercount > 0 ? ' and ': '') + anonymous + ' guest' + (anonymous.length > 1 ? 's are': ' is') : '') + ((anonymous > 0) ? (usercount > 0 ? ' and ': '') + anonymous + ' guest' + (anonymous > 1 ? 's are': ' is') : '')
+ (anonymous === 0 ? (usercount > 1 ? ' are' : ' is') : '') + ' browsing this thread'; + (anonymous === 0 ? (usercount > 1 ? ' are' : ' is') : '') + ' browsing this thread';
document.getElementById('thread_active_users').innerHTML = active; document.getElementById('thread_active_users').innerHTML = active;

@ -6,10 +6,7 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
(function(io) { (function(io) {
var modules = null, var modules = null,
users = {}, users = {},
rooms = { rooms = {}
'users' : {},
'anonymous' : {}
};
global.io = io; global.io = io;
module.exports.init = function() { module.exports.init = function() {
@ -77,35 +74,34 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
if (data.leave !== null) socket.leave (data.leave); if (data.leave !== null) socket.leave (data.leave);
socket.join(data.enter); socket.join(data.enter);
rooms.users[data.enter] = rooms.users[data.enter] || {}; rooms[data.enter] = rooms[data.enter] || {};
if (uid) { if (uid) {
rooms.users[data.enter][uid] = true; rooms[data.enter][uid] = true;
if (rooms.users[data.leave]) { if (rooms[data.leave]) {
delete rooms.users[data.leave][uid]; delete rooms[data.leave][uid];
} }
} else {
rooms.anonymous[data.enter] = (rooms.anonymous[data.enter] || 0) + 1;
rooms.anonymous[data.leave] = rooms.anonymous[data.leave] || 0;
} }
var uids = Object.keys(rooms.users[data.enter] || {}); var uids = Object.keys(rooms[data.enter] || {});
var anonymous = io.sockets.clients(data.enter).length - uids.length;
if (uids.length == 0) { if (uids.length == 0) {
socket.emit('api:get_users_in_room', { io.sockets.in(data.enter).emit('api:get_users_in_room', {
usernames: [], usernames: [],
uids: [], uids: [],
anonymous: rooms.anonymous[data.enter] || 0 anonymous: anonymous
}); });
} }
modules.user.get_usernames_by_uids(uids, function(usernames) { modules.user.get_usernames_by_uids(uids, function(usernames) {
socket.emit('api:get_users_in_room', { io.sockets.in(data.enter).emit('api:get_users_in_room', {
usernames: usernames, usernames: usernames,
uids: uids, uids: uids,
anonymous: rooms.anonymous[data.enter] || 0 anonymous: anonymous
}); });
}); });
}); });
// BEGIN: API calls (todo: organize) // BEGIN: API calls (todo: organize)

Loading…
Cancel
Save