migrating posts to new socketAL format

v1.18.x
Julian Lam 11 years ago
parent 35aa06c230
commit 42d6880ac4

@ -6,9 +6,9 @@ var posts = require('../posts'),
SocketPosts = {}; SocketPosts = {};
SocketPosts.reply = function(data, callback, sessionData) { SocketPosts.reply = function(socket, data, callback) {
if (sessionData.uid < 1 && parseInt(meta.config.allowGuestPosting, 10) === 0) { if (socket.uid < 1 && parseInt(meta.config.allowGuestPosting, 10) === 0) {
sessionData.socket.emit('event:alert', { socket.emit('event:alert', {
title: 'Reply Unsuccessful', title: 'Reply Unsuccessful',
message: 'You don&apos;t seem to be logged in, so you cannot reply.', message: 'You don&apos;t seem to be logged in, so you cannot reply.',
type: 'danger', type: 'danger',
@ -17,21 +17,21 @@ SocketPosts.reply = function(data, callback, sessionData) {
return; return;
} }
topics.reply(data.topic_id, sessionData.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') {
module.parent.exports.emitContentTooShortAlert(sessionData.socket); module.parent.exports.emitContentTooShortAlert(socket);
} else if (err.message === 'too-many-posts') { } else if (err.message === 'too-many-posts') {
module.parent.exports.emitTooManyPostsAlert(sessionData.socket); module.parent.exports.emitTooManyPostsAlert(socket);
} else if (err.message === 'reply-error') { } else if (err.message === 'reply-error') {
sessionData.socket.emit('event:alert', { socket.emit('event:alert', {
title: 'Reply Unsuccessful', title: 'Reply Unsuccessful',
message: 'Your reply could not be posted at this time. Please try again later.', message: 'Your reply could not be posted at this time. Please try again later.',
type: 'warning', type: 'warning',
timeout: 2000 timeout: 2000
}); });
} else if (err.message === 'no-privileges') { } else if (err.message === 'no-privileges') {
sessionData.socket.emit('event:alert', { socket.emit('event:alert', {
title: 'Unable to post', title: 'Unable to post',
message: 'You do not have posting privileges in this category.', message: 'You do not have posting privileges in this category.',
type: 'danger', type: 'danger',
@ -45,7 +45,7 @@ SocketPosts.reply = function(data, callback, sessionData) {
module.parent.exports.emitTopicPostStats(); module.parent.exports.emitTopicPostStats();
sessionData.socket.emit('event:alert', { socket.emit('event:alert', {
title: 'Reply Successful', title: 'Reply Successful',
message: 'You have successfully replied. Click here to view your reply.', message: 'You have successfully replied. Click here to view your reply.',
type: 'success', type: 'success',
@ -54,32 +54,32 @@ SocketPosts.reply = function(data, callback, sessionData) {
var socketData = { var socketData = {
posts: [postData] posts: [postData]
}; };
sessionData.server.sockets.in('topic_' + postData.tid).emit('event:new_post', socketData); socket.server.sockets.in('topic_' + postData.tid).emit('event:new_post', socketData);
sessionData.server.sockets.in('recent_posts').emit('event:new_post', socketData); socket.server.sockets.in('recent_posts').emit('event:new_post', socketData);
sessionData.server.sockets.in('user/' + postData.uid).emit('event:new_post', socketData); socket.server.sockets.in('user/' + postData.uid).emit('event:new_post', socketData);
callback(); callback();
} }
}); });
}; };
SocketPosts.favourite = function(data, sessionData) { SocketPosts.favourite = function(socket, data) {
favourites.favourite(data.pid, data.room_id, sessionData.uid, sessionData.socket); favourites.favourite(data.pid, data.room_id, socket.uid, socket);
}; };
SocketPosts.unfavourite = function(data, sessionData) { SocketPosts.unfavourite = function(socket, data) {
favourites.unfavourite(data.pid, data.room_id, sessionData.uid, sessionData.socket); favourites.unfavourite(data.pid, data.room_id, socket.uid, socket);
}; };
SocketPosts.uploadImage = function(data, callback) { SocketPosts.uploadImage = function(socket, data, callback) {
posts.uploadPostImage(data, callback); posts.uploadPostImage(data, callback);
}; };
SocketPosts.uploadFile = function(data, callback) { SocketPosts.uploadFile = function(socket, data, callback) {
posts.uploadPostFile(data, callback); posts.uploadPostFile(data, callback);
}; };
SocketPosts.getRawPost = function(data, callback) { SocketPosts.getRawPost = function(socket, data, callback) {
posts.getPostField(data.pid, 'content', function(err, raw) { posts.getPostField(data.pid, 'content', function(err, raw) {
callback({ callback({
post: raw post: raw
@ -87,9 +87,9 @@ SocketPosts.getRawPost = function(data, callback) {
}); });
}; };
SocketPosts.edit = function(data, callback, sessionData) { SocketPosts.edit = function(socket, data, callback) {
if(!sessionData.uid) { if(!socket.uid) {
sessionData.socket.emit('event:alert', { socket.emit('event:alert', {
title: 'Can&apos;t edit', title: 'Can&apos;t edit',
message: 'Guests can&apos;t edit posts!', message: 'Guests can&apos;t edit posts!',
type: 'warning', type: 'warning',
@ -97,19 +97,19 @@ SocketPosts.edit = function(data, callback, sessionData) {
}); });
return; return;
} 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(sessionData.socket); topics.emitTitleTooShortAlert(socket);
return; return;
} else if (!data.content || data.content.length < parseInt(meta.config.minimumPostLength, 10)) { } else if (!data.content || data.content.length < parseInt(meta.config.minimumPostLength, 10)) {
module.parent.exports.emitContentTooShortAlert(sessionData.socket); module.parent.exports.emitContentTooShortAlert(socket);
return; return;
} }
postTools.edit(sessionData.uid, data.pid, data.title, data.content, data.images); postTools.edit(socket.uid, data.pid, data.title, data.content, data.images);
callback(); callback();
}; };
SocketPosts.delete = function(data, callback, sessionData) { SocketPosts.delete = function(socket, data, callback) {
postTools.delete(sessionData.uid, data.pid, function(err) { postTools.delete(socket.uid, data.pid, function(err) {
if(err) { if(err) {
return callback(err); return callback(err);
@ -117,30 +117,30 @@ SocketPosts.delete = function(data, callback, sessionData) {
module.parent.exports.emitTopicPostStats(); module.parent.exports.emitTopicPostStats();
sessionData.server.sockets.in('topic_' + data.tid).emit('event:post_deleted', { socket.server.sockets.in('topic_' + data.tid).emit('event:post_deleted', {
pid: data.pid pid: data.pid
}); });
callback(null); callback(null);
}); });
}; };
SocketPosts.restore = function(data, callback, sessionData) { SocketPosts.restore = function(socket, data, callback) {
postTools.restore(sessionData.uid, data.pid, function(err) { postTools.restore(socket.uid, data.pid, function(err) {
if(err) { if(err) {
return callback(err); return callback(err);
} }
module.parent.exports.emitTopicPostStats(); module.parent.exports.emitTopicPostStats();
sessionData.server.sockets.in('topic_' + data.tid).emit('event:post_restored', { socket.server.sockets.in('topic_' + data.tid).emit('event:post_restored', {
pid: data.pid pid: data.pid
}); });
callback(null); callback(null);
}); });
}; };
SocketPosts.getPrivileges = function(pid, callback, sessionData) { SocketPosts.getPrivileges = function(socket, pid, callback) {
postTools.privileges(pid, sessionData.uid, function(privileges) { postTools.privileges(pid, socket.uid, function(privileges) {
privileges.pid = parseInt(pid); privileges.pid = parseInt(pid);
callback(privileges); callback(privileges);
}); });

Loading…
Cancel
Save