From 11cc68ce8f5619fc0abcada56df686d5273c5841 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 10 May 2013 16:20:27 -0400 Subject: [PATCH] server-side srestruction to editing posts (though need to add rep of editor blah blah) --- src/posts.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/posts.js b/src/posts.js index 953b16e188..7dcba9131e 100644 --- a/src/posts.js +++ b/src/posts.js @@ -285,12 +285,21 @@ var RDB = require('./redis.js'), } Posts.edit = function(uid, pid, content) { - RDB.get('pid:' + pid + ':tid', function(err, tid) { - RDB.set('pid:' + pid + ':content', content); - RDB.set('pid:' + pid + ':edited', new Date().getTime()); - RDB.set('pid:' + pid + ':editor', uid); + RDB.mget(['pid:' + pid + ':tid', 'pid:' + pid + ':uid'], function(err, results) { + var tid = results[0], + author = results[1]; - io.sockets.in('topic_' + tid).emit('event:post_edited', { pid: pid, content: marked(content || '') }); + if (uid === author) { + RDB.set('pid:' + pid + ':content', content); + RDB.set('pid:' + pid + ':edited', new Date().getTime()); + RDB.set('pid:' + pid + ':editor', uid); + + io.sockets.in('topic_' + tid).emit('event:post_edited', { pid: pid, content: marked(content || '') }); + } }); } + + Posts.delete = function(uid, pid) { + return 'elephants'; + } }(exports)); \ No newline at end of file