You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
912 B
JavaScript
37 lines
912 B
JavaScript
'use strict';
|
|
|
|
var async = require('async');
|
|
var privileges = require('../../privileges');
|
|
var topics = require('../../topics');
|
|
var socketHelpers = require('../helpers');
|
|
|
|
module.exports = function (SocketPosts) {
|
|
|
|
SocketPosts.movePost = function (socket, data, callback) {
|
|
if (!socket.uid) {
|
|
return callback(new Error('[[error:not-logged-in]]'));
|
|
}
|
|
|
|
if (!data || !data.pid || !data.tid) {
|
|
return callback(new Error('[[error:invalid-data]]'));
|
|
}
|
|
|
|
async.waterfall([
|
|
function (next) {
|
|
privileges.posts.canMove(data.pid, socket.uid, next);
|
|
},
|
|
function (canMove, next) {
|
|
if (!canMove) {
|
|
return next(new Error('[[error:no-privileges]]'));
|
|
}
|
|
|
|
topics.movePostToTopic(data.pid, data.tid, next);
|
|
},
|
|
function (next) {
|
|
socketHelpers.sendNotificationToPostOwner(data.pid, socket.uid, 'move', 'notifications:moved_your_post');
|
|
next();
|
|
}
|
|
], callback);
|
|
};
|
|
|
|
}; |