mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
decrease/increase post count on post deletion/restore
This commit is contained in:
@@ -83,21 +83,25 @@ marked.setOptions({
|
|||||||
PostTools.delete = function(uid, pid) {
|
PostTools.delete = function(uid, pid) {
|
||||||
var success = function() {
|
var success = function() {
|
||||||
posts.setPostField(pid, 'deleted', 1);
|
posts.setPostField(pid, 'deleted', 1);
|
||||||
|
|
||||||
|
|
||||||
posts.getPostField(pid, 'tid', function(tid) {
|
posts.getPostFields(pid, ['tid', 'uid'], function(postData) {
|
||||||
io.sockets.in('topic_' + tid).emit('event:post_deleted', {
|
|
||||||
|
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 = [];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user