diff --git a/src/postTools.js b/src/postTools.js index a2164bb5a6..14cbc60757 100644 --- a/src/postTools.js +++ b/src/postTools.js @@ -24,23 +24,21 @@ marked.setOptions({ function getThreadPrivileges(next) { posts.getPostField(pid, 'tid', function(tid) { - threadTools.privileges(tid, uid, function(privileges) { - next(null, privileges); - }); + threadTools.privileges(tid, uid, function(privileges) { + next(null, privileges); }); + }); } function isOwnPost(next) { - RDB.get('pid:' + pid + ':uid', function(err, author) { - if (author && parseInt(author) > 0) { - next(null, author === uid); - } - }); + posts.getPostField(pid, 'uid', function(author) { + if (author && parseInt(author) > 0) { + next(null, author === uid); + } + }); } function hasEnoughRep(next) { - // DRY fail in threadTools. - user.getUserField(uid, 'reputation', function(reputation) { next(null, reputation >= global.config['privileges:manage_content']); }); @@ -55,12 +53,13 @@ marked.setOptions({ } PostTools.edit = function(uid, pid, title, content) { + var success = function() { posts.setPostField(pid, 'content', content); posts.setPostField(pid, 'edited', Date.now()); 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) { if (isMainPost) topics.setTopicField(tid, 'title', title); @@ -85,7 +84,7 @@ marked.setOptions({ var success = function() { 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', { pid: pid }); @@ -103,7 +102,7 @@ marked.setOptions({ var success = function() { 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', { pid: pid }); diff --git a/src/threadTools.js b/src/threadTools.js index 65ea08faa3..a2268185b9 100644 --- a/src/threadTools.js +++ b/src/threadTools.js @@ -19,8 +19,6 @@ var RDB = require('./redis.js'), } function hasEnoughRep(next) { - // DRY fail in postTools - user.getUserField(uid, 'reputation', function(reputation) { next(null, reputation >= global.config['privileges:manage_topic']); }); diff --git a/src/websockets.js b/src/websockets.js index b3e40b6847..8d2ed1fe73 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -379,7 +379,7 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }), }); 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) { socket.emit('api:composer.editCheck', { titleEditable: isMain