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

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

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

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

@ -368,41 +368,41 @@ var db = require('./database'),
Posts.uploadPostImage = function(image, callback) {
if(meta.config.imgurClientID) {
if(!image) {
if(!image || !image.data) {
return callback('invalid image', null);
}
require('./imgur').upload(meta.config.imgurClientID, image.data, 'base64', function(err, data) {
if(err) {
callback(err.message, null);
} else {
return callback(err);
}
callback(null, {
url: data.link,
name: image.name
});
}
});
} else if (meta.config.allowFileUploads) {
Posts.uploadPostFile(image, callback);
} else {
callback('Uploads are disabled!');
callback(new Error('Uploads are disabled!'));
}
}
Posts.uploadPostFile = function(file, callback) {
if(!meta.config.allowFileUploads) {
return callback('File uploads are not allowed');
return callback(new Error('File uploads are not allowed'));
}
if(!file) {
return callback('invalid file');
if(!file || !file.data) {
return callback(new Error('invalid file'));
}
var buffer = new Buffer(file.data, 'base64');
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);
@ -410,13 +410,13 @@ var db = require('./database'),
fs.writeFile(uploadPath, buffer, function (err) {
if(err) {
callback(err.message, null);
} else {
return callback(err);
}
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) {
postTools.privileges(pid, 0, function(privileges) {
postTools.privileges(pid, 0, function(err, privileges) {
next(privileges.read);
});
}, function(pids) {

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

@ -3,11 +3,12 @@ var posts = require('../posts'),
topics = require('../topics'),
favourites = require('../favourites'),
postTools = require('../postTools'),
index = require('./index'),
SocketPosts = {};
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', {
title: 'Reply Unsuccessful',
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;
}
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) {
if(err) {
if (err.message === 'content-too-short') {
@ -38,7 +43,7 @@ SocketPosts.reply = function(socket, data, callback) {
timeout: 7500
});
}
return;
return callback(err);
}
if (postData) {
@ -54,37 +59,40 @@ SocketPosts.reply = function(socket, data, callback) {
var socketData = {
posts: [postData]
};
socket.server.sockets.in('topic_' + postData.tid).emit('event:new_post', socketData);
socket.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('topic_' + postData.tid).emit('event:new_post', socketData);
index.server.sockets.in('recent_posts').emit('event:new_post', socketData);
index.server.sockets.in('user/' + postData.uid).emit('event:new_post', socketData);
callback();
}
});
};
SocketPosts.favourite = function(socket, data) {
if(data && data.pid && data.room_id) {
favourites.favourite(data.pid, data.room_id, socket.uid, socket);
}
};
SocketPosts.unfavourite = function(socket, data) {
if(data && data.pid && data.room_id) {
favourites.unfavourite(data.pid, data.room_id, socket.uid, socket);
}
};
SocketPosts.uploadImage = function(socket, data, callback) {
if(data) {
posts.uploadPostImage(data, callback);
}
};
SocketPosts.uploadFile = function(socket, data, callback) {
if(data) {
posts.uploadPostFile(data, callback);
}
};
SocketPosts.getRawPost = function(socket, data, callback) {
posts.getPostField(data.pid, 'content', function(err, raw) {
callback({
post: raw
});
});
SocketPosts.getRawPost = function(socket, pid, callback) {
posts.getPostField(pid, 'content', callback);
};
SocketPosts.edit = function(socket, data, callback) {
@ -96,6 +104,8 @@ SocketPosts.edit = function(socket, data, callback) {
timeout: 2000
});
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)) {
topics.emitTitleTooShortAlert(socket);
return;
@ -104,11 +114,15 @@ SocketPosts.edit = function(socket, data, callback) {
return;
}
postTools.edit(socket.uid, data.pid, data.title, data.content, data.images);
postTools.edit(socket.uid, data.pid, data.title, data.content);
callback();
};
SocketPosts.delete = function(socket, data, callback) {
if(!data) {
return callback(new Error('invalid data'));
}
postTools.delete(socket.uid, data.pid, function(err) {
if(err) {
@ -117,14 +131,18 @@ SocketPosts.delete = function(socket, data, callback) {
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
});
callback(null);
callback();
});
};
SocketPosts.restore = function(socket, data, callback) {
if(!data) {
return callback(new Error('invalid data'));
}
postTools.restore(socket.uid, data.pid, function(err) {
if(err) {
return callback(err);
@ -132,17 +150,21 @@ SocketPosts.restore = function(socket, data, callback) {
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
});
callback(null);
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);
callback(privileges);
callback(null, privileges);
});
};

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

Loading…
Cancel
Save