moved postTools and threadTools into posts/ and topics/

This commit is contained in:
barisusakli
2015-09-17 14:58:58 -04:00
parent 19a0e1cf54
commit 0c6495de72
6 changed files with 56 additions and 57 deletions

View File

@@ -11,7 +11,6 @@ var async = require('async'),
meta = require('../meta'),
topics = require('../topics'),
favourites = require('../favourites'),
postTools = require('../postTools'),
notifications = require('../notifications'),
groups = require('../groups'),
user = require('../user'),
@@ -346,28 +345,27 @@ SocketPosts.edit = function(socket, data, callback) {
};
SocketPosts.delete = function(socket, data, callback) {
deleteOrRestore('delete', socket, data, callback);
doPostAction('delete', 'event:post_deleted', socket, data, callback);
};
SocketPosts.restore = function(socket, data, callback) {
deleteOrRestore('restore', socket, data, callback);
doPostAction('restore', 'event:post_restored', socket, data, callback);
};
function deleteOrRestore(command, socket, data, callback) {
function doPostAction(command, eventName, socket, data, callback) {
if (!data) {
return callback(new Error('[[error:invalid-data]]'));
}
postTools[command](socket.uid, data.pid, function(err, postData) {
posts.tools[command](socket.uid, data.pid, function(err, postData) {
if (err) {
return callback(err);
}
var eventName = command === 'delete' ? 'event:post_deleted' : 'event:post_restored';
websockets.in('topic_' + data.tid).emit(eventName, postData);
events.log({
type: command === 'delete' ? 'post-delete' : 'post-restore',
type: 'post-' + command,
uid: socket.uid,
pid: data.pid,
ip: socket.ip
@@ -379,7 +377,7 @@ function deleteOrRestore(command, socket, data, callback) {
SocketPosts.purge = function(socket, data, callback) {
function purgePost() {
postTools.purge(socket.uid, data.pid, function(err) {
posts.tools.purge(socket.uid, data.pid, function(err) {
if (err) {
return callback(err);
}

View File

@@ -10,7 +10,6 @@ var nconf = require('nconf'),
privileges = require('../privileges'),
plugins = require('../plugins'),
notifications = require('../notifications'),
threadTools = require('../threadTools'),
websockets = require('./index'),
user = require('../user'),
db = require('../database'),
@@ -239,12 +238,12 @@ SocketTopics.doTopicAction = function(action, event, socket, data, callback) {
return callback(new Error('[[error:invalid-tid]]'));
}
if (typeof threadTools[action] !== 'function') {
if (typeof topics.tools[action] !== 'function') {
return callback();
}
async.each(data.tids, function(tid, next) {
threadTools[action](tid, socket.uid, function(err, data) {
topics.tools[action](tid, socket.uid, function(err, data) {
if (err) {
return next(err);
}
@@ -330,7 +329,7 @@ SocketTopics.move = function(socket, data, callback) {
function(_topicData, next) {
topicData = _topicData;
topicData.tid = tid;
threadTools.move(tid, data.cid, socket.uid, next);
topics.tools.move(tid, data.cid, socket.uid, next);
}
], function(err) {
if(err) {
@@ -392,7 +391,7 @@ SocketTopics.moveAll = function(socket, data, callback) {
}
async.eachLimit(tids, 10, function(tid, next) {
threadTools.move(tid, data.cid, socket.uid, next);
topics.tools.move(tid, data.cid, socket.uid, next);
}, callback);
});
});