diff --git a/public/src/forum/home.js b/public/src/forum/home.js index 2988a0c695..c38568bd6c 100644 --- a/public/src/forum/home.js +++ b/public/src/forum/home.js @@ -9,18 +9,27 @@ define(function() { 'user.getActiveUsers' ]); - socket.emit('user.count', function(data) { + socket.emit('user.count', updateUserCount); + socket.on('user.count', updateUserCount); + + function updateUserCount(err, data) { $('#stats_users').html(utils.makeNumberHumanReadable(data.count)).attr('title', data.count); - }); + } + + socket.emit('meta.getUsageStats', updateUsageStats); + socket.on('meta.getUsageStats', updateUsageStats); - socket.emit('meta.getUsageStats', function(data) { + function updateUsageStats(err, data) { $('#stats_topics').html(utils.makeNumberHumanReadable(data.topics)).attr('title', data.topics); $('#stats_posts').html(utils.makeNumberHumanReadable(data.posts)).attr('title', data.posts); - }); + } + + socket.emit('user.getActiveUsers', updateActiveUsers); + socket.on('user.getActiveUsers', updateActiveUsers); - socket.emit('user.getActiveUsers', function(data) { + function updateActiveUsers(err, data) { $('#stats_online').html(data.users); - }); + } } return home; diff --git a/src/socket.io/index.js b/src/socket.io/index.js index 8781156188..8c27bbaa14 100644 --- a/src/socket.io/index.js +++ b/src/socket.io/index.js @@ -139,8 +139,8 @@ Sockets.init = function() { } }); } -console.log('derp'); -console.log(payload, callback); + + var parts = payload.name.split('.'), namespace = parts.slice(0, 1), methodToCall = parts.reduce(function(prev, cur) { @@ -182,7 +182,7 @@ Sockets.logoutUser = function(uid) { Sockets.emitUserCount = function() { db.getObjectField('global', 'userCount', function(err, count) { - io.sockets.emit('user.count', { + io.sockets.emit('user.count', err?{message:err.message}:null, { count: count }); }); @@ -261,9 +261,9 @@ function emitTopicPostStats(callback) { }; if (!callback) { - io.sockets.emit('post.stats', stats); + io.sockets.emit('post.stats', null, stats); } else { - callback(stats); + callback(null, stats); } }); } @@ -282,9 +282,9 @@ function emitOnlineUserCount(callback) { }; if (callback) { - callback(returnObj); + callback(null, returnObj); } else { - io.sockets.emit('user.active.get', returnObj); + io.sockets.emit('user.getActiveUsers', null, returnObj); } } diff --git a/src/user.js b/src/user.js index ce68d70836..8c12611149 100644 --- a/src/user.js +++ b/src/user.js @@ -673,10 +673,10 @@ var bcrypt = require('bcrypt'), User.count = function(callback) { db.getObjectField('global', 'userCount', function(err, count) { if(err) { - return; + return callback(err); } - callback({ + callback(null, { count: count ? count : 0 }); });