thread pinning

v1.18.x
Julian Lam 12 years ago
parent ae43a299df
commit bf7c602cd8

@ -37,6 +37,7 @@
<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="#" id="pin_thread"><i class="icon-pushpin"></i> Pin 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"><i class="icon-trash"></i> Delete Thread</span></a></li>
@ -50,7 +51,8 @@
tid = '{topic_id}',
thread_state = {
locked: '{locked}',
deleted: '{deleted}'
deleted: '{deleted}',
pinned: '{pinned}'
};
jQuery('document').ready(function() {
@ -62,10 +64,12 @@
if (thread_state.locked === '1') set_locked_state(true);
if (thread_state.deleted === '1') set_delete_state(true);
if (thread_state.pinned === '1') set_pinned_state(true);
if (expose_tools === '1') {
var deleteThreadEl = document.getElementById('delete_thread'),
lockThreadEl = document.getElementById('lock_thread');
lockThreadEl = document.getElementById('lock_thread'),
pinThreadEl = document.getElementById('pin_thread');
adminTools.style.visibility = 'inherit';
@ -86,13 +90,18 @@
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 });
}
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 });
}
socket.emit('api:topic.unlock', { tid: tid });
}
});
pinThreadEl.addEventListener('click', function(e) {
e.preventDefault();
if (thread_state.pinned !== '1') {
socket.emit('api:topic.pin', { tid: tid });
} else {
socket.emit('api:topic.unpin', { tid: tid });
}
});
}
@ -163,6 +172,18 @@
}
});
socket.on('event:topic_pinned', function(data) {
if (data.tid === tid && data.status === 'ok') {
set_pinned_state(true);
}
});
socket.on('event:topic_unpinned', function(data) {
if (data.tid === tid && data.status === 'ok') {
set_pinned_state(false);
}
});
function adjust_rep(value, pid, uid) {
var post_rep = jQuery('.post_rep_' + pid),
user_rep = jQuery('.user_rep_' + uid);
@ -280,5 +301,19 @@
thread_state.deleted = '0';
}
}
function set_pinned_state(pinned) {
var pinEl = document.getElementById('pin_thread');
if (pinned) {
pinEl.innerHTML = '<i class="icon-pushpin"></i> Unpin Thread';
thread_state.pinned = '1';
} else {
pinEl.innerHTML = '<i class="icon-pushpin"></i> Pin Thread';
thread_state.pinned = '0';
}
}
})();
</script>

@ -215,4 +215,36 @@ var RDB = require('./redis.js'),
}
});
}
Topics.pin = function(tid, uid, socket) {
user.getUserField(uid, 'reputation', function(rep) {
if (rep >= configs.privilege_thresholds.manage_thread) {
// Mark thread as deleted
RDB.set('tid:' + tid + ':pinned', 1);
if (socket) {
io.sockets.in('topic_' + tid).emit('event:topic_pinned', {
tid: tid,
status: 'ok'
});
}
}
});
}
Topics.unpin = function(tid, uid, socket) {
user.getUserField(uid, 'reputation', function(rep) {
if (rep >= configs.privilege_thresholds.manage_thread) {
// Mark thread as deleted
RDB.del('tid:' + tid + ':pinned');
if (socket) {
io.sockets.in('topic_' + tid).emit('event:topic_unpinned', {
tid: tid,
status: 'ok'
});
}
}
});
}
}(exports));

@ -190,6 +190,14 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
socket.on('api:topic.unlock', function(data) {
modules.topics.unlock(data.tid, uid, socket);
});
socket.on('api:topic.pin', function(data) {
modules.topics.pin(data.tid, uid, socket);
});
socket.on('api:topic.unpin', function(data) {
modules.topics.unpin(data.tid, uid, socket);
});
});
}(SocketIO));

Loading…
Cancel
Save