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

v1.18.x
Baris Soner Usakli 11 years ago
parent a16f93cbd5
commit 64ae9ac033

@ -347,13 +347,25 @@ define(function() {
confirmDel = confirm((deleteAction ? 'Delete' : 'Restore') + ' this post?');
if (confirmDel) {
deleteAction ?
if(deleteAction) {
socket.emit('api:posts.delete', {
pid: pid
}) :
pid: pid,
tid: tid
}, function(err) {
if(err) {
return app.alertError('Can\'t delete post!');
}
});
} else {
socket.emit('api:posts.restore', {
pid: pid
pid: pid,
tid: tid
}, function(err) {
if(err) {
return app.alertError('Can\'t restore post!');
}
});
}
}
});
@ -546,11 +558,15 @@ define(function() {
});
socket.on('event:post_deleted', function(data) {
if (data.pid) toggle_post_delete_state(data.pid, true);
if (data.pid) {
toggle_post_delete_state(data.pid);
}
});
socket.on('event:post_restored', function(data) {
if (data.pid) toggle_post_delete_state(data.pid, true);
if (data.pid) {
toggle_post_delete_state(data.pid);
}
});
socket.on('api:post.privileges', function(privileges) {
@ -709,6 +725,7 @@ define(function() {
} else {
postEl.toggleClass('none');
}
updatePostCount();
});
socket.emit('api:post.privileges', pid);
}
@ -871,10 +888,14 @@ define(function() {
var after = null,
firstPid = data.posts[0].pid;
$('#post-container li[data-pid]').each(function() {
if(parseInt(firstPid, 10) > parseInt($(this).attr('data-pid'), 10))
after = $(this);
else
return false;
if(parseInt(firstPid, 10) > parseInt($(this).attr('data-pid'), 10)) {
after = $(this);
if(after.hasClass('main-post')) {
after = after.next();
}
} else {
return false;
}
});
return after;
}
@ -908,9 +929,14 @@ define(function() {
app.addCommasToNumbers();
$('span.timeago').timeago();
$('.post-content img').addClass('img-responsive');
updatePostCount();
});
}
function updatePostCount() {
$('#topic-post-count').html($('#post-container li[data-pid]:not(.deleted)').length);
}
function loadMorePosts(tid, callback) {
var indicatorEl = $('.loading-indicator');

@ -103,7 +103,7 @@
<div class="inline-block">
<small class="topic-stats">
<span>posts</span>
<strong><span class="formatted-number">{postcount}</span></strong> |
<strong><span id="topic-post-count" class="formatted-number">{postcount}</span></strong> |
<span>views</span>
<strong><span class="formatted-number">{viewcount}</span></strong> |
<span>browsing</span>

@ -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();
}
});
});
}

@ -1,36 +1,37 @@
var cookie = require('cookie'),
var cookie = require('cookie'),
express = require('express'),
user = require('./user.js'),
Groups = require('./groups'),
posts = require('./posts.js'),
favourites = require('./favourites.js'),
utils = require('../public/src/utils.js'),
util = require('util'),
topics = require('./topics.js'),
categories = require('./categories.js'),
notifications = require('./notifications.js'),
threadTools = require('./threadTools.js'),
postTools = require('./postTools.js'),
meta = require('./meta.js'),
async = require('async'),
fs = require('fs'),
nconf = require('nconf'),
winston = require('winston'),
RedisStoreLib = require('connect-redis')(express),
RDB = require('./redis'),
util = require('util'),
logger = require('./logger.js'),
fs = require('fs'),
RedisStore = new RedisStoreLib({
client: RDB,
ttl: 60 * 60 * 24 * 14
}),
nconf = require('nconf'),
user = require('./user'),
Groups = require('./groups'),
posts = require('./posts'),
favourites = require('./favourites'),
utils = require('../public/src/utils'),
topics = require('./topics'),
categories = require('./categories'),
notifications = require('./notifications'),
threadTools = require('./threadTools'),
postTools = require('./postTools'),
meta = require('./meta'),
logger = require('./logger'),
socketCookieParser = express.cookieParser(nconf.get('secret')),
admin = {
'categories': require('./admin/categories.js'),
'user': require('./admin/user.js')
'categories': require('./admin/categories'),
'user': require('./admin/user')
},
plugins = require('./plugins'),
winston = require('winston');
plugins = require('./plugins');
var users = {},
@ -43,8 +44,9 @@ module.exports.logoutUser = function(uid) {
userSockets[uid][i].emit('event:disconnect');
userSockets[uid][i].disconnect();
if(!userSockets[uid])
if(!userSockets[uid]) {
return;
}
}
}
}
@ -569,15 +571,33 @@ module.exports.init = function(io) {
postTools.edit(uid, data.pid, data.title, data.content, data.images);
});
socket.on('api:posts.delete', function(data) {
postTools.delete(uid, data.pid, function() {
socket.on('api:posts.delete', function(data, callback) {
postTools.delete(uid, data.pid, function(err) {
if(err) {
return callback(err);
}
posts.getTopicPostStats();
io.sockets.in('topic_' + data.tid).emit('event:post_deleted', {
pid: data.pid
});
callback(null);
});
});
socket.on('api:posts.restore', function(data) {
postTools.restore(uid, data.pid, function() {
socket.on('api:posts.restore', function(data, callback) {
postTools.restore(uid, data.pid, function(err) {
if(err) {
return callback(err);
}
posts.getTopicPostStats();
io.sockets.in('topic_' + data.tid).emit('event:post_restored', {
pid: data.pid
});
callback(null);
});
});

Loading…
Cancel
Save