diff --git a/public/src/forum/admin/index.js b/public/src/forum/admin/index.js
index c0806106dd..c99dd43cb9 100644
--- a/public/src/forum/admin/index.js
+++ b/public/src/forum/admin/index.js
@@ -18,6 +18,7 @@ define(function() {
};
Admin.updateRoomUsage = function(err, data) {
+
function getUserCountIn(room) {
var count = 0;
for(var user in data[room]) {
@@ -25,27 +26,36 @@ define(function() {
}
return count;
}
- var active_users = $('#active_users'),
+
+ var active_users = $('#active_users').html(''),
total = 0;
if(!active_users.length) {
return;
}
- active_users.html('');
- var usersHtml = '';
+ var sortedData = [];
for (var room in data) {
if (room !== '') {
- var count = getUserCountIn(room);
- total += count;
- usersHtml += "
" + room + " " + count + " active user" + (count > 1 ? "s" : "") + "
";
+ sortedData.push({room: room, count: data[room].length});
+ total += data[room].length;
}
}
+ sortedData.sort(function(a, b) {
+ return parseInt(b.count, 10) - parseInt(a.count, 10);
+ });
+
+ var usersHtml = '';
+ for(var i=0; i" + sortedData[i].room + " " +
+ sortedData[i].count + " active user" + (sortedData[i].count > 1 ? "s" : "") + "";
+ }
+
active_users.html(usersHtml);
- document.getElementById('connections').innerHTML = total;
+ $('#connections').html(total);
};
return Admin;
diff --git a/src/routes/debug.js b/src/routes/debug.js
index b2a6e5c335..b25d00a894 100644
--- a/src/routes/debug.js
+++ b/src/routes/debug.js
@@ -75,12 +75,12 @@ var DebugRoute = function(app) {
app.get('/test', function(req, res) {
- /*topics.getTopicPosts2(2, 0, 10, 5, function(err, data) {
- res.json(data);
- })*/
- topics.getTopicWithPosts(2, 1, 0, -1, true, function (err, topicData) {
- res.json(topicData);
+ var db = require('./../database');
+
+ db.getSortedSetRevRange('topics:recent', 0 , -1, function(err, tids) {
+ res.json(tids);
});
+
});
});
diff --git a/src/socket.io/index.js b/src/socket.io/index.js
index 90ff00d7f3..a0d89bc102 100644
--- a/src/socket.io/index.js
+++ b/src/socket.io/index.js
@@ -22,12 +22,11 @@ var SocketIO = require('socket.io'),
/* === */
-var users = {},
- io;
+
+var io;
Sockets.userSockets = {};
-Sockets.rooms = {};
Sockets.init = function(server) {
@@ -59,9 +58,9 @@ Sockets.init = function(server) {
sessionID = socket.handshake.signedCookies["express.sid"];
db.sessionStore.get(sessionID, function(err, sessionData) {
if (!err && sessionData && sessionData.passport && sessionData.passport.user) {
- uid = users[sessionID] = sessionData.passport.user;
+ uid = sessionData.passport.user;
} else {
- uid = users[sessionID] = 0;
+ uid = 0;
}
socket.uid = parseInt(uid, 10);
@@ -110,8 +109,8 @@ Sockets.init = function(server) {
}
if (Sockets.userSockets[uid] && Sockets.userSockets[uid].length === 0) {
- delete users[sessionID];
delete Sockets.userSockets[uid];
+
if (uid) {
db.sortedSetRemove('users:online', uid, function(err, data) {
});
@@ -126,17 +125,10 @@ Sockets.init = function(server) {
emitOnlineUserCount();
- for (var roomName in Sockets.rooms) {
- if (Sockets.rooms.hasOwnProperty(roomName)) {
- socket.leave(roomName);
-
- if (Sockets.rooms[roomName][socket.id]) {
- delete Sockets.rooms[roomName][socket.id];
- }
-
- updateRoomBrowsingText(roomName);
- }
+ for(var roomName in io.sockets.manager.roomClients[socket.id]) {
+ updateRoomBrowsingText(roomName.slice(1));
}
+
});
socket.on('*', function(payload, callback) {
@@ -222,9 +214,10 @@ function updateRoomBrowsingText(roomName) {
function getUidsInRoom(room) {
var uids = [];
- for (var socketId in room) {
- if (uids.indexOf(room[socketId]) === -1) {
- uids.push(room[socketId]);
+ var clients = io.sockets.clients(roomName);
+ for(var i=0; i