if every post gets deleted in a topic, then the topic deletes itself also

v1.18.x
Julian Lam 12 years ago
parent 87aec422e9
commit 561ff38e5a

@ -88,6 +88,15 @@ marked.setOptions({
io.sockets.in('topic_' + tid).emit('event:post_deleted', {
pid: pid
});
// Delete the thread if it is the last undeleted post
threadTools.get_latest_undeleted_pid(tid, function(err, pid) {
if (err && err.message === 'no-undeleted-pids-found') {
threadTools.delete(tid, -1, function(err) {
if (err) console.log('Error: Could not delete topic (tid: ' + tid + ')');
});
}
});
});
};

@ -81,25 +81,20 @@ var RDB = require('./redis.js'),
});
}
ThreadTools.delete = function(tid, uid, socket) {
ThreadTools.delete = function(tid, uid, callback) {
ThreadTools.privileges(tid, uid, function(privileges) {
if (privileges.editable) {
if (privileges.editable || uid === -1) {
topics.setTopicField(tid, 'deleted', 1);
ThreadTools.lock(tid, uid);
if (socket) {
io.sockets.in('topic_' + tid).emit('event:topic_deleted', {
tid: tid,
status: 'ok'
});
socket.emit('api:topic.delete', {
status: 'ok',
tid: tid
});
}
}
callback(null);
} else callback(new Error('not-enough-privs'));
});
}

@ -286,7 +286,14 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
});
socket.on('api:topic.delete', function(data) {
threadTools.delete(data.tid, uid, socket);
threadTools.delete(data.tid, uid, function(err) {
if (!err) {
socket.emit('api:topic.delete', {
status: 'ok',
tid: data.tid
});
}
});
});
socket.on('api:topic.restore', function(data) {

Loading…
Cancel
Save