mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-08 15:05:46 +01:00
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:
@@ -347,13 +347,25 @@ define(function() {
|
|||||||
confirmDel = confirm((deleteAction ? 'Delete' : 'Restore') + ' this post?');
|
confirmDel = confirm((deleteAction ? 'Delete' : 'Restore') + ' this post?');
|
||||||
|
|
||||||
if (confirmDel) {
|
if (confirmDel) {
|
||||||
deleteAction ?
|
if(deleteAction) {
|
||||||
socket.emit('api:posts.delete', {
|
socket.emit('api:posts.delete', {
|
||||||
pid: pid
|
pid: pid,
|
||||||
}) :
|
tid: tid
|
||||||
socket.emit('api:posts.restore', {
|
}, function(err) {
|
||||||
pid: pid
|
if(err) {
|
||||||
|
return app.alertError('Can\'t delete post!');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
socket.emit('api:posts.restore', {
|
||||||
|
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) {
|
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) {
|
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) {
|
socket.on('api:post.privileges', function(privileges) {
|
||||||
@@ -709,6 +725,7 @@ define(function() {
|
|||||||
} else {
|
} else {
|
||||||
postEl.toggleClass('none');
|
postEl.toggleClass('none');
|
||||||
}
|
}
|
||||||
|
updatePostCount();
|
||||||
});
|
});
|
||||||
socket.emit('api:post.privileges', pid);
|
socket.emit('api:post.privileges', pid);
|
||||||
}
|
}
|
||||||
@@ -871,10 +888,14 @@ define(function() {
|
|||||||
var after = null,
|
var after = null,
|
||||||
firstPid = data.posts[0].pid;
|
firstPid = data.posts[0].pid;
|
||||||
$('#post-container li[data-pid]').each(function() {
|
$('#post-container li[data-pid]').each(function() {
|
||||||
if(parseInt(firstPid, 10) > parseInt($(this).attr('data-pid'), 10))
|
if(parseInt(firstPid, 10) > parseInt($(this).attr('data-pid'), 10)) {
|
||||||
after = $(this);
|
after = $(this);
|
||||||
else
|
if(after.hasClass('main-post')) {
|
||||||
|
after = after.next();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return after;
|
return after;
|
||||||
}
|
}
|
||||||
@@ -908,9 +929,14 @@ define(function() {
|
|||||||
app.addCommasToNumbers();
|
app.addCommasToNumbers();
|
||||||
$('span.timeago').timeago();
|
$('span.timeago').timeago();
|
||||||
$('.post-content img').addClass('img-responsive');
|
$('.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) {
|
function loadMorePosts(tid, callback) {
|
||||||
var indicatorEl = $('.loading-indicator');
|
var indicatorEl = $('.loading-indicator');
|
||||||
|
|
||||||
|
|||||||
@@ -103,7 +103,7 @@
|
|||||||
<div class="inline-block">
|
<div class="inline-block">
|
||||||
<small class="topic-stats">
|
<small class="topic-stats">
|
||||||
<span>posts</span>
|
<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>
|
<span>views</span>
|
||||||
<strong><span class="formatted-number">{viewcount}</span></strong> |
|
<strong><span class="formatted-number">{viewcount}</span></strong> |
|
||||||
<span>browsing</span>
|
<span>browsing</span>
|
||||||
|
|||||||
@@ -139,15 +139,13 @@ var RDB = require('./redis.js'),
|
|||||||
RDB.zadd('users:postcount', postcount, postData.uid);
|
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
|
// Delete the thread if it is the last undeleted post
|
||||||
threadTools.getLatestUndeletedPid(postData.tid, function(err, pid) {
|
threadTools.getLatestUndeletedPid(postData.tid, function(err, pid) {
|
||||||
if (err && err.message === 'no-undeleted-pids-found') {
|
if (err && err.message === 'no-undeleted-pids-found') {
|
||||||
threadTools.delete(postData.tid, -1, function(err) {
|
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 {
|
} else {
|
||||||
posts.getPostField(pid, 'timestamp', function(err, timestamp) {
|
posts.getPostField(pid, 'timestamp', function(err, timestamp) {
|
||||||
@@ -159,15 +157,22 @@ var RDB = require('./redis.js'),
|
|||||||
Feed.updateTopic(postData.tid);
|
Feed.updateTopic(postData.tid);
|
||||||
Feed.updateRecent();
|
Feed.updateRecent();
|
||||||
|
|
||||||
callback();
|
callback(null);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
posts.getPostField(pid, 'deleted', function(err, deleted) {
|
||||||
|
if(deleted === '1') {
|
||||||
|
return callback(new Error('Post already deleted!'));
|
||||||
|
}
|
||||||
|
|
||||||
PostTools.privileges(pid, uid, function(privileges) {
|
PostTools.privileges(pid, uid, function(privileges) {
|
||||||
if (privileges.editable) {
|
if (privileges.editable) {
|
||||||
success();
|
success();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PostTools.restore = function(uid, pid, callback) {
|
PostTools.restore = function(uid, pid, callback) {
|
||||||
@@ -180,10 +185,6 @@ var RDB = require('./redis.js'),
|
|||||||
|
|
||||||
user.incrementUserFieldBy(postData.uid, 'postcount', 1);
|
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) {
|
threadTools.getLatestUndeletedPid(postData.tid, function(err, pid) {
|
||||||
posts.getPostField(pid, 'timestamp', function(err, timestamp) {
|
posts.getPostField(pid, 'timestamp', function(err, timestamp) {
|
||||||
topics.updateTimestamp(postData.tid, timestamp);
|
topics.updateTimestamp(postData.tid, timestamp);
|
||||||
@@ -206,11 +207,17 @@ var RDB = require('./redis.js'),
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
posts.getPostField(pid, 'deleted', function(err, deleted) {
|
||||||
|
if(deleted === '0') {
|
||||||
|
return callback(new Error('Post already restored'));
|
||||||
|
}
|
||||||
|
|
||||||
PostTools.privileges(pid, uid, function(privileges) {
|
PostTools.privileges(pid, uid, function(privileges) {
|
||||||
if (privileges.editable) {
|
if (privileges.editable) {
|
||||||
success();
|
success();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
PostTools.parse = function(raw, callback) {
|
PostTools.parse = function(raw, callback) {
|
||||||
|
|||||||
@@ -1,36 +1,37 @@
|
|||||||
|
|
||||||
var cookie = require('cookie'),
|
var cookie = require('cookie'),
|
||||||
express = require('express'),
|
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'),
|
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'),
|
async = require('async'),
|
||||||
|
fs = require('fs'),
|
||||||
|
nconf = require('nconf'),
|
||||||
|
winston = require('winston'),
|
||||||
|
|
||||||
RedisStoreLib = require('connect-redis')(express),
|
RedisStoreLib = require('connect-redis')(express),
|
||||||
RDB = require('./redis'),
|
RDB = require('./redis'),
|
||||||
util = require('util'),
|
|
||||||
logger = require('./logger.js'),
|
|
||||||
fs = require('fs'),
|
|
||||||
RedisStore = new RedisStoreLib({
|
RedisStore = new RedisStoreLib({
|
||||||
client: RDB,
|
client: RDB,
|
||||||
ttl: 60 * 60 * 24 * 14
|
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')),
|
socketCookieParser = express.cookieParser(nconf.get('secret')),
|
||||||
admin = {
|
admin = {
|
||||||
'categories': require('./admin/categories.js'),
|
'categories': require('./admin/categories'),
|
||||||
'user': require('./admin/user.js')
|
'user': require('./admin/user')
|
||||||
},
|
},
|
||||||
plugins = require('./plugins'),
|
plugins = require('./plugins');
|
||||||
winston = require('winston');
|
|
||||||
|
|
||||||
|
|
||||||
var users = {},
|
var users = {},
|
||||||
@@ -43,10 +44,11 @@ module.exports.logoutUser = function(uid) {
|
|||||||
userSockets[uid][i].emit('event:disconnect');
|
userSockets[uid][i].emit('event:disconnect');
|
||||||
userSockets[uid][i].disconnect();
|
userSockets[uid][i].disconnect();
|
||||||
|
|
||||||
if(!userSockets[uid])
|
if(!userSockets[uid]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isUserOnline(uid) {
|
function isUserOnline(uid) {
|
||||||
@@ -569,15 +571,33 @@ module.exports.init = function(io) {
|
|||||||
postTools.edit(uid, data.pid, data.title, data.content, data.images);
|
postTools.edit(uid, data.pid, data.title, data.content, data.images);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:posts.delete', function(data) {
|
socket.on('api:posts.delete', function(data, callback) {
|
||||||
postTools.delete(uid, data.pid, function() {
|
postTools.delete(uid, data.pid, function(err) {
|
||||||
|
if(err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
posts.getTopicPostStats();
|
posts.getTopicPostStats();
|
||||||
|
|
||||||
|
io.sockets.in('topic_' + data.tid).emit('event:post_deleted', {
|
||||||
|
pid: data.pid
|
||||||
|
});
|
||||||
|
callback(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:posts.restore', function(data) {
|
socket.on('api:posts.restore', function(data, callback) {
|
||||||
postTools.restore(uid, data.pid, function() {
|
postTools.restore(uid, data.pid, function(err) {
|
||||||
|
if(err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
posts.getTopicPostStats();
|
posts.getTopicPostStats();
|
||||||
|
|
||||||
|
io.sockets.in('topic_' + data.tid).emit('event:post_restored', {
|
||||||
|
pid: data.pid
|
||||||
|
});
|
||||||
|
callback(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user