Node.js based forum software built for the modern web
some work on deleting posts, and allowing a mod to edit a post
Julian Lam4fd1244e2d27
diff --git a/public/css/style.less b/public/css/style.lessindex 9b7ddeac40..4aeedd53ba 100644--- a/public/css/style.less+++ b/public/css/style.less@@ -201,8 +201,14 @@ footer.footer {text-align: center;font-size: 12px;}+li {padding-bottom: 15px;++ &.deleted {+ -moz-opacity: 0.30;+ opacity: 0.30;+ }}.profile-block, .post-block {diff --git a/public/templates/topic.tpl b/public/templates/topic.tplindex dd626e72a7..63c4771783 100644--- a/public/templates/topic.tpl+++ b/public/templates/topic.tpl@@ -9,7 +9,7 @@<ul id="post-container" class="post-container container"><!-- BEGIN posts -->-<li class="row">+<li class="row {posts.deleted-class}"><div class="span1 profile-image-block visible-desktop"><!--<i class="icon-spinner icon-spin icon-2x pull-left"></i>--><a href="/users/{posts.username}">@@ -218,15 +218,19 @@});$('.post-container').delegate('.delete', 'click', function(e) {- var pid = ($(this).attr('id') || $(this.parentNode).attr('id')).split('_')[1];- alert('delete clicked post id '+pid);+ var pid = ($(this).attr('id') || $(this.parentNode).attr('id')).split('_')[1];+ confirmDel = confirm('Delete this post?');++ if (confirmDel) {+ socket.emit('api:posts.delete', { pid: pid });+ }});ajaxify.register_events(['event:rep_up', 'event:rep_down', 'event:new_post', 'api:get_users_in_room','event:topic_deleted', 'event:topic_restored', 'event:topic:locked','event:topic_unlocked', 'event:topic_pinned', 'event:topic_unpinned',- 'event:topic_moved', 'event:post_edited'+ 'event:topic_moved', 'event:post_edited', 'event:post_deleted', 'event:post_restored']);socket.on('api:get_users_in_room', function(users) {var anonymous = users.anonymous,@@ -315,6 +319,11 @@});});+ socket.on('event:post_deleted', function(data) {+ console.log(data);+ if (data.pid) set_post_delete_state(data.pid, true);+ });+function adjust_rep(value, pid, uid) {var post_rep = jQuery('.post_rep_' + pid),user_rep = jQuery('.user_rep_' + uid);@@ -485,5 +494,9 @@thread_state.pinned = '0';}}++ function set_post_delete_state(pid, deleted) {+ console.log('SETTING DELETE STATE: ', pid, deleted);+ }})();</script>\ No newline at end of filediff --git a/src/posts.js b/src/posts.jsindex 5a20f67b38..2cd4b5d08e 100644--- a/src/posts.js+++ b/src/posts.js@@ -43,7 +43,8 @@ marked.setOptions({'display_moderator_tools': (uid == current_user || viewer_data.reputation >= config.privilege_thresholds.manage_content) ? 'show' : 'none','edited-class': post_data.editor[i] !== null ? '' : 'none','editor': post_data.editor[i] !== null ? user_data[post_data.editor[i]].username : '',- 'relativeEditTime': post_data.editTime !== null ? utils.relativeTime(post_data.editTime[i]) : ''+ 'relativeEditTime': post_data.editTime !== null ? utils.relativeTime(post_data.editTime[i]) : '',+ 'deleted-class': post_data.deleted[i] === '1' ? 'deleted' : ''});}@@ -65,7 +66,7 @@ marked.setOptions({RDB.lrange('tid:' + tid + ':posts', start, end, function(err, pids) {RDB.handle(err);- var content = [], uid = [], timestamp = [], pid = [], post_rep = [], editor = [], editTime = [];+ var content = [], uid = [], timestamp = [], pid = [], post_rep = [], editor = [], editTime = [], deleted = [];for (var i=0, ii=pids.length; i<ii; i++) {content.push('pid:' + pids[i] + ':content');@@ -74,6 +75,7 @@ marked.setOptions({post_rep.push('pid:' + pids[i] + ':rep');editor.push('pid:' + pids[i] + ':editor');editTime.push('pid:' + pids[i] + ':edited');+ deleted.push('pid:' + pids[i] + ':deleted');pid.push(pids[i]);}@@ -95,6 +97,7 @@ marked.setOptions({.get('tid:' + tid + ':pinned').mget(editor).mget(editTime)+ .mget(deleted).exec(function(err, replies) {post_data = {pid: pids,@@ -103,7 +106,8 @@ marked.setOptions({timestamp: replies[2],reputation: replies[3],editor: replies[10],- editTime: replies[11]+ editTime: replies[11],+ deleted: replies[12]};thread_data = {@@ -291,19 +295,40 @@ marked.setOptions({Posts.edit = function(uid, pid, content) {RDB.mget(['pid:' + pid + ':tid', 'pid:' + pid + ':uid'], function(err, results) {var tid = results[0],- author = results[1];+ author = results[1],+ success = function() {+ RDB.set('pid:' + pid + ':content', content);+ RDB.set('pid:' + pid + ':edited', new Date().getTime());+ RDB.set('pid:' + pid + ':editor', uid);- 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 || '') });+ };- io.sockets.in('topic_' + tid).emit('event:post_edited', { pid: pid, content: marked(content || '') });+ if (uid === author) success();+ else {+ user.getUserField(uid, 'reputation', function(reputation) {+ if (reputation >= config.privilege_thresholds.manage_content) success();+ });}});}Posts.delete = function(uid, pid) {- return 'elephants';+ RDB.mget(['pid:' + pid + ':tid', 'pid:' + pid + ':uid'], function(err, results) {+ var tid = results[0],+ author = results[1],+ success = function() {+ RDB.set('pid:' + pid + ':deleted', 1);++ io.sockets.in('topic_' + tid).emit('event:post_deleted', { pid: pid });+ };++ if (uid === author) success();+ else {+ user.getUserField(uid, 'reputation', function(reputation) {+ if (reputation >= config.privilege_thresholds.manage_content) success();+ });+ }+ });}}(exports));\ No newline at end of filediff --git a/src/websockets.js b/src/websockets.jsindex a0dacd9bcf..e2fdfa0a62 100644--- a/src/websockets.js+++ b/src/websockets.js@@ -222,6 +222,14 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),socket.on('api:posts.edit', function(data) {modules.posts.edit(uid, data.pid, data.content);});++ socket.on('api:posts.delete', function(data) {+ modules.posts.delete(uid, data.pid);+ });++ socket.on('api:posts.restore', function(data) {+ modules.posts.restore(uid, data.pid);+ });});}(SocketIO));