changes to online users code

v1.18.x
Baris Usakli 12 years ago
parent 4f9a2d0b93
commit 2bb4aab6ac

@ -399,10 +399,12 @@ body .navbar .nodebb-inline-block {
.icon-circle {
font-size: 12px;
color: green;
margin-right:3px;
}
.icon-circle-blank {
font-size: 12px;
color: red;
margin-right:3px;
}
}

@ -86,9 +86,11 @@ var socket,
uid = el.parents('li').attr('data-uid');
if (uid && jQuery.inArray(uid, users) !== -1) {
el.prepend('<i class="icon-circle"></i>&nbsp;');
el.find('i').remove();
el.prepend('<i class="icon-circle"></i>');
} else {
el.prepend('<i class="icon-circle-blank"></i>&nbsp;');
el.find('i').remove();
el.prepend('<i class="icon-circle-blank"></i>');
}
el.processed = true;
@ -208,9 +210,7 @@ var socket,
}
};
app.process_page = function() {
function populate_online_users() {
app.populate_online_users = function() {
var uids = [];
jQuery('.post-row').each(function() {
@ -220,13 +220,15 @@ var socket,
socket.emit('api:user.get_online_users', uids);
}
app.process_page = function() {
// here is where all modules' onNavigate should be called, I think.
require(['mobileMenu'], function(mobileMenu) {
mobileMenu.onNavigate();
});
populate_online_users();
app.populate_online_users();
setTimeout(function() {
window.scrollTo(0, 1); // rehide address bar on mobile after page load completes.

@ -324,6 +324,8 @@
var activeEl = $('#thread_active_users');
if(activeEl.length)
activeEl.html(data);
app.populate_online_users();
});
socket.on('event:rep_up', function(data) {
@ -351,6 +353,7 @@
tempContainer.replaceWith(tempContainer.contents());
infiniteLoaderActive = false;
app.populate_online_users();
addCommasToNumbers();
});

@ -904,29 +904,6 @@ var utils = require('./../public/src/utils.js'),
}
};
User.get_online_users = function(socket, uids) {
RDB.sismembers('users:online', uids, function(err, data) {
RDB.handle(err);
socket.emit('api:user.get_online_users', data);
});
};
User.go_online = function(uid) {
RDB.sadd('users:online', uid, function(err) {
if (err) {
RDB.handle(err);
}
});
};
User.go_offline = function(uid) {
RDB.srem('users:online', uid, function(err) {
if (err) {
RDB.handle(err);
}
});
};
User.active = {
get_record : function(socket) {
RDB.mget(['global:active_user_record', 'global:active_user_record_date'], function(err, data) {

@ -58,43 +58,35 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
var hs = socket.handshake;
var uid = users[hs.sessionID];
// if (uid > 0) {
userSockets[uid] = userSockets[uid] || [];
userSockets[uid].push(socket);
user.go_online(uid);
socket.join('uid_' + uid);
// }
/*process.on('uncaughtException', function(err) {
// handle the error safely
console.log("error message "+err);
socket.emit('event:consolelog',{type:'uncaughtException', stack:err.stack, error:err.toString()});
});*/
socket.join('uid_' + uid);
socket.emit('event:connect', {status: 1});
socket.on('disconnect', function() {
// if (uid > 0) {
user.go_offline(uid);
delete users[hs.sessionID];
var index = userSockets[uid].indexOf(socket);
if(index !== -1) {
userSockets[uid].splice(index, 1);
}
if(userSockets[uid].length === 0)
delete users[hs.sessionID];
for(var roomName in rooms) {
socket.leave(roomName);
if(rooms[roomName][hs.sessionID]) {
delete rooms[roomName][hs.sessionID];
if(rooms[roomName][socket.id]) {
delete rooms[roomName][socket.id];
}
updateRoomBrowsingText(roomName);
}
// }
});
socket.on('api:get_all_rooms', function(data) {
@ -105,9 +97,9 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
function getUidsInRoom(room) {
var uids = [];
for(var sessionId in room) {
if(uids.indexOf(room[sessionId]) === -1)
uids.push(room[sessionId]);
for(var socketId in room) {
if(uids.indexOf(room[socketId]) === -1)
uids.push(room[socketId]);
}
return uids;
}
@ -118,6 +110,7 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
for(var i=0; i<clients.length; ++i) {
var hs = clients[i].handshake;
if(hs && !users[hs.sessionID]) {
++anonCount;
}
@ -163,16 +156,16 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
rooms[data.enter] = rooms[data.enter] || {};
if(data.leave) {
if (uid) {
rooms[data.enter][hs.sessionID] = uid;
rooms[data.enter][socket.id] = uid;
if (data.leave && rooms[data.leave] && rooms[data.leave][hs.sessionID]) {
delete rooms[data.leave][hs.sessionID];
if (data.leave && rooms[data.leave] && rooms[data.leave][socket.id]) {
delete rooms[data.leave][socket.id];
}
}
if(data.leave)
updateRoomBrowsingText(data.leave);
}
updateRoomBrowsingText(data.enter);
@ -185,7 +178,6 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
socket.on('api:updateHeader', function(data) {
if(uid) {
user.getUserFields(uid, data.fields, function(fields) {
fields.uid = uid;
socket.emit('api:updateHeader', fields);
@ -237,7 +229,16 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
});
socket.on('api:user.get_online_users', function(data) {
user.get_online_users(socket, data);
var returnData = [];
for(var i=0; i<data.length; ++i) {
var uid = data[i];
if(userSockets[uid] && userSockets[uid].length > 0)
returnData.push(uid);
else
returnData.push(0);
}
socket.emit('api:user.get_online_users', returnData);
});
socket.on('api:user.changePassword', function(data) {

Loading…
Cancel
Save