|
|
@ -3,11 +3,12 @@ var posts = require('../posts'),
|
|
|
|
topics = require('../topics'),
|
|
|
|
topics = require('../topics'),
|
|
|
|
favourites = require('../favourites'),
|
|
|
|
favourites = require('../favourites'),
|
|
|
|
postTools = require('../postTools'),
|
|
|
|
postTools = require('../postTools'),
|
|
|
|
|
|
|
|
index = require('./index'),
|
|
|
|
|
|
|
|
|
|
|
|
SocketPosts = {};
|
|
|
|
SocketPosts = {};
|
|
|
|
|
|
|
|
|
|
|
|
SocketPosts.reply = function(socket, data, callback) {
|
|
|
|
SocketPosts.reply = function(socket, data, callback) {
|
|
|
|
if (socket.uid < 1 && parseInt(meta.config.allowGuestPosting, 10) === 0) {
|
|
|
|
if (!socket.uid && !parseInt(meta.config.allowGuestPosting, 10)) {
|
|
|
|
socket.emit('event:alert', {
|
|
|
|
socket.emit('event:alert', {
|
|
|
|
title: 'Reply Unsuccessful',
|
|
|
|
title: 'Reply Unsuccessful',
|
|
|
|
message: 'You don't seem to be logged in, so you cannot reply.',
|
|
|
|
message: 'You don't seem to be logged in, so you cannot reply.',
|
|
|
@ -17,6 +18,10 @@ SocketPosts.reply = function(socket, data, callback) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!data || !data.topic_id || !data.content) {
|
|
|
|
|
|
|
|
return callback(new Error('invalid data'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
topics.reply(data.topic_id, socket.uid, data.content, function(err, postData) {
|
|
|
|
topics.reply(data.topic_id, socket.uid, data.content, function(err, postData) {
|
|
|
|
if(err) {
|
|
|
|
if(err) {
|
|
|
|
if (err.message === 'content-too-short') {
|
|
|
|
if (err.message === 'content-too-short') {
|
|
|
@ -38,7 +43,7 @@ SocketPosts.reply = function(socket, data, callback) {
|
|
|
|
timeout: 7500
|
|
|
|
timeout: 7500
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
return callback(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (postData) {
|
|
|
|
if (postData) {
|
|
|
@ -54,37 +59,40 @@ SocketPosts.reply = function(socket, data, callback) {
|
|
|
|
var socketData = {
|
|
|
|
var socketData = {
|
|
|
|
posts: [postData]
|
|
|
|
posts: [postData]
|
|
|
|
};
|
|
|
|
};
|
|
|
|
socket.server.sockets.in('topic_' + postData.tid).emit('event:new_post', socketData);
|
|
|
|
index.server.sockets.in('topic_' + postData.tid).emit('event:new_post', socketData);
|
|
|
|
socket.server.sockets.in('recent_posts').emit('event:new_post', socketData);
|
|
|
|
index.server.sockets.in('recent_posts').emit('event:new_post', socketData);
|
|
|
|
socket.server.sockets.in('user/' + postData.uid).emit('event:new_post', socketData);
|
|
|
|
index.server.sockets.in('user/' + postData.uid).emit('event:new_post', socketData);
|
|
|
|
callback();
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
SocketPosts.favourite = function(socket, data) {
|
|
|
|
SocketPosts.favourite = function(socket, data) {
|
|
|
|
|
|
|
|
if(data && data.pid && data.room_id) {
|
|
|
|
favourites.favourite(data.pid, data.room_id, socket.uid, socket);
|
|
|
|
favourites.favourite(data.pid, data.room_id, socket.uid, socket);
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
SocketPosts.unfavourite = function(socket, data) {
|
|
|
|
SocketPosts.unfavourite = function(socket, data) {
|
|
|
|
|
|
|
|
if(data && data.pid && data.room_id) {
|
|
|
|
favourites.unfavourite(data.pid, data.room_id, socket.uid, socket);
|
|
|
|
favourites.unfavourite(data.pid, data.room_id, socket.uid, socket);
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
SocketPosts.uploadImage = function(socket, data, callback) {
|
|
|
|
SocketPosts.uploadImage = function(socket, data, callback) {
|
|
|
|
|
|
|
|
if(data) {
|
|
|
|
posts.uploadPostImage(data, callback);
|
|
|
|
posts.uploadPostImage(data, callback);
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
SocketPosts.uploadFile = function(socket, data, callback) {
|
|
|
|
SocketPosts.uploadFile = function(socket, data, callback) {
|
|
|
|
|
|
|
|
if(data) {
|
|
|
|
posts.uploadPostFile(data, callback);
|
|
|
|
posts.uploadPostFile(data, callback);
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
SocketPosts.getRawPost = function(socket, data, callback) {
|
|
|
|
SocketPosts.getRawPost = function(socket, pid, callback) {
|
|
|
|
posts.getPostField(data.pid, 'content', function(err, raw) {
|
|
|
|
posts.getPostField(pid, 'content', callback);
|
|
|
|
callback({
|
|
|
|
|
|
|
|
post: raw
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
SocketPosts.edit = function(socket, data, callback) {
|
|
|
|
SocketPosts.edit = function(socket, data, callback) {
|
|
|
@ -96,6 +104,8 @@ SocketPosts.edit = function(socket, data, callback) {
|
|
|
|
timeout: 2000
|
|
|
|
timeout: 2000
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
} else if(!data || !data.pid || !data.title || !data.content) {
|
|
|
|
|
|
|
|
return callback(new Error('invalid data'));
|
|
|
|
} else if (!data.title || data.title.length < parseInt(meta.config.minimumTitleLength, 10)) {
|
|
|
|
} else if (!data.title || data.title.length < parseInt(meta.config.minimumTitleLength, 10)) {
|
|
|
|
topics.emitTitleTooShortAlert(socket);
|
|
|
|
topics.emitTitleTooShortAlert(socket);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -104,11 +114,15 @@ SocketPosts.edit = function(socket, data, callback) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
postTools.edit(socket.uid, data.pid, data.title, data.content, data.images);
|
|
|
|
postTools.edit(socket.uid, data.pid, data.title, data.content);
|
|
|
|
callback();
|
|
|
|
callback();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
SocketPosts.delete = function(socket, data, callback) {
|
|
|
|
SocketPosts.delete = function(socket, data, callback) {
|
|
|
|
|
|
|
|
if(!data) {
|
|
|
|
|
|
|
|
return callback(new Error('invalid data'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
postTools.delete(socket.uid, data.pid, function(err) {
|
|
|
|
postTools.delete(socket.uid, data.pid, function(err) {
|
|
|
|
|
|
|
|
|
|
|
|
if(err) {
|
|
|
|
if(err) {
|
|
|
@ -117,14 +131,18 @@ SocketPosts.delete = function(socket, data, callback) {
|
|
|
|
|
|
|
|
|
|
|
|
module.parent.exports.emitTopicPostStats();
|
|
|
|
module.parent.exports.emitTopicPostStats();
|
|
|
|
|
|
|
|
|
|
|
|
socket.server.sockets.in('topic_' + data.tid).emit('event:post_deleted', {
|
|
|
|
index.server.sockets.in('topic_' + data.tid).emit('event:post_deleted', {
|
|
|
|
pid: data.pid
|
|
|
|
pid: data.pid
|
|
|
|
});
|
|
|
|
});
|
|
|
|
callback(null);
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
SocketPosts.restore = function(socket, data, callback) {
|
|
|
|
SocketPosts.restore = function(socket, data, callback) {
|
|
|
|
|
|
|
|
if(!data) {
|
|
|
|
|
|
|
|
return callback(new Error('invalid data'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
postTools.restore(socket.uid, data.pid, function(err) {
|
|
|
|
postTools.restore(socket.uid, data.pid, function(err) {
|
|
|
|
if(err) {
|
|
|
|
if(err) {
|
|
|
|
return callback(err);
|
|
|
|
return callback(err);
|
|
|
@ -132,17 +150,21 @@ SocketPosts.restore = function(socket, data, callback) {
|
|
|
|
|
|
|
|
|
|
|
|
module.parent.exports.emitTopicPostStats();
|
|
|
|
module.parent.exports.emitTopicPostStats();
|
|
|
|
|
|
|
|
|
|
|
|
socket.server.sockets.in('topic_' + data.tid).emit('event:post_restored', {
|
|
|
|
index.server.sockets.in('topic_' + data.tid).emit('event:post_restored', {
|
|
|
|
pid: data.pid
|
|
|
|
pid: data.pid
|
|
|
|
});
|
|
|
|
});
|
|
|
|
callback(null);
|
|
|
|
|
|
|
|
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
SocketPosts.getPrivileges = function(socket, pid, callback) {
|
|
|
|
SocketPosts.getPrivileges = function(socket, pid, callback) {
|
|
|
|
postTools.privileges(pid, socket.uid, function(privileges) {
|
|
|
|
postTools.privileges(pid, socket.uid, function(err, privileges) {
|
|
|
|
|
|
|
|
if(err) {
|
|
|
|
|
|
|
|
return callback(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
privileges.pid = parseInt(pid);
|
|
|
|
privileges.pid = parseInt(pid);
|
|
|
|
callback(privileges);
|
|
|
|
callback(null, privileges);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|