v1.18.x
Baris Usakli 11 years ago
parent 230ed1ab11
commit 929336cb57

@ -110,10 +110,10 @@ var RDB = require('./redis.js'),
}); });
} }
PostTools.delete = function(uid, pid) { PostTools.delete = function(uid, pid, callback) {
var success = function() { var success = function() {
posts.setPostField(pid, 'deleted', 1); posts.setPostField(pid, 'deleted', 1);
RDB.decr('totalpostcount');
postSearch.remove(pid); postSearch.remove(pid);
posts.getPostFields(pid, ['tid', 'uid'], function(postData) { posts.getPostFields(pid, ['tid', 'uid'], function(postData) {
@ -141,6 +141,8 @@ var RDB = require('./redis.js'),
}); });
Feed.updateTopic(postData.tid); Feed.updateTopic(postData.tid);
callback();
}); });
}; };
@ -151,9 +153,10 @@ var RDB = require('./redis.js'),
}); });
} }
PostTools.restore = function(uid, pid) { PostTools.restore = function(uid, pid, callback) {
var success = function() { var success = function() {
posts.setPostField(pid, 'deleted', 0); posts.setPostField(pid, 'deleted', 0);
RDB.incr('totalpostcount');
posts.getPostFields(pid, ['tid', 'uid', 'content'], function(postData) { posts.getPostFields(pid, ['tid', 'uid', 'content'], function(postData) {
RDB.hincrby('topic:' + postData.tid, 'postcount', 1); RDB.hincrby('topic:' + postData.tid, 'postcount', 1);
@ -180,6 +183,8 @@ var RDB = require('./redis.js'),
Feed.updateTopic(postData.tid); Feed.updateTopic(postData.tid);
postSearch.index(postData.content, pid); postSearch.index(postData.content, pid);
callback();
}); });
}; };

@ -92,6 +92,9 @@ var RDB = require('./redis.js'),
if (privileges.editable || uid === -1) { if (privileges.editable || uid === -1) {
topics.delete(tid); topics.delete(tid);
RDB.decr('totaltopiccount');
ThreadTools.lock(tid, uid); ThreadTools.lock(tid, uid);
topicSearch.remove(tid); topicSearch.remove(tid);
@ -106,11 +109,12 @@ var RDB = require('./redis.js'),
}); });
} }
ThreadTools.restore = function(tid, uid, socket) { ThreadTools.restore = function(tid, uid, socket, callback) {
ThreadTools.privileges(tid, uid, function(privileges) { ThreadTools.privileges(tid, uid, function(privileges) {
if (privileges.editable) { if (privileges.editable) {
topics.restore(tid); topics.restore(tid);
RDB.incr('totaltopiccount');
ThreadTools.unlock(tid, uid); ThreadTools.unlock(tid, uid);
io.sockets. in ('topic_' + tid).emit('event:topic_restored', { io.sockets. in ('topic_' + tid).emit('event:topic_restored', {
@ -118,16 +122,12 @@ var RDB = require('./redis.js'),
status: 'ok' status: 'ok'
}); });
if (socket) {
socket.emit('api:topic.restore', {
status: 'ok',
tid: tid
});
}
topics.getTopicField(tid, 'title', function(err, title) { topics.getTopicField(tid, 'title', function(err, title) {
topicSearch.index(title, tid); topicSearch.index(title, tid);
}); });
if(callback)
callback(null);
} }
}); });
} }

@ -493,6 +493,7 @@ module.exports.init = function(io) {
socket.on('api:topic.delete', function(data) { socket.on('api:topic.delete', function(data) {
threadTools.delete(data.tid, uid, function(err) { threadTools.delete(data.tid, uid, function(err) {
if (!err) { if (!err) {
posts.getTopicPostStats(socket);
socket.emit('api:topic.delete', { socket.emit('api:topic.delete', {
status: 'ok', status: 'ok',
tid: data.tid tid: data.tid
@ -502,7 +503,14 @@ module.exports.init = function(io) {
}); });
socket.on('api:topic.restore', function(data) { socket.on('api:topic.restore', function(data) {
threadTools.restore(data.tid, uid, socket); threadTools.restore(data.tid, uid, socket, function(err) {
posts.getTopicPostStats(socket);
socket.emit('api:topic.restore', {
status: 'ok',
tid: data.tid
});
});
}); });
socket.on('api:topic.lock', function(data) { socket.on('api:topic.lock', function(data) {
@ -555,11 +563,15 @@ module.exports.init = function(io) {
}); });
socket.on('api:posts.delete', function(data) { socket.on('api:posts.delete', function(data) {
postTools.delete(uid, data.pid); postTools.delete(uid, data.pid, function() {
posts.getTopicPostStats(socket);
});
}); });
socket.on('api:posts.restore', function(data) { socket.on('api:posts.restore', function(data) {
postTools.restore(uid, data.pid); postTools.restore(uid, data.pid, function() {
posts.getTopicPostStats(socket);
});
}); });
socket.on('api:notifications.get', function(data, callback) { socket.on('api:notifications.get', function(data, callback) {

Loading…
Cancel
Save