cant delete or restore posts twice, post count goes up or down when posts are deleted or restored in a topic, fixed the post insertion when there is only 1 post in topic

This commit is contained in:
Baris Soner Usakli
2013-11-24 13:58:06 -05:00
parent a16f93cbd5
commit 64ae9ac033
4 changed files with 107 additions and 54 deletions

View File

@@ -139,15 +139,13 @@ var RDB = require('./redis.js'),
RDB.zadd('users:postcount', postcount, postData.uid);
});
io.sockets. in ('topic_' + postData.tid).emit('event:post_deleted', {
pid: pid
});
// Delete the thread if it is the last undeleted post
threadTools.getLatestUndeletedPid(postData.tid, function(err, pid) {
if (err && err.message === 'no-undeleted-pids-found') {
threadTools.delete(postData.tid, -1, function(err) {
if (err) winston.error('Could not delete topic (tid: ' + postData.tid + ')', err.stack);
if (err) {
winston.error('Could not delete topic (tid: ' + postData.tid + ')', err.stack);
}
});
} else {
posts.getPostField(pid, 'timestamp', function(err, timestamp) {
@@ -159,15 +157,22 @@ var RDB = require('./redis.js'),
Feed.updateTopic(postData.tid);
Feed.updateRecent();
callback();
callback(null);
});
};
PostTools.privileges(pid, uid, function(privileges) {
if (privileges.editable) {
success();
posts.getPostField(pid, 'deleted', function(err, deleted) {
if(deleted === '1') {
return callback(new Error('Post already deleted!'));
}
PostTools.privileges(pid, uid, function(privileges) {
if (privileges.editable) {
success();
}
});
});
}
PostTools.restore = function(uid, pid, callback) {
@@ -180,10 +185,6 @@ var RDB = require('./redis.js'),
user.incrementUserFieldBy(postData.uid, 'postcount', 1);
io.sockets. in ('topic_' + postData.tid).emit('event:post_restored', {
pid: pid
});
threadTools.getLatestUndeletedPid(postData.tid, function(err, pid) {
posts.getPostField(pid, 'timestamp', function(err, timestamp) {
topics.updateTimestamp(postData.tid, timestamp);
@@ -206,10 +207,16 @@ var RDB = require('./redis.js'),
});
};
PostTools.privileges(pid, uid, function(privileges) {
if (privileges.editable) {
success();
}
posts.getPostField(pid, 'deleted', function(err, deleted) {
if(deleted === '0') {
return callback(new Error('Post already restored'));
}
PostTools.privileges(pid, uid, function(privileges) {
if (privileges.editable) {
success();
}
});
});
}