mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-04 03:21:18 +01:00
topic locking and deletion
This commit is contained in:
@@ -37,18 +37,21 @@
|
||||
<div class="btn-group pull-right" id="thread-tools" style="visibility: hidden;">
|
||||
<button class="btn dropdown-toggle" data-toggle="dropdown">Thread Tools <span class="caret"></span></button>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="#">Lock/Unlock Thread</a></li>
|
||||
<li><a href="#" id="lock_thread"><i class="icon-lock"></i> Lock Thread</a></li>
|
||||
<li class="divider"></li>
|
||||
<li><a href="#" id="delete_thread"><span class="text-error">Delete Thread</span></a></li>
|
||||
<li><a href="#" id="delete_thread"><span class="text-error"><i class="icon-trash"></i> Delete Thread</span></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
(function() {
|
||||
var locked = '{locked}',
|
||||
expose_tools = '{expose_tools}',
|
||||
tid = '{topic_id}';
|
||||
var expose_tools = '{expose_tools}',
|
||||
tid = '{topic_id}',
|
||||
thread_state = {
|
||||
locked: '{locked}',
|
||||
deleted: '{deleted}'
|
||||
};
|
||||
|
||||
jQuery('document').ready(function() {
|
||||
var room = 'topic_' + '{topic_id}',
|
||||
@@ -57,18 +60,39 @@
|
||||
app.enter_room(room);
|
||||
set_up_posts();
|
||||
|
||||
if (locked === '1') set_locked_state(true);
|
||||
if (thread_state.locked === '1') set_locked_state(true);
|
||||
if (thread_state.deleted === '1') set_delete_state(true);
|
||||
|
||||
if (expose_tools === '1') {
|
||||
var deleteThreadEl = document.getElementById('delete_thread');
|
||||
var deleteThreadEl = document.getElementById('delete_thread'),
|
||||
lockThreadEl = document.getElementById('lock_thread');
|
||||
|
||||
adminTools.style.visibility = 'inherit';
|
||||
|
||||
// Add events to the thread tools
|
||||
deleteThreadEl.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
if (confirm('really delete thread? (THIS DIALOG TO BE REPLACED WITH BOOTBOX)')) {
|
||||
socket.emit('api:topic.delete', { tid: tid });
|
||||
if (thread_state.deleted !== '1') {
|
||||
if (confirm('really delete thread? (THIS DIALOG TO BE REPLACED WITH BOOTBOX)')) {
|
||||
socket.emit('api:topic.delete', { tid: tid });
|
||||
}
|
||||
} else {
|
||||
if (confirm('really restore thread? (THIS DIALOG TO BE REPLACED WITH BOOTBOX)')) {
|
||||
socket.emit('api:topic.restore', { tid: tid });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
lockThreadEl.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
if (thread_state.locked !== '1') {
|
||||
if (confirm('really lock thread? (THIS DIALOG TO BE REPLACED WITH BOOTBOX)')) {
|
||||
socket.emit('api:topic.lock', { tid: tid });
|
||||
}
|
||||
} else {
|
||||
if (confirm('really unlock thread? (THIS DIALOG TO BE REPLACED WITH BOOTBOX)')) {
|
||||
socket.emit('api:topic.unlock', { tid: tid });
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -114,8 +138,32 @@
|
||||
});
|
||||
|
||||
socket.on('event:topic_deleted', function(data) {
|
||||
console.log('deleted');
|
||||
if (data.tid === tid && data.status === 'ok') {
|
||||
console.log('thread deleted!!');
|
||||
set_locked_state(true);
|
||||
set_delete_state(true);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('event:topic_restored', function(data) {
|
||||
console.log('restored');
|
||||
if (data.tid === tid && data.status === 'ok') {
|
||||
set_locked_state(false);
|
||||
set_delete_state(false);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('event:topic_locked', function(data) {
|
||||
console.log('locked');
|
||||
if (data.tid === tid && data.status === 'ok') {
|
||||
set_locked_state(true);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('event:topic_unlocked', function(data) {
|
||||
console.log('unlocked');
|
||||
if (data.tid === tid && data.status === 'ok') {
|
||||
set_locked_state(false);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -178,21 +226,43 @@
|
||||
postReplyBtns = document.querySelectorAll('#post-container .post_reply'),
|
||||
quoteBtns = document.querySelectorAll('#post-container .quote'),
|
||||
numReplyBtns = postReplyBtns.length,
|
||||
lockThreadEl = document.getElementById('lock_thread'),
|
||||
x;
|
||||
if (locked === true) {
|
||||
lockThreadEl.innerHTML = '<i class="icon-unlock"></i> Unlock Thread';
|
||||
threadReplyBtn.disabled = true;
|
||||
threadReplyBtn.innerHTML = 'Locked <i class="icon-lock"></i>';
|
||||
for(x=0;x<numReplyBtns;x++) {
|
||||
postReplyBtns[x].innerHTML = 'Locked <i class="icon-lock"></i>';
|
||||
quoteBtns[x].style.display = 'none';
|
||||
}
|
||||
|
||||
thread_state.locked = '1';
|
||||
} else {
|
||||
lockThreadEl.innerHTML = '<i class="icon-lock"></i> Lock Thread';
|
||||
threadReplyBtn.disabled = false;
|
||||
threadReplyBtn.innerHTML = 'Reply';
|
||||
for(x=0;x<numReplyBtns;x++) {
|
||||
postReplyBtns[x].innerHTML = 'Reply <i class="icon-reply"></i>';
|
||||
quoteBtns[x].style.display = 'inline-block';
|
||||
}
|
||||
|
||||
thread_state.locked = '0';
|
||||
}
|
||||
}
|
||||
|
||||
function set_delete_state(deleted) {
|
||||
var deleteThreadEl = document.getElementById('delete_thread'),
|
||||
deleteTextEl = deleteThreadEl.getElementsByTagName('span')[0];
|
||||
|
||||
if (deleted) {
|
||||
deleteTextEl.innerHTML = '<i class="icon-comment"></i> Restore Thread';
|
||||
|
||||
thread_state.deleted = '1';
|
||||
} else {
|
||||
deleteTextEl.innerHTML = '<i class="icon-trash"></i> Delete Thread';
|
||||
|
||||
thread_state.deleted = '0';
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
19
src/posts.js
19
src/posts.js
@@ -10,12 +10,12 @@ var RDB = require('./redis.js'),
|
||||
if (start == null) start = 0;
|
||||
if (end == null) end = start + 10;
|
||||
|
||||
var post_data, user_data, thread_data, vote_data;
|
||||
var post_data, user_data, thread_data, vote_data, viewer_data;
|
||||
|
||||
|
||||
//compile thread after all data is asynchronously called
|
||||
function generateThread() {
|
||||
if (!post_data ||! user_data || !thread_data || !vote_data) return;
|
||||
if (!post_data ||! user_data || !thread_data || !vote_data || !viewer_data) return;
|
||||
|
||||
var posts = [];
|
||||
|
||||
@@ -41,8 +41,9 @@ var RDB = require('./redis.js'),
|
||||
callback({
|
||||
'topic_name':thread_data.topic_name,
|
||||
'locked': parseInt(thread_data.locked) || 0,
|
||||
'deleted': parseInt(thread_data.deleted) || 0,
|
||||
'topic_id': tid,
|
||||
'expose_tools': user_data[uid].reputation >= config.privilege_thresholds.manage_thread ? 1 : 0,
|
||||
'expose_tools': viewer_data.reputation >= config.privilege_thresholds.manage_thread ? 1 : 0,
|
||||
'posts': posts
|
||||
});
|
||||
}
|
||||
@@ -78,6 +79,7 @@ var RDB = require('./redis.js'),
|
||||
.mget(post_rep)
|
||||
.get('tid:' + tid + ':title')
|
||||
.get('tid:' + tid + ':locked')
|
||||
.get('tid:' + tid + ':deleted')
|
||||
.exec(function(err, replies) {
|
||||
post_data = {
|
||||
pid: pids,
|
||||
@@ -89,7 +91,8 @@ var RDB = require('./redis.js'),
|
||||
|
||||
thread_data = {
|
||||
topic_name: replies[4],
|
||||
locked: replies[5]
|
||||
locked: replies[5] || 0,
|
||||
deleted: replies[6] || 0
|
||||
};
|
||||
|
||||
user.getMultipleUserFields(post_data.uid, ['username','reputation','picture'], function(user_details){
|
||||
@@ -97,7 +100,13 @@ var RDB = require('./redis.js'),
|
||||
generateThread();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
user.getUserField(current_user, 'reputation', function(reputation){
|
||||
viewer_data = {
|
||||
reputation: reputation
|
||||
};
|
||||
generateThread();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ var RDB = require('./redis.js'),
|
||||
RDB.set('tid:' + tid + ':locked', 1);
|
||||
|
||||
if (socket) {
|
||||
socket.emit('event:topic_locked', {
|
||||
socket.in('topic_' + tid).emit('event:topic_locked', {
|
||||
tid: tid,
|
||||
status: 'ok'
|
||||
});
|
||||
@@ -158,10 +158,10 @@ var RDB = require('./redis.js'),
|
||||
user.getUserField(uid, 'reputation', function(rep) {
|
||||
if (rep >= configs.privilege_thresholds.manage_thread) {
|
||||
// Mark thread as locked
|
||||
RDB.set('tid:' + tid + ':locked', 0);
|
||||
RDB.del('tid:' + tid + ':locked');
|
||||
|
||||
if (socket) {
|
||||
socket.emit('event:topic_unlocked', {
|
||||
socket.in('topic_' + tid).emit('event:topic_unlocked', {
|
||||
tid: tid,
|
||||
status: 'ok'
|
||||
});
|
||||
@@ -178,7 +178,7 @@ var RDB = require('./redis.js'),
|
||||
Topics.lock(tid, uid);
|
||||
|
||||
if (socket) {
|
||||
socket.emit('event:topic_deleted', {
|
||||
socket.in('topic_' + tid).emit('event:topic_deleted', {
|
||||
tid: tid,
|
||||
status: 'ok'
|
||||
});
|
||||
@@ -191,11 +191,11 @@ var RDB = require('./redis.js'),
|
||||
user.getUserField(uid, 'reputation', function(rep) {
|
||||
if (rep >= configs.privilege_thresholds.manage_thread) {
|
||||
// Mark thread as deleted
|
||||
RDB.set('tid:' + tid + ':deleted', 0);
|
||||
Topics.lock(tid, uid);
|
||||
RDB.del('tid:' + tid + ':deleted');
|
||||
Topics.unlock(tid, uid);
|
||||
|
||||
if (socket) {
|
||||
socket.emit('event:topic_restored', {
|
||||
socket.in('topic_' + tid).emit('event:topic_restored', {
|
||||
tid: tid,
|
||||
status: 'ok'
|
||||
});
|
||||
|
||||
@@ -62,10 +62,7 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
|
||||
socket.emit('event:connect', {status: 1});
|
||||
|
||||
socket.on('disconnect', function() {
|
||||
console.log('Got disconnect! SESSION ID : '+hs.sessionID+' USER ID : '+uid);
|
||||
|
||||
delete users[hs.sessionID];
|
||||
console.log(users);
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user