v1.18.x
barisusakli 11 years ago
parent b43602f5b6
commit 311a7ad5b9

@ -58,6 +58,8 @@
"thread_tools.delete_confirm": "Are you sure you want to delete this thread?", "thread_tools.delete_confirm": "Are you sure you want to delete this thread?",
"thread_tools.restore": "Restore Topic", "thread_tools.restore": "Restore Topic",
"thread_tools.restore_confirm": "Are you sure you want to restore this thread?", "thread_tools.restore_confirm": "Are you sure you want to restore this thread?",
"thread_tools.purge": "Purge Topic",
"thread_tools.purge_confirm" : "Are you sure you want to purge this thread?",
"topic_lock_success": "Topic has been successfully locked.", "topic_lock_success": "Topic has been successfully locked.",
"topic_unlock_success": "Topic has been successfully unlocked.", "topic_unlock_success": "Topic has been successfully unlocked.",

@ -15,34 +15,25 @@ define('forum/categoryTools', ['forum/topic/move', 'topicSelect'], function(move
$('.delete_thread').on('click', function(e) { $('.delete_thread').on('click', function(e) {
var tids = topicSelect.getSelectedTids(); var tids = topicSelect.getSelectedTids();
categoryCommand(isAny(isTopicDeleted, tids) ? 'restore' : 'delete', tids);
return false;
});
if (tids.length) { $('.purge_thread').on('click', function() {
var command = isAny(isTopicDeleted, tids) ? 'restore' : 'delete'; var tids = topicSelect.getSelectedTids();
categoryCommand('purge', tids);
translator.translate('[[topic:thread_tools.' + command + '_confirm]]', function(msg) {
bootbox.confirm(msg, function(confirm) {
if (!confirm) {
return;
}
socket.emit('topics.' + command, tids, onCommandComplete);
});
});
}
return false; return false;
}); });
$('.lock_thread').on('click', function(e) { $('.lock_thread').on('click', function() {
var tids = topicSelect.getSelectedTids(); var tids = topicSelect.getSelectedTids();
if (tids.length) { if (tids.length) {
socket.emit(isAny(isTopicLocked, tids) ? 'topics.unlock' : 'topics.lock', tids, onCommandComplete); socket.emit(isAny(isTopicLocked, tids) ? 'topics.unlock' : 'topics.lock', tids, onCommandComplete);
} }
return false; return false;
}); });
$('.pin_thread').on('click', function(e) { $('.pin_thread').on('click', function() {
var tids = topicSelect.getSelectedTids(); var tids = topicSelect.getSelectedTids();
if (tids.length) { if (tids.length) {
socket.emit(isAny(isTopicPinned, tids) ? 'topics.unpin' : 'topics.pin', tids, onCommandComplete); socket.emit(isAny(isTopicPinned, tids) ? 'topics.unpin' : 'topics.pin', tids, onCommandComplete);
@ -84,6 +75,7 @@ define('forum/categoryTools', ['forum/topic/move', 'topicSelect'], function(move
socket.on('event:topic_deleted', setDeleteState); socket.on('event:topic_deleted', setDeleteState);
socket.on('event:topic_restored', setDeleteState); socket.on('event:topic_restored', setDeleteState);
socket.on('event:topic_purged', onTopicPurged);
socket.on('event:topic_locked', setLockedState); socket.on('event:topic_locked', setLockedState);
socket.on('event:topic_unlocked', setLockedState); socket.on('event:topic_unlocked', setLockedState);
socket.on('event:topic_pinned', setPinnedState); socket.on('event:topic_pinned', setPinnedState);
@ -91,9 +83,25 @@ define('forum/categoryTools', ['forum/topic/move', 'topicSelect'], function(move
socket.on('event:topic_moved', onTopicMoved); socket.on('event:topic_moved', onTopicMoved);
}; };
function categoryCommand(command, tids) {
if (!tids.length) {
return;
}
translator.translate('[[topic:thread_tools.' + command + '_confirm]]', function(msg) {
bootbox.confirm(msg, function(confirm) {
if (!confirm) {
return;
}
socket.emit('topics.' + command, tids, onCommandComplete);
});
});
}
CategoryTools.removeListeners = function() { CategoryTools.removeListeners = function() {
socket.removeListener('event:topic_deleted', setDeleteState); socket.removeListener('event:topic_deleted', setDeleteState);
socket.removeListener('event:topic_restored', setDeleteState); socket.removeListener('event:topic_restored', setDeleteState);
socket.removeListener('event:topic_purged', onTopicPurged);
socket.removeListener('event:topic_locked', setLockedState); socket.removeListener('event:topic_locked', setLockedState);
socket.removeListener('event:topic_unlocked', setLockedState); socket.removeListener('event:topic_unlocked', setLockedState);
socket.removeListener('event:topic_pinned', setPinnedState); socket.removeListener('event:topic_pinned', setPinnedState);
@ -116,6 +124,7 @@ define('forum/categoryTools', ['forum/topic/move', 'topicSelect'], function(move
function onTopicSelect() { function onTopicSelect() {
var tids = topicSelect.getSelectedTids(); var tids = topicSelect.getSelectedTids();
var isAnyDeleted = isAny(isTopicDeleted, tids); var isAnyDeleted = isAny(isTopicDeleted, tids);
var areAllDeleted = areAll(isTopicDeleted, tids);
var isAnyPinned = isAny(isTopicPinned, tids); var isAnyPinned = isAny(isTopicPinned, tids);
var isAnyLocked = isAny(isTopicLocked, tids); var isAnyLocked = isAny(isTopicLocked, tids);
@ -130,6 +139,8 @@ define('forum/categoryTools', ['forum/topic/move', 'topicSelect'], function(move
translator.translate('<i class="fa fa-fw fa-' + (isAnyLocked ? 'un': '') + 'lock"></i> [[topic:thread_tools.' + (isAnyLocked ? 'un': '') + 'lock]]', function(translated) { translator.translate('<i class="fa fa-fw fa-' + (isAnyLocked ? 'un': '') + 'lock"></i> [[topic:thread_tools.' + (isAnyLocked ? 'un': '') + 'lock]]', function(translated) {
$('.lock_thread').html(translated); $('.lock_thread').html(translated);
}); });
$('.purge_thread').toggleClass('none', !areAllDeleted);
} }
function isAny(method, tids) { function isAny(method, tids) {
@ -141,6 +152,15 @@ define('forum/categoryTools', ['forum/topic/move', 'topicSelect'], function(move
return false; return false;
} }
function areAll(method, tids) {
for(var i=0; i<tids.length; ++i) {
if(!method(tids[i])) {
return false;
}
}
return true;
}
function isTopicDeleted(tid) { function isTopicDeleted(tid) {
return getTopicEl(tid).hasClass('deleted'); return getTopicEl(tid).hasClass('deleted');
} }
@ -180,5 +200,9 @@ define('forum/categoryTools', ['forum/topic/move', 'topicSelect'], function(move
getTopicEl(data.tid).remove(); getTopicEl(data.tid).remove();
} }
function onTopicPurged(tid) {
getTopicEl(tid).remove();
}
return CategoryTools; return CategoryTools;
}); });

@ -15,6 +15,7 @@ define('forum/topic/events', ['forum/topic/browsing', 'forum/topic/postTools', '
'event:topic_deleted': toggleTopicDeleteState, 'event:topic_deleted': toggleTopicDeleteState,
'event:topic_restored': toggleTopicDeleteState, 'event:topic_restored': toggleTopicDeleteState,
'event:topic_purged': onTopicPurged,
'event:topic_locked': toggleTopicLockedState, 'event:topic_locked': toggleTopicLockedState,
'event:topic_unlocked': toggleTopicLockedState, 'event:topic_unlocked': toggleTopicLockedState,
@ -73,6 +74,10 @@ define('forum/topic/events', ['forum/topic/browsing', 'forum/topic/postTools', '
threadTools.setDeleteState(data); threadTools.setDeleteState(data);
} }
function onTopicPurged(tid) {
ajaxify.refresh();
}
function toggleTopicLockedState(data) { function toggleTopicLockedState(data) {
threadTools.setLockedState(data); threadTools.setLockedState(data);

@ -53,7 +53,7 @@ define('forum/topic/postTools', ['composer', 'share', 'navigator'], function(com
function addPostHandlers(tid, threadState) { function addPostHandlers(tid, threadState) {
$('.topic').on('click', '.post_reply', function() { $('.topic').on('click', '.post_reply', function() {
if (threadState.locked !== '1') { if (!threadState.locked) {
onReplyClicked($(this), tid, topicName); onReplyClicked($(this), tid, topicName);
} }
}); });
@ -61,7 +61,7 @@ define('forum/topic/postTools', ['composer', 'share', 'navigator'], function(com
var postContainer = $('#post-container'); var postContainer = $('#post-container');
postContainer.on('click', '.quote', function() { postContainer.on('click', '.quote', function() {
if (threadState.locked !== '1') { if (!threadState.locked) {
onQuoteClicked($(this), tid, topicName); onQuoteClicked($(this), tid, topicName);
} }
}); });

@ -9,39 +9,35 @@ define('forum/topic/threadTools', ['forum/topic/fork', 'forum/topic/move'], func
ThreadTools.init = function(tid, threadState) { ThreadTools.init = function(tid, threadState) {
ThreadTools.threadState = threadState; ThreadTools.threadState = threadState;
if (threadState.locked === '1') { if (threadState.locked) {
ThreadTools.setLockedState({tid: tid, isLocked: true}); ThreadTools.setLockedState({tid: tid, isLocked: true});
} }
if (threadState.deleted === '1') { if (threadState.deleted) {
ThreadTools.setDeleteState({tid: tid, isDelete: true}); ThreadTools.setDeleteState({tid: tid, isDelete: true});
} }
if (threadState.pinned === '1') { if (threadState.pinned) {
ThreadTools.setPinnedState({tid: tid, isPinned: true}); ThreadTools.setPinnedState({tid: tid, isPinned: true});
} }
$('.delete_thread').on('click', function(e) { $('.delete_thread').on('click', function() {
var command = threadState.deleted !== '1' ? 'delete' : 'restore'; topicCommand(threadState.deleted ? 'restore' : 'delete', tid);
return false;
translator.translate('[[topic:thread_tools.' + command + '_confirm]]', function(msg) { });
bootbox.confirm(msg, function(confirm) {
if (confirm) {
socket.emit('topics.' + command, [tid]);
}
});
});
$('.purge_thread').on('click', function() {
topicCommand('purge', tid);
return false; return false;
}); });
$('.lock_thread').on('click', function(e) { $('.lock_thread').on('click', function() {
socket.emit(threadState.locked !== '1' ? 'topics.lock' : 'topics.unlock', [tid]); socket.emit(threadState.locked ? 'topics.unlock' : 'topics.lock', [tid]);
return false; return false;
}); });
$('.pin_thread').on('click', function(e) { $('.pin_thread').on('click', function() {
socket.emit(threadState.pinned !== '1' ? 'topics.pin' : 'topics.unpin', [tid]); socket.emit(threadState.pinned ? 'topics.unpin' : 'topics.pin', [tid]);
return false; return false;
}); });
@ -89,6 +85,16 @@ define('forum/topic/threadTools', ['forum/topic/fork', 'forum/topic/move'], func
}); });
}; };
function topicCommand(command, tid) {
translator.translate('[[topic:thread_tools.' + command + '_confirm]]', function(msg) {
bootbox.confirm(msg, function(confirm) {
if (confirm) {
socket.emit('topics.' + command, [tid]);
}
});
});
}
ThreadTools.setLockedState = function(data) { ThreadTools.setLockedState = function(data) {
var threadEl = $('#post-container'); var threadEl = $('#post-container');
if (parseInt(data.tid, 10) === parseInt(threadEl.attr('data-tid'), 10)) { if (parseInt(data.tid, 10) === parseInt(threadEl.attr('data-tid'), 10)) {
@ -100,27 +106,30 @@ define('forum/topic/threadTools', ['forum/topic/fork', 'forum/topic/move'], func
threadEl.find('.quote, .edit, .delete').toggleClass('none', data.isLocked); threadEl.find('.quote, .edit, .delete').toggleClass('none', data.isLocked);
$('.topic-main-buttons .post_reply').attr('disabled', data.isLocked).html(data.isLocked ? 'Locked <i class="fa fa-lock"></i>' : 'Reply'); $('.topic-main-buttons .post_reply').attr('disabled', data.isLocked).html(data.isLocked ? 'Locked <i class="fa fa-lock"></i>' : 'Reply');
ThreadTools.threadState.locked = data.isLocked ? '1' : '0'; ThreadTools.threadState.locked = data.isLocked;
} }
}; };
ThreadTools.setDeleteState = function(data) { ThreadTools.setDeleteState = function(data) {
var threadEl = $('#post-container'); var threadEl = $('#post-container');
if (parseInt(data.tid, 10) === parseInt(threadEl.attr('data-tid'), 10)) { if (parseInt(data.tid, 10) !== parseInt(threadEl.attr('data-tid'), 10)) {
translator.translate('<i class="fa fa-fw ' + (data.isDelete ? 'fa-comment' : 'fa-trash-o') + '"></i> [[topic:thread_tools.' + (data.isDelete ? 'restore' : 'delete') + ']]', function(translated) { return;
$('.delete_thread span').html(translated); }
});
threadEl.toggleClass('deleted', data.isDelete); translator.translate('<i class="fa fa-fw ' + (data.isDelete ? 'fa-comment' : 'fa-trash-o') + '"></i> [[topic:thread_tools.' + (data.isDelete ? 'restore' : 'delete') + ']]', function(translated) {
ThreadTools.threadState.deleted = data.isDelete ? '1' : '0'; $('.delete_thread span').html(translated);
});
threadEl.toggleClass('deleted', data.isDelete);
ThreadTools.threadState.deleted = data.isDelete;
$('.purge_thread').toggleClass('none', !data.isDelete);
if (data.isDelete) { if (data.isDelete) {
translator.translate('[[topic:deleted_message]]', function(translated) { translator.translate('[[topic:deleted_message]]', function(translated) {
$('<div id="thread-deleted" class="alert alert-warning">' + translated + '</div>').insertBefore(threadEl); $('<div id="thread-deleted" class="alert alert-warning">' + translated + '</div>').insertBefore(threadEl);
}); });
} else { } else {
$('#thread-deleted').remove(); $('#thread-deleted').remove();
}
} }
}; };
@ -130,7 +139,7 @@ define('forum/topic/threadTools', ['forum/topic/fork', 'forum/topic/move'], func
translator.translate('<i class="fa fa-fw fa-thumb-tack"></i> [[topic:thread_tools.' + (data.isPinned ? 'unpin' : 'pin') + ']]', function(translated) { translator.translate('<i class="fa fa-fw fa-thumb-tack"></i> [[topic:thread_tools.' + (data.isPinned ? 'unpin' : 'pin') + ']]', function(translated) {
$('.pin_thread').html(translated); $('.pin_thread').html(translated);
ThreadTools.threadState.pinned = data.isPinned ? '1' : '0'; ThreadTools.threadState.pinned = data.isPinned;
}); });
} }
} }

@ -183,7 +183,7 @@ var winston = require('winston'),
return callback(err || new Error('[[error:no-privileges]]')); return callback(err || new Error('[[error:no-privileges]]'));
} }
posts.delete(pid, callback); posts.purge(pid, callback);
}); });
}; };

@ -8,7 +8,7 @@ var async = require('async'),
module.exports = function(Posts) { module.exports = function(Posts) {
Posts.delete = function(pid, callback) { Posts.purge = function(pid, callback) {
async.parallel([ async.parallel([
function(next) { function(next) {
deletePostFromTopicAndUser(pid, next); deletePostFromTopicAndUser(pid, next);

@ -160,6 +160,10 @@ SocketTopics.restore = function(socket, tids, callback) {
doTopicAction('restore', socket, tids, callback); doTopicAction('restore', socket, tids, callback);
}; };
SocketTopics.purge = function(socket, tids, callback) {
doTopicAction('purge', socket, tids, callback);
};
SocketTopics.lock = function(socket, tids, callback) { SocketTopics.lock = function(socket, tids, callback) {
doTopicAction('lock', socket, tids, callback); doTopicAction('lock', socket, tids, callback);
}; };

@ -70,6 +70,44 @@ var winston = require('winston'),
}); });
} }
ThreadTools.purge = function(tid, uid, callback) {
async.parallel({
topic: function(next) {
topics.getTopicFields(tid, ['cid', 'mainPid'], next);
},
pids: function(next) {
topics.getPids(tid, next);
}
}, function(err, results) {
if (err) {
return callback(err);
}
var pids = [];
if (results.topic.mainPid) {
pids = [results.topic.mainPid].concat(results.pids);
}
async.parallel([
function(next) {
async.each(pids, posts.purge, next);
},
function(next) {
topics.purge(tid, next);
}
], function(err) {
if (err) {
return callback(err);
}
websockets.emitTopicPostStats();
websockets.in('topic_' + tid).emit('event:topic_purged', tid);
websockets.in('category_' + results.topic.cid).emit('event:topic_purged', tid);
callback();
});
});
};
ThreadTools.lock = function(tid, uid, callback) { ThreadTools.lock = function(tid, uid, callback) {
toggleLock(tid, uid, true, callback); toggleLock(tid, uid, true, callback);
}; };

@ -316,6 +316,9 @@ var async = require('async'),
topicData.thread_tools = results.threadTools; topicData.thread_tools = results.threadTools;
topicData.pageCount = results.pageCount; topicData.pageCount = results.pageCount;
topicData.unreplied = parseInt(topicData.postcount, 10) === 1; topicData.unreplied = parseInt(topicData.postcount, 10) === 1;
topicData.deleted = parseInt(topicData.deleted, 10) === 1;
topicData.locked = parseInt(topicData.locked, 10) === 1;
topicData.pinned = parseInt(topicData.pinned, 10) === 1;
callback(null, topicData); callback(null, topicData);
}); });
@ -433,71 +436,5 @@ var async = require('async'),
}); });
}; };
Topics.delete = function(tid, callback) {
async.parallel([
function(next) {
Topics.setTopicField(tid, 'deleted', 1, next);
},
function(next) {
db.sortedSetRemove('topics:recent', tid, next);
},
function(next) {
db.sortedSetRemove('topics:posts', tid, next);
},
function(next) {
db.sortedSetRemove('topics:views', tid, next);
},
function(next) {
Topics.getTopicField(tid, 'cid', function(err, cid) {
if(err) {
return next(err);
}
db.incrObjectFieldBy('category:' + cid, 'topic_count', -1, next);
});
}
], function(err) {
if (err) {
return callback(err);
}
Topics.updateTopicCount(callback);
});
};
Topics.restore = function(tid, callback) {
Topics.getTopicFields(tid, ['lastposttime', 'postcount', 'viewcount'], function(err, topicData) {
if(err) {
return callback(err);
}
async.parallel([
function(next) {
Topics.setTopicField(tid, 'deleted', 0, next);
},
function(next) {
db.sortedSetAdd('topics:recent', topicData.lastposttime, tid, next);
},
function(next) {
db.sortedSetAdd('topics:posts', topicData.postcount, tid, next);
},
function(next) {
db.sortedSetAdd('topics:views', topicData.viewcount, tid, next);
},
function(next) {
Topics.getTopicField(tid, 'cid', function(err, cid) {
if(err) {
return next(err);
}
db.incrObjectFieldBy('category:' + cid, 'topic_count', 1, next);
});
}
], function(err) {
if (err) {
return callback(err);
}
Topics.updateTopicCount(callback);
});
});
};
}(exports)); }(exports));

@ -7,7 +7,76 @@ var async = require('async'),
module.exports = function(Topics) { module.exports = function(Topics) {
Topics.delete = function(tid, callback) { Topics.delete = function(tid, callback) {
async.parallel([
function(next) {
Topics.setTopicField(tid, 'deleted', 1, next);
},
function(next) {
db.sortedSetRemove('topics:recent', tid, next);
},
function(next) {
db.sortedSetRemove('topics:posts', tid, next);
},
function(next) {
db.sortedSetRemove('topics:views', tid, next);
},
function(next) {
Topics.getTopicField(tid, 'cid', function(err, cid) {
if(err) {
return next(err);
}
db.incrObjectFieldBy('category:' + cid, 'topic_count', -1, next);
});
}
], function(err) {
if (err) {
return callback(err);
}
Topics.updateTopicCount(callback);
});
};
Topics.restore = function(tid, callback) {
Topics.getTopicFields(tid, ['lastposttime', 'postcount', 'viewcount'], function(err, topicData) {
if(err) {
return callback(err);
}
async.parallel([
function(next) {
Topics.setTopicField(tid, 'deleted', 0, next);
},
function(next) {
db.sortedSetAdd('topics:recent', topicData.lastposttime, tid, next);
},
function(next) {
db.sortedSetAdd('topics:posts', topicData.postcount, tid, next);
},
function(next) {
db.sortedSetAdd('topics:views', topicData.viewcount, tid, next);
},
function(next) {
Topics.getTopicField(tid, 'cid', function(err, cid) {
if(err) {
return next(err);
}
db.incrObjectFieldBy('category:' + cid, 'topic_count', 1, next);
});
}
], function(err) {
if (err) {
return callback(err);
}
Topics.updateTopicCount(callback);
});
});
};
Topics.purge = function(tid, callback) {
async.parallel([ async.parallel([
function(next) { function(next) {
db.delete('tid:' + tid + ':followers', next); db.delete('tid:' + tid + ':followers', next);
@ -60,17 +129,18 @@ module.exports = function(Topics) {
return callback(err); return callback(err);
} }
db.decrObjectField('category:' + topicData.cid, 'topic_count', function(err) { if (parseInt(topicData.deleted, 10) === 0) {
if (err) { async.parallel([
return callback(err); function(next) {
} db.decrObjectField('category:' + topicData.cid, 'topic_count', next);
},
if (parseInt(topicData.deleted, 10) === 0) { function(next) {
db.decrObjectField('global', 'topicCount', callback); db.decrObjectField('global', 'topicCount', callback);
} else { }
callback(); ], callback);
} } else {
}); callback();
}
}); });
}); });
} }

@ -28,11 +28,11 @@ module.exports = function(User) {
}; };
function deletePosts(uid, callback) { function deletePosts(uid, callback) {
deleteSortedSetElements('uid:' + uid + ':posts', posts.delete, callback); deleteSortedSetElements('uid:' + uid + ':posts', posts.purge, callback);
} }
function deleteTopics(uid, callback) { function deleteTopics(uid, callback) {
deleteSortedSetElements('uid:' + uid + ':topics', topics.delete, callback); deleteSortedSetElements('uid:' + uid + ':topics', topics.purge, callback);
} }
function deleteSortedSetElements(set, deleteMethod, callback) { function deleteSortedSetElements(set, deleteMethod, callback) {

Loading…
Cancel
Save