Node.js based forum software built for the modern web
decrease/increase post count on post deletion/restore
Baris Usaklia4de1b247fba
diff --git a/src/postTools.js b/src/postTools.jsindex 7759f7ef60..736613cc35 100644--- a/src/postTools.js+++ b/src/postTools.js@@ -83,21 +83,25 @@ marked.setOptions({PostTools.delete = function(uid, pid) {var success = function() {posts.setPostField(pid, 'deleted', 1);+- posts.getPostField(pid, 'tid', function(tid) {- io.sockets.in('topic_' + tid).emit('event:post_deleted', {+ posts.getPostFields(pid, ['tid', 'uid'], function(postData) {++ user.decrementUserFieldBypostData.uid, 'postcount', 1);++ io.sockets.in('topic_' + postData.tid).emit('event:post_deleted', {pid: pid});// Delete the thread if it is the last undeleted post- threadTools.get_latest_undeleted_pid(tid, function(err, pid) {+ threadTools.get_latest_undeleted_pid(postData.tid, function(err, pid) {if (err && err.message === 'no-undeleted-pids-found') {- threadTools.delete(tid, -1, function(err) {- if (err) console.log('Error: Could not delete topic (tid: ' + tid + ')');+ threadTools.delete(postData.tid, -1, function(err) {+ if (err) console.log('Error: Could not delete topic (tid: ' + postData.tid + ')');});} else {posts.getPostField(pid, 'timestamp', function(timestamp) {- topics.updateTimestamp(tid, timestamp);+ topics.updateTimestamp(postData.tid, timestamp);});}});@@ -115,8 +119,11 @@ marked.setOptions({var success = function() {posts.setPostField(pid, 'deleted', 0);- posts.getPostField(pid, 'tid', function(tid) {- io.sockets.in('topic_' + tid).emit('event:post_restored', {+ posts.getPostFields(pid, ['tid', 'uid', function(postData) {++ user.incrementUserFieldBy(postData.uid, 'postcount', 1);++ io.sockets.in('topic_' + postData.tid).emit('event:post_restored', {pid: pid});});diff --git a/src/posts.js b/src/posts.jsindex dd28e6c64e..3c9714b5bc 100644--- a/src/posts.js+++ b/src/posts.js@@ -82,8 +82,9 @@ marked.setOptions({Posts.getPostData = function(pid, callback) {RDB.hgetall('post:' + pid, function(err, data) {- if(err === null)+ if(err === null) {callback(data);+ }elseconsole.log(err);});diff --git a/src/user.js b/src/user.jsindex 0e8e84f1fc..e32214f483 100644--- a/src/user.js+++ b/src/user.js@@ -316,6 +316,10 @@ var utils = require('./../public/src/utils.js'),RDB.hincrby('user:' + uid, field, value);}+ User.decrementUserFieldBy = function(uid, field, value) {+ RDB.hincrby('user:' + uid, field, -value);+ }+User.getUserList = function(callback) {var data = [];