mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
some work on deleting posts, and allowing a mod to edit a post
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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}">
|
||||
@@ -219,14 +219,18 @@
|
||||
|
||||
$('.post-container').delegate('.delete', 'click', function(e) {
|
||||
var pid = ($(this).attr('id') || $(this.parentNode).attr('id')).split('_')[1];
|
||||
alert('delete clicked post id '+pid);
|
||||
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>
|
||||
39
src/posts.js
39
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];
|
||||
|
||||
if (uid === author) {
|
||||
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);
|
||||
|
||||
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));
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user