more post fixes

v1.18.x
Baris Soner Usakli 11 years ago
parent 9e6f7fa960
commit b3816b98a1

@ -367,9 +367,14 @@ define(['composer'], function(composer) {
username = '@' + post.attr('data-username'); username = '@' + post.attr('data-username');
} }
socket.emit('posts.getRawPost', {pid: pid}, function(data) { socket.emit('posts.getRawPost', pid, function(err, post) {
if(err) {
quoted = '> ' + data.post.replace(/\n/g, '\n> ') + '\n\n'; return app.alert(err.message);
}
var quoted = '';
if(post) {
quoted = '> ' + post.replace(/\n/g, '\n> ') + '\n\n';
}
composer.newReply(tid, topic_name, username + ' said:\n' + quoted); composer.newReply(tid, topic_name, username + ' said:\n' + quoted);
}); });
@ -428,30 +433,20 @@ define(['composer'], function(composer) {
$('#post-container').on('click', '.delete', function(e) { $('#post-container').on('click', '.delete', function(e) {
var pid = $(this).parents('li').attr('data-pid'), var pid = $(this).parents('li').attr('data-pid'),
postEl = $(document.querySelector('#post-container li[data-pid="' + pid + '"]')), postEl = $(document.querySelector('#post-container li[data-pid="' + pid + '"]')),
deleteAction = !postEl.hasClass('deleted') ? true : false, action = !postEl.hasClass('deleted') ? 'delete' : 'restore';
confirmDel = confirm((deleteAction ? 'Delete' : 'Restore') + ' this post?');
if (confirmDel) { bootbox.confirm('Are you sure you want to ' + action + ' this post?', function(confirm) {
if(deleteAction) { if (confirm) {
socket.emit('posts.delete', { socket.emit('posts.' + action, {
pid: pid,
tid: tid
}, function(err) {
if(err) {
return app.alertError('Can\'t delete post!');
}
});
} else {
socket.emit('posts.restore', {
pid: pid, pid: pid,
tid: tid tid: tid
}, function(err) { }, function(err) {
if(err) { if(err) {
return app.alertError('Can\'t restore post!'); return app.alertError('Can\'t ' + action + ' post!');
} }
}); });
} }
} });
}); });
$('#post-container').on('click', '.move', function(e) { $('#post-container').on('click', '.move', function(e) {
@ -684,7 +679,7 @@ define(['composer'], function(composer) {
}); });
socket.on('posts.favourite', function(data) { socket.on('posts.favourite', function(data) {
if (data.status === 'ok' && data.pid) { if (data && data.pid) {
var favBtn = $('li[data-pid="' + data.pid + '"] .favourite'); var favBtn = $('li[data-pid="' + data.pid + '"] .favourite');
if(favBtn.length) { if(favBtn.length) {
favBtn.addClass('btn-warning') favBtn.addClass('btn-warning')
@ -695,7 +690,7 @@ define(['composer'], function(composer) {
}); });
socket.on('posts.unfavourite', function(data) { socket.on('posts.unfavourite', function(data) {
if (data.status === 'ok' && data.pid) { if (data && data.pid) {
var favBtn = $('li[data-pid="' + data.pid + '"] .favourite'); var favBtn = $('li[data-pid="' + data.pid + '"] .favourite');
if(favBtn.length) { if(favBtn.length) {
favBtn.removeClass('btn-warning') favBtn.removeClass('btn-warning')
@ -855,7 +850,11 @@ define(['composer'], function(composer) {
favEl = postEl.find('.favourite'), favEl = postEl.find('.favourite'),
replyEl = postEl.find('.post_reply'); replyEl = postEl.find('.post_reply');
socket.emit('posts.getPrivileges', pid, function(privileges) { socket.emit('posts.getPrivileges', pid, function(err, privileges) {
if(err) {
return app.alert(err.message);
}
if (privileges.editable) { if (privileges.editable) {
if (!postEl.hasClass('deleted')) { if (!postEl.hasClass('deleted')) {
toggle_post_tools(pid, false); toggle_post_tools(pid, false);

@ -45,9 +45,10 @@ define(['taskbar'], function(taskbar) {
composer.editPost = function(pid) { composer.editPost = function(pid) {
if(allowed()) { if(allowed()) {
socket.emit('modules.composer.push', { socket.emit('modules.composer.push', pid, function(err, threadData) {
pid: pid if(err) {
}, function(err, threadData) { return app.alertError(err.message);
}
push({ push({
pid: pid, pid: pid,
title: threadData.title, title: threadData.title,

@ -47,7 +47,6 @@ var db = require('./database'),
} }
socket.emit('posts.favourite', { socket.emit('posts.favourite', {
status: 'ok',
pid: pid pid: pid
}); });
} }
@ -84,7 +83,6 @@ var db = require('./database'),
} }
socket.emit('posts.unfavourite', { socket.emit('posts.unfavourite', {
status: 'ok',
pid: pid pid: pid
}); });
} }

@ -51,7 +51,11 @@ var winston = require('winston'),
} }
// [getThreadPrivileges, isOwnPost, hasEnoughRep] // [getThreadPrivileges, isOwnPost, hasEnoughRep]
}, function(err, results) { }, function(err, results) {
callback({ if(err) {
return callback(err);
}
callback(null, {
read: results.topicPrivs.read, read: results.topicPrivs.read,
editable: results.topicPrivs.editable || results.isOwner || results.hasEnoughRep, editable: results.topicPrivs.editable || results.isOwner || results.hasEnoughRep,
view_deleted: results.topicPrivs.view_deleted || results.isOwner || results.hasEnoughRep view_deleted: results.topicPrivs.view_deleted || results.isOwner || results.hasEnoughRep
@ -111,7 +115,7 @@ var winston = require('winston'),
}); });
}; };
PostTools.privileges(pid, uid, function(privileges) { PostTools.privileges(pid, uid, function(err, privileges) {
if (privileges.editable) { if (privileges.editable) {
plugins.fireHook('filter:post.save', content, function(err, parsedContent) { plugins.fireHook('filter:post.save', content, function(err, parsedContent) {
if (!err) content = parsedContent; if (!err) content = parsedContent;
@ -169,7 +173,7 @@ var winston = require('winston'),
return callback(new Error('Post already deleted!')); return callback(new Error('Post already deleted!'));
} }
PostTools.privileges(pid, uid, function(privileges) { PostTools.privileges(pid, uid, function(err, privileges) {
if (privileges.editable) { if (privileges.editable) {
success(); success();
} }
@ -223,7 +227,7 @@ var winston = require('winston'),
return callback(new Error('Post already restored')); return callback(new Error('Post already restored'));
} }
PostTools.privileges(pid, uid, function(privileges) { PostTools.privileges(pid, uid, function(err, privileges) {
if (privileges.editable) { if (privileges.editable) {
success(); success();
} }

@ -368,41 +368,41 @@ var db = require('./database'),
Posts.uploadPostImage = function(image, callback) { Posts.uploadPostImage = function(image, callback) {
if(meta.config.imgurClientID) { if(meta.config.imgurClientID) {
if(!image) { if(!image || !image.data) {
return callback('invalid image', null); return callback('invalid image', null);
} }
require('./imgur').upload(meta.config.imgurClientID, image.data, 'base64', function(err, data) { require('./imgur').upload(meta.config.imgurClientID, image.data, 'base64', function(err, data) {
if(err) { if(err) {
callback(err.message, null); return callback(err);
} else {
callback(null, {
url: data.link,
name: image.name
});
} }
callback(null, {
url: data.link,
name: image.name
});
}); });
} else if (meta.config.allowFileUploads) { } else if (meta.config.allowFileUploads) {
Posts.uploadPostFile(image, callback); Posts.uploadPostFile(image, callback);
} else { } else {
callback('Uploads are disabled!'); callback(new Error('Uploads are disabled!'));
} }
} }
Posts.uploadPostFile = function(file, callback) { Posts.uploadPostFile = function(file, callback) {
if(!meta.config.allowFileUploads) { if(!meta.config.allowFileUploads) {
return callback('File uploads are not allowed'); return callback(new Error('File uploads are not allowed'));
} }
if(!file) { if(!file || !file.data) {
return callback('invalid file'); return callback(new Error('invalid file'));
} }
var buffer = new Buffer(file.data, 'base64'); var buffer = new Buffer(file.data, 'base64');
if(buffer.length > parseInt(meta.config.maximumFileSize, 10) * 1024) { if(buffer.length > parseInt(meta.config.maximumFileSize, 10) * 1024) {
return callback('File too big'); return callback(new Error('File too big'));
} }
var filename = 'upload-' + utils.generateUUID() + path.extname(file.name); var filename = 'upload-' + utils.generateUUID() + path.extname(file.name);
@ -410,13 +410,13 @@ var db = require('./database'),
fs.writeFile(uploadPath, buffer, function (err) { fs.writeFile(uploadPath, buffer, function (err) {
if(err) { if(err) {
callback(err.message, null); return callback(err);
} else {
callback(null, {
url: nconf.get('upload_url') + filename,
name: file.name
});
} }
callback(null, {
url: nconf.get('upload_url') + filename,
name: file.name
});
}); });
} }
@ -427,7 +427,7 @@ var db = require('./database'),
} }
async.filter(pids, function(pid, next) { async.filter(pids, function(pid, next) {
postTools.privileges(pid, 0, function(privileges) { postTools.privileges(pid, 0, function(err, privileges) {
next(privileges.read); next(privileges.read);
}); });
}, function(pids) { }, function(pids) {

@ -19,31 +19,29 @@ var posts = require('../posts'),
SocketModules.composer = {}; SocketModules.composer = {};
SocketModules.composer.push = function(socket, data, callback) { SocketModules.composer.push = function(socket, pid, callback) {
if (parseInt(socket.uid, 10) > 0 || parseInt(meta.config.allowGuestPosting, 10) === 1) { if (socket.uid || parseInt(meta.config.allowGuestPosting, 10)) {
if (parseInt(data.pid, 10) > 0) { if (parseInt(pid, 10) > 0) {
async.parallel([ async.parallel([
function(next) { function(next) {
posts.getPostFields(data.pid, ['content'], next); posts.getPostFields(pid, ['content'], next);
}, },
function(next) { function(next) {
topics.getTitleByPid(data.pid, function(title) { topics.getTitleByPid(pid, function(title) {
next(null, title); next(null, title);
}); });
} }
], function(err, results) { ], function(err, results) {
callback(err, { callback(err, {
title: results[1], title: results[1],
pid: data.pid, pid: pid,
body: results[0].content body: results[0].content
}); });
}); });
} }
} else { } else {
callback(null, { callback(new Error('no-uid'));
error: 'no-uid'
});
} }
}; };

@ -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&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.',
@ -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) {
favourites.favourite(data.pid, data.room_id, socket.uid, socket); if(data && data.pid && data.room_id) {
favourites.favourite(data.pid, data.room_id, socket.uid, socket);
}
}; };
SocketPosts.unfavourite = function(socket, data) { SocketPosts.unfavourite = function(socket, data) {
favourites.unfavourite(data.pid, data.room_id, socket.uid, socket); if(data && data.pid && data.room_id) {
favourites.unfavourite(data.pid, data.room_id, socket.uid, socket);
}
}; };
SocketPosts.uploadImage = function(socket, data, callback) { SocketPosts.uploadImage = function(socket, data, callback) {
posts.uploadPostImage(data, callback); if(data) {
posts.uploadPostImage(data, callback);
}
}; };
SocketPosts.uploadFile = function(socket, data, callback) { SocketPosts.uploadFile = function(socket, data, callback) {
posts.uploadPostFile(data, callback); if(data) {
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);
}); });
}; };

@ -262,7 +262,7 @@ var async = require('async'),
}); });
function move(pid, next) { function move(pid, next) {
postTools.privileges(pid, uid, function(privileges) { postTools.privileges(pid, uid, function(err, privileges) {
if(privileges.editable) { if(privileges.editable) {
Topics.movePostToTopic(pid, tid, next); Topics.movePostToTopic(pid, tid, next);
} else { } else {
@ -384,9 +384,7 @@ var async = require('async'),
} }
function getPrivileges(next) { function getPrivileges(next) {
postTools.privileges(tid, current_user, function(privData) { postTools.privileges(tid, current_user, next);
next(null, privData);
});
} }
async.parallel([getFavouritesData, addUserInfoToPosts, getPrivileges], function(err, results) { async.parallel([getFavouritesData, addUserInfoToPosts, getPrivileges], function(err, results) {

Loading…
Cancel
Save