diff --git a/public/src/forum/footer.js b/public/src/forum/footer.js index d3cc3d094f..31e96395df 100644 --- a/public/src/forum/footer.js +++ b/public/src/forum/footer.js @@ -7,13 +7,16 @@ socket.emit('user.count', {}); socket.on('user.count', function(data) { - stats_users.innerHTML = data.count; + stats_users.innerHTML = utils.makeNumberHumanReadable(data.count); + stats_users.title = data.count; }); socket.emit('post.stats'); socket.on('post.stats', function(data) { - stats_topics.innerHTML = data.topics; - stats_posts.innerHTML = data.posts; + stats_topics.innerHTML = utils.makeNumberHumanReadable(data.topics); + stats_topics.title = data.topics; + stats_posts.innerHTML = utils.makeNumberHumanReadable(data.posts); + stats_posts.title = data.posts; }); socket.emit('api:user.active.get'); diff --git a/public/src/utils.js b/public/src/utils.js index c6f586425e..c99fbb99a3 100644 --- a/public/src/utils.js +++ b/public/src/utils.js @@ -162,6 +162,15 @@ isRelativeUrl: function(url) { var firstChar = url.slice(0, 1); return (firstChar === '.' || firstChar === '/'); + }, + + makeNumberHumanReadable: function(num) { + num = parseInt(num, 10); + if (num > 999999) + return (num / 1000000).toFixed(1) + 'm'; + else if(num > 999) + return (num / 1000).toFixed(1) + 'k'; + return num; } } diff --git a/src/postTools.js b/src/postTools.js index 9f989866cd..ca3dd2dae0 100644 --- a/src/postTools.js +++ b/src/postTools.js @@ -110,10 +110,10 @@ var RDB = require('./redis.js'), }); } - PostTools.delete = function(uid, pid) { + PostTools.delete = function(uid, pid, callback) { var success = function() { posts.setPostField(pid, 'deleted', 1); - + RDB.decr('totalpostcount'); postSearch.remove(pid); posts.getPostFields(pid, ['tid', 'uid'], function(postData) { @@ -141,6 +141,8 @@ var RDB = require('./redis.js'), }); Feed.updateTopic(postData.tid); + + callback(); }); }; @@ -151,9 +153,10 @@ var RDB = require('./redis.js'), }); } - PostTools.restore = function(uid, pid) { + PostTools.restore = function(uid, pid, callback) { var success = function() { posts.setPostField(pid, 'deleted', 0); + RDB.incr('totalpostcount'); posts.getPostFields(pid, ['tid', 'uid', 'content'], function(postData) { RDB.hincrby('topic:' + postData.tid, 'postcount', 1); @@ -180,6 +183,8 @@ var RDB = require('./redis.js'), Feed.updateTopic(postData.tid); postSearch.index(postData.content, pid); + + callback(); }); }; diff --git a/src/threadTools.js b/src/threadTools.js index 6f7b9bbaf7..478f25fd7e 100644 --- a/src/threadTools.js +++ b/src/threadTools.js @@ -92,6 +92,9 @@ var RDB = require('./redis.js'), if (privileges.editable || uid === -1) { topics.delete(tid); + + RDB.decr('totaltopiccount'); + ThreadTools.lock(tid, uid); topicSearch.remove(tid); @@ -106,11 +109,12 @@ var RDB = require('./redis.js'), }); } - ThreadTools.restore = function(tid, uid, socket) { + ThreadTools.restore = function(tid, uid, socket, callback) { ThreadTools.privileges(tid, uid, function(privileges) { if (privileges.editable) { topics.restore(tid); + RDB.incr('totaltopiccount'); ThreadTools.unlock(tid, uid); io.sockets. in ('topic_' + tid).emit('event:topic_restored', { @@ -118,16 +122,12 @@ var RDB = require('./redis.js'), status: 'ok' }); - if (socket) { - socket.emit('api:topic.restore', { - status: 'ok', - tid: tid - }); - } - topics.getTopicField(tid, 'title', function(err, title) { topicSearch.index(title, tid); }); + + if(callback) + callback(null); } }); } diff --git a/src/topics.js b/src/topics.js index ed73a06c58..ec86fde245 100644 --- a/src/topics.js +++ b/src/topics.js @@ -788,6 +788,7 @@ var RDB = require('./redis.js'), Topics.getTopicField(tid, 'cid', function(err, cid) { feed.updateCategory(cid); + RDB.hincrby('category:' + cid, 'topic_count', -1); }); } @@ -799,6 +800,7 @@ var RDB = require('./redis.js'), Topics.getTopicField(tid, 'cid', function(err, cid) { feed.updateCategory(cid); + RDB.hincrby('category:' + cid, 'topic_count', 1); }); } diff --git a/src/websockets.js b/src/websockets.js index ad0403b3a1..1a9f43b9fc 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -493,6 +493,7 @@ module.exports.init = function(io) { socket.on('api:topic.delete', function(data) { threadTools.delete(data.tid, uid, function(err) { if (!err) { + posts.getTopicPostStats(socket); socket.emit('api:topic.delete', { status: 'ok', tid: data.tid @@ -502,7 +503,14 @@ module.exports.init = function(io) { }); socket.on('api:topic.restore', function(data) { - threadTools.restore(data.tid, uid, socket); + threadTools.restore(data.tid, uid, socket, function(err) { + posts.getTopicPostStats(socket); + + socket.emit('api:topic.restore', { + status: 'ok', + tid: data.tid + }); + }); }); socket.on('api:topic.lock', function(data) { @@ -555,11 +563,15 @@ module.exports.init = function(io) { }); socket.on('api:posts.delete', function(data) { - postTools.delete(uid, data.pid); + postTools.delete(uid, data.pid, function() { + posts.getTopicPostStats(socket); + }); }); socket.on('api:posts.restore', function(data) { - postTools.restore(uid, data.pid); + postTools.restore(uid, data.pid, function() { + posts.getTopicPostStats(socket); + }); }); socket.on('api:notifications.get', function(data, callback) {