fixed editing

v1.18.x
Baris Usakli 12 years ago
parent bff188b116
commit 0c77db1f22

@ -24,23 +24,21 @@ marked.setOptions({
function getThreadPrivileges(next) { function getThreadPrivileges(next) {
posts.getPostField(pid, 'tid', function(tid) { posts.getPostField(pid, 'tid', function(tid) {
threadTools.privileges(tid, uid, function(privileges) { threadTools.privileges(tid, uid, function(privileges) {
next(null, privileges); next(null, privileges);
});
}); });
});
} }
function isOwnPost(next) { function isOwnPost(next) {
RDB.get('pid:' + pid + ':uid', function(err, author) { posts.getPostField(pid, 'uid', function(author) {
if (author && parseInt(author) > 0) { if (author && parseInt(author) > 0) {
next(null, author === uid); next(null, author === uid);
} }
}); });
} }
function hasEnoughRep(next) { function hasEnoughRep(next) {
// DRY fail in threadTools.
user.getUserField(uid, 'reputation', function(reputation) { user.getUserField(uid, 'reputation', function(reputation) {
next(null, reputation >= global.config['privileges:manage_content']); next(null, reputation >= global.config['privileges:manage_content']);
}); });
@ -55,12 +53,13 @@ marked.setOptions({
} }
PostTools.edit = function(uid, pid, title, content) { PostTools.edit = function(uid, pid, title, content) {
var success = function() { var success = function() {
posts.setPostField(pid, 'content', content); posts.setPostField(pid, 'content', content);
posts.setPostField(pid, 'edited', Date.now()); posts.setPostField(pid, 'edited', Date.now());
posts.setPostField(pid, 'editor', uid); posts.setPostField(pid, 'editor', uid);
posts.get_tid_by_pid(pid, function(tid) { posts.getPostField(pid, 'tid', function(tid) {
PostTools.isMain(pid, tid, function(isMainPost) { PostTools.isMain(pid, tid, function(isMainPost) {
if (isMainPost) if (isMainPost)
topics.setTopicField(tid, 'title', title); topics.setTopicField(tid, 'title', title);
@ -85,7 +84,7 @@ marked.setOptions({
var success = function() { var success = function() {
posts.setPostField(pid, 'deleted', 1); posts.setPostField(pid, 'deleted', 1);
posts.get_tid_by_pid(pid, function(tid) { posts.getPostField(pid, 'tid', function(tid) {
io.sockets.in('topic_' + tid).emit('event:post_deleted', { io.sockets.in('topic_' + tid).emit('event:post_deleted', {
pid: pid pid: pid
}); });
@ -103,7 +102,7 @@ marked.setOptions({
var success = function() { var success = function() {
RDB.del('pid:' + pid + ':deleted'); RDB.del('pid:' + pid + ':deleted');
posts.get_tid_by_pid(pid, function(tid) { posts.getPostField(pid, 'tid', function(tid) {
io.sockets.in('topic_' + tid).emit('event:post_restored', { io.sockets.in('topic_' + tid).emit('event:post_restored', {
pid: pid pid: pid
}); });

@ -19,8 +19,6 @@ var RDB = require('./redis.js'),
} }
function hasEnoughRep(next) { function hasEnoughRep(next) {
// DRY fail in postTools
user.getUserField(uid, 'reputation', function(reputation) { user.getUserField(uid, 'reputation', function(reputation) {
next(null, reputation >= global.config['privileges:manage_topic']); next(null, reputation >= global.config['privileges:manage_topic']);
}); });

@ -379,7 +379,7 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
}); });
socket.on('api:composer.editCheck', function(pid) { socket.on('api:composer.editCheck', function(pid) {
posts.get_tid_by_pid(pid, function(tid) { posts.getPostField(pid, 'tid', function(tid) {
postTools.isMain(pid, tid, function(isMain) { postTools.isMain(pid, tid, function(isMain) {
socket.emit('api:composer.editCheck', { socket.emit('api:composer.editCheck', {
titleEditable: isMain titleEditable: isMain

Loading…
Cancel
Save