decrease/increase post count on post deletion/restore

v1.18.x
Baris Usakli 12 years ago
parent 3adddf44ca
commit a4de1b247f

@ -84,20 +84,24 @@ marked.setOptions({
var success = function() { var success = function() {
posts.setPostField(pid, 'deleted', 1); 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 pid: pid
}); });
// Delete the thread if it is the last undeleted post // 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') { if (err && err.message === 'no-undeleted-pids-found') {
threadTools.delete(tid, -1, function(err) { threadTools.delete(postData.tid, -1, function(err) {
if (err) console.log('Error: Could not delete topic (tid: ' + tid + ')'); if (err) console.log('Error: Could not delete topic (tid: ' + postData.tid + ')');
}); });
} else { } else {
posts.getPostField(pid, 'timestamp', function(timestamp) { posts.getPostField(pid, 'timestamp', function(timestamp) {
topics.updateTimestamp(tid, timestamp); topics.updateTimestamp(postData.tid, timestamp);
}); });
} }
}); });
@ -115,8 +119,11 @@ marked.setOptions({
var success = function() { var success = function() {
posts.setPostField(pid, 'deleted', 0); posts.setPostField(pid, 'deleted', 0);
posts.getPostField(pid, 'tid', function(tid) { posts.getPostFields(pid, ['tid', 'uid', function(postData) {
io.sockets.in('topic_' + tid).emit('event:post_restored', {
user.incrementUserFieldBy(postData.uid, 'postcount', 1);
io.sockets.in('topic_' + postData.tid).emit('event:post_restored', {
pid: pid pid: pid
}); });
}); });

@ -82,8 +82,9 @@ marked.setOptions({
Posts.getPostData = function(pid, callback) { Posts.getPostData = function(pid, callback) {
RDB.hgetall('post:' + pid, function(err, data) { RDB.hgetall('post:' + pid, function(err, data) {
if(err === null) if(err === null) {
callback(data); callback(data);
}
else else
console.log(err); console.log(err);
}); });

@ -316,6 +316,10 @@ var utils = require('./../public/src/utils.js'),
RDB.hincrby('user:' + uid, field, value); RDB.hincrby('user:' + uid, field, value);
} }
User.decrementUserFieldBy = function(uid, field, value) {
RDB.hincrby('user:' + uid, field, -value);
}
User.getUserList = function(callback) { User.getUserList = function(callback) {
var data = []; var data = [];

Loading…
Cancel
Save