Node.js based forum software built for the modern web
closes #1371
barisusaklie12beccc094c
diff --git a/public/src/app.js b/public/src/app.jsindex 4725ca9866..6928ab3197 100644--- a/public/src/app.js+++ b/public/src/app.js@@ -569,6 +569,7 @@ var socket,createHeaderTooltips();ajaxify.variables.parse();+ ajaxify.currentPage = tpl_url;app.processPage();ajaxify.widgets.render(tpl_url, url);diff --git a/public/src/forum/category.js b/public/src/forum/category.jsindex 8acd9543ce..e834156a3a 100644--- a/public/src/forum/category.js+++ b/public/src/forum/category.js@@ -1,13 +1,13 @@"use strict";/* global define, config, templates, app, utils, ajaxify, socket, translator */-define(['composer', 'forum/pagination', 'share', 'navigator'], function(composer, pagination, share, navigator) {+define(['composer', 'forum/pagination', 'share', 'navigator', 'forum/categoryTools'], function(composer, pagination, share, navigator, categoryTools) {var Category = {},loadingMoreTopics = false;$(window).on('action:ajaxify.start', function(ev, data) {- if(data.url.indexOf('category') !== 0) {+ if(data && data.url.indexOf('category') !== 0) {navigator.hide();}});@@ -24,11 +24,14 @@ define(['composer', 'forum/pagination', 'share', 'navigator'], function(composer});ajaxify.register_events([- 'event:new_topic'+ 'event:new_topic', 'event:topic_deleted', 'event:topic_restored', 'event:topic_locked',+ 'event:topic_unlocked', 'event:topic_pinned', 'event:topic_unpinned', 'event:topic_moved']);socket.on('event:new_topic', Category.onNewTopic);+ categoryTools.init(cid);+enableInfiniteLoading();if (!config.usePagination) {diff --git a/public/src/forum/categoryTools.js b/public/src/forum/categoryTools.jsnew file mode 100644index 0000000000..34608f6d63--- /dev/null+++ b/public/src/forum/categoryTools.js@@ -0,0 +1,168 @@++'use strict';++/* globals define, app, translator, socket, bootbox */+++define(['forum/topic/move', 'topicSelect'], function(move, topicSelect) {++ var CategoryTools = {};++ CategoryTools.init = function(cid) {+ CategoryTools.cid = cid;++ topicSelect.init(onTopicSelect);++ $('.delete_thread').on('click', function(e) {+ var tids = topicSelect.getSelectedTids();++ if (tids.length) {+ var command = isAny(isTopicDeleted, tids) ? 'restore' : 'delete';++ 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;+ });++ $('.lock_thread').on('click', function(e) {+ var tids = topicSelect.getSelectedTids();+ if (tids.length) {+ socket.emit(isAny(isTopicLocked, tids) ? 'topics.unlock' : 'topics.lock', tids, onCommandComplete);+ }++ return false;+ });++ $('.pin_thread').on('click', function(e) {+ var tids = topicSelect.getSelectedTids();+ if (tids.length) {+ socket.emit(isAny(isTopicPinned, tids) ? 'topics.unpin' : 'topics.pin', tids, onCommandComplete);+ }+ return false;+ });++ $('.markAsUnreadForAll').on('click', function() {+ var tids = topicSelect.getSelectedTids();+ if (tids.length) {+ socket.emit('topics.markAsUnreadForAll', tids, function(err) {+ if(err) {+ return app.alertError(err.message);+ }+ app.alertSuccess('[[topic:markAsUnreadForAll.success]]');++ onCommandComplete();+ });+ }++ return false;+ });++ $('.move_thread').on('click', function() {+ var tids = topicSelect.getSelectedTids();+ console.log(tids);+ if (tids.length) {+ move.init(tids, cid, onCommandComplete);+ }+ return false;+ });+++ socket.on('event:topic_deleted', setDeleteState);+ socket.on('event:topic_restored', setDeleteState);+ socket.on('event:topic_locked', setLockedState);+ socket.on('event:topic_unlocked', setLockedState);+ socket.on('event:topic_pinned', setPinnedState);+ socket.on('event:topic_unpinned', setPinnedState);+ socket.on('event:topic_moved', onTopicMoved);+ };++ function closeDropDown() {+ $('.thread-tools.open').find('.dropdown-toggle').trigger('click');+ }++ function onCommandComplete(err) {+ if (err) {+ return app.alertError(err.message);+ }+ closeDropDown();+ topicSelect.unselectAll();+ }++ function onTopicSelect() {+ var tids = topicSelect.getSelectedTids();+ var isAnyDeleted = isAny(isTopicDeleted, tids);+ var isAnyPinned = isAny(isTopicPinned, tids);+ var isAnyLocked = isAny(isTopicLocked, tids);++ translator.translate('<i class="fa fa-fw ' + (isAnyDeleted ? 'fa-comment' : 'fa-trash-o') + '"></i> [[topic:thread_tools.' + (isAnyDeleted ? 'restore' : 'delete') + ']]', function(translated) {+ $('.delete_thread span').html(translated);+ });++ translator.translate('<i class="fa fa-fw fa-thumb-tack"></i> [[topic:thread_tools.' + (isAnyPinned ? 'unpin' : 'pin') + ']]', function(translated) {+ $('.pin_thread').html(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);+ });+ }++ function isAny(method, tids) {+ for(var i=0; i<tids.length; ++i) {+ if(method(tids[i])) {+ return true;+ }+ }+ return false;+ }++ function isTopicDeleted(tid) {+ return getTopicEl(tid).hasClass('deleted');+ }++ function isTopicLocked(tid) {+ return getTopicEl(tid).hasClass('locked');+ }++ function isTopicPinned(tid) {+ return getTopicEl(tid).hasClass('pinned');+ }++ function getTopicEl(tid) {+ return $('#topics-container li[data-tid="' + tid + '"]');+ }++ function setDeleteState(data) {+ var topic = getTopicEl(data.tid);+ topic.toggleClass('deleted', data.isDeleted);+ topic.find('.fa-lock').toggleClass('hide', !data.isDeleted);+ }++ function setPinnedState(data) {+ var topic = getTopicEl(data.tid);+ topic.toggleClass('pinned', data.isPinned);+ topic.find('.fa-thumb-tack').toggleClass('hide', !data.isPinned);+ ajaxify.go('category/' + CategoryTools.cid);+ }++ function setLockedState(data) {+ var topic = getTopicEl(data.tid);+ topic.toggleClass('locked', data.isLocked);+ topic.find('.fa-lock').toggleClass('hide', !data.isLocked);+ }++ function onTopicMoved(data) {+ getTopicEl(data.tid).remove();+ }++ return CategoryTools;+});diff --git a/public/src/forum/topic.js b/public/src/forum/topic.jsindex 8c40689d82..96f8db8134 100644--- a/public/src/forum/topic.js+++ b/public/src/forum/topic.js@@ -144,7 +144,7 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools',ajaxify.register_events(['event:voted', 'event:favourited', 'event:new_post', 'get_users_in_room',- 'event:topic_deleted', 'event:topic_restored', 'event:topic:locked',+ '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:post_deleted', 'event:post_restored','posts.favourite', 'user.isOnline', 'posts.upvote', 'posts.downvote',diff --git a/public/src/forum/topic/move.js b/public/src/forum/topic/move.jsindex 1b17a9af37..8c5efd6fe1 100644--- a/public/src/forum/topic/move.js+++ b/public/src/forum/topic/move.js@@ -4,97 +4,104 @@define(function() {- var Move = {};+ var Move = {},+ modal,+ targetCid,+ targetCategoryLabel;- Move.init = function(tid) {- var modal = $('#move_thread_modal'),- targetCid,- targetCategoryLabel;+ Move.init = function(tids, currentCid, onComplete) {+ modal = $('#move_thread_modal');- $('.move_thread').on('click', function(e) {- modal.modal('show');- return false;- });+ Move.tids = tids;+ Move.currentCid = currentCid;+ Move.onComplete = onComplete;modal.on('shown.bs.modal', onMoveModalShown);+ $('#move-confirm').hide();+ modal.modal('show');- function onMoveModalShown() {- var loadingEl = $('#categories-loading');- if (!loadingEl.length) {- return;- }+ };- socket.emit('categories.get', onCategoriesLoaded);+ function onMoveModalShown() {+ var loadingEl = $('#categories-loading');+ if (!loadingEl.length) {+ return;}- function onCategoriesLoaded(err, data) {- if (err) {- return app.alertError(err.message);- }+ socket.emit('categories.get', onCategoriesLoaded);+ }- renderCategories(data.categories);+ function onCategoriesLoaded(err, data) {+ if (err) {+ return app.alertError(err.message);+ }- modal.find('.category-list').on('click', 'li[data-cid]', function(e) {- selectCategory($(this));- });+ renderCategories(data.categories);- $('#move_thread_commit').on('click', onCommitClicked);- }+ modal.find('.category-list').on('click', 'li[data-cid]', function(e) {+ selectCategory($(this));+ });- function selectCategory(category) {- modal.find('#confirm-category-name').html(category.html());- $('#move-confirm').css({display: 'block'});+ $('#move_thread_commit').on('click', onCommitClicked);+ }- targetCid = category.attr('data-cid');- targetCategoryLabel = category.html();- $('#move_thread_commit').prop('disabled', false);- }+ function selectCategory(category) {+ modal.find('#confirm-category-name').html(category.html());+ $('#move-confirm').show();- function onCommitClicked() {- var commitEl = $('#move_thread_commit'),- cancelEl = $('#move_thread_cancel');+ targetCid = category.attr('data-cid');+ targetCategoryLabel = category.html();+ $('#move_thread_commit').prop('disabled', false);+ }- if (!commitEl.prop('disabled') && targetCid) {- commitEl.prop('disabled', true);- cancelEl.fadeOut(250);- modal.find('.modal-header button').fadeOut(250);- commitEl.html('Moving <i class="fa-spin fa-refresh"></i>');+ function onCommitClicked() {+ var commitEl = $('#move_thread_commit');- moveTopic();- }- }+ if (!commitEl.prop('disabled') && targetCid) {+ commitEl.prop('disabled', true);- function moveTopic() {- socket.emit('topics.move', {- tid: tid,- cid: targetCid- }, function(err) {- modal.modal('hide');- if(err) {- return app.alertError(err.message);- }-- app.alertSuccess('[[topic:topic_move_success, ' + targetCategoryLabel + ']]');- });+ moveTopic();}+ }++ function moveTopic() {+ socket.emit('topics.move', {+ tids: Move.tids,+ cid: targetCid+ }, function(err) {+ modal.modal('hide');+ $('#move_thread_commit').prop('disabled', false);++ if(err) {+ return app.alertError(err.message);+ }- function renderCategories(categories) {- var categoriesEl = modal.find('.category-list'),- info;-- for (var x = 0; x < categories.length; ++x) {- info = categories[x];- $('<li />')- .css({background: info.bgColor, color: info.color || '#fff'})- .addClass(info.disabled === '1' ? ' disabled' : '')- .attr('data-cid', info.cid)- .html('<i class="fa ' + info.icon + '"></i> ' + info.name)- .appendTo(categoriesEl);+ app.alertSuccess('[[topic:topic_move_success, ' + targetCategoryLabel + ']]');+ if (typeof Move.onComplete === 'function') {+ Move.onComplete();}+ });+ }++ function renderCategories(categories) {+ var categoriesEl = modal.find('.category-list'),+ info;- $('#categories-loading').remove();+ for (var x = 0; x < categories.length; ++x) {+ info = categories[x];+ if(parseInt(info.cid, 10) === parseInt(Move.currentCid, 10)) {+ continue;+ }+ $('<li />')+ .css({background: info.bgColor, color: info.color || '#fff'})+ .addClass(info.disabled === '1' ? ' disabled' : '')+ .attr('data-cid', info.cid)+ .html('<i class="fa ' + info.icon + '"></i> ' + info.name)+ .appendTo(categoriesEl);}- };++ $('#categories-loading').remove();+ }return Move;});diff --git a/public/src/forum/topic/threadTools.js b/public/src/forum/topic/threadTools.jsindex 186bf682c6..ec03d81200 100644--- a/public/src/forum/topic/threadTools.js+++ b/public/src/forum/topic/threadTools.js@@ -18,7 +18,7 @@ define(['forum/topic/fork', 'forum/topic/move'], function(fork, move) {translator.translate('[[topic:thread_tools.' + command + '_confirm]]', function(msg) {bootbox.confirm(msg, function(confirm) {if (confirm) {- socket.emit('topics.' + command, tid);+ socket.emit('topics.' + command, [tid]);}});});@@ -27,18 +27,18 @@ define(['forum/topic/fork', 'forum/topic/move'], function(fork, move) {});$('.lock_thread').on('click', function(e) {- socket.emit(threadState.locked !== '1' ? 'topics.lock' : 'topics.unlock', tid);+ socket.emit(threadState.locked !== '1' ? 'topics.lock' : 'topics.unlock', [tid]);return false;});$('.pin_thread').on('click', function(e) {- socket.emit(threadState.pinned !== '1' ? 'topics.pin' : 'topics.unpin', tid);+ socket.emit(threadState.pinned !== '1' ? 'topics.pin' : 'topics.unpin', [tid]);return false;});$('.markAsUnreadForAll').on('click', function() {var btn = $(this);- socket.emit('topics.markAsUnreadForAll', tid, function(err) {+ socket.emit('topics.markAsUnreadForAll', [tid], function(err) {if(err) {return app.alertError(err.message);}@@ -48,7 +48,10 @@ define(['forum/topic/fork', 'forum/topic/move'], function(fork, move) {return false;});- move.init(tid);+ $('.move_thread').on('click', function(e) {+ move.init([tid], ajaxify.variables.get('category_id'));+ return false;+ });fork.init();}diff --git a/public/src/forum/unread.js b/public/src/forum/unread.jsindex cdfe192df3..d7b31b7eec 100644--- a/public/src/forum/unread.js+++ b/public/src/forum/unread.js@@ -2,7 +2,7 @@/* globals define, app, socket */-define(['forum/recent'], function(recent) {+define(['forum/recent', 'topicSelect'], function(recent, topicSelect) {var Unread = {},loadingMoreTopics = false;@@ -16,14 +16,7 @@ define(['forum/recent'], function(recent) {recent.watchForNewPosts();$('#markSelectedRead').on('click', function() {- function getSelectedTids() {- var tids = [];- $('#topics-container .category-item.selected').each(function() {- tids.push($(this).attr('data-tid'));- });- return tids;- }- var tids = getSelectedTids();+ var tids = topicSelect.getSelectedTids();if(!tids.length) {return;}@@ -77,14 +70,7 @@ define(['forum/recent'], function(recent) {socket.emit('categories.get', onCategoriesLoaded);- $('#topics-container').on('click', '.select', function() {- var select = $(this);- var isChecked = !select.hasClass('fa-square-o');-- select.toggleClass('fa-check-square-o', !isChecked);- select.toggleClass('fa-square-o', isChecked);- select.parents('.category-item').toggleClass('selected', !isChecked);- });+ topicSelect.init();if ($("body").height() <= $(window).height() && $('#topics-container').children().length >= 20) {$('#load-more-btn').show();diff --git a/public/src/modules/topicSelect.js b/public/src/modules/topicSelect.jsnew file mode 100644index 0000000000..4fbbc38f12--- /dev/null+++ b/public/src/modules/topicSelect.js@@ -0,0 +1,36 @@+'use strict';++/* globals define*/++define(function() {+ var TopicSelect = {};++ TopicSelect.init = function(onSelect) {+ $('#topics-container').on('click', '.select', function() {+ var select = $(this);+ var isChecked = !select.hasClass('fa-square-o');++ select.toggleClass('fa-check-square-o', !isChecked);+ select.toggleClass('fa-square-o', isChecked);+ select.parents('.category-item').toggleClass('selected', !isChecked);+ if (typeof onSelect === 'function') {+ onSelect();+ }+ });+ };++ TopicSelect.getSelectedTids = function() {+ var tids = [];+ $('#topics-container .category-item.selected').each(function() {+ tids.push($(this).attr('data-tid'));+ });+ return tids;+ };++ TopicSelect.unselectAll = function() {+ $('#topics-container .category-item.selected').removeClass('selected');+ $('#topics-container .select').toggleClass('fa-check-square-o', false).toggleClass('fa-square-o', true);+ };++ return TopicSelect;+});\ No newline at end of filediff --git a/src/categories/activeusers.js b/src/categories/activeusers.jsindex 418b891aa9..9b8e558aae 100644--- a/src/categories/activeusers.js+++ b/src/categories/activeusers.js@@ -57,7 +57,7 @@ module.exports = function(Categories) {db.getSortedSetRevRange('cid:' + cid + ':active_users', 0, 23, callback);};- Categories.moveActiveUsers = function(tid, oldCid, cid, callback) {+ Categories.moveActiveUsers = function(tid, oldCid, cid) {function updateUser(uid, timestamp) {Categories.addActiveUser(cid, uid, timestamp);Categories.isUserActiveIn(oldCid, uid, function(err, active) {diff --git a/src/categories/recentreplies.js b/src/categories/recentreplies.jsindex 8f4b571e9e..33ee629811 100644--- a/src/categories/recentreplies.js+++ b/src/categories/recentreplies.js@@ -22,25 +22,27 @@ module.exports = function(Categories) {});};- Categories.moveRecentReplies = function(tid, oldCid, cid, callback) {- function movePost(pid, callback) {+ Categories.moveRecentReplies = function(tid, oldCid, cid) {+ function movePost(pid, next) {posts.getPostField(pid, 'timestamp', function(err, timestamp) {if(err) {- return callback(err);+ return next(err);}db.sortedSetRemove('categories:recent_posts:cid:' + oldCid, pid);db.sortedSetAdd('categories:recent_posts:cid:' + cid, timestamp, pid);- callback();+ next();});}topics.getPids(tid, function(err, pids) {- if(err) {- return callback(err);+ if(!err && pids) {+ async.each(pids, movePost, function(err) {+ if (err) {+ winston.error(err.message);+ }+ });}-- async.each(pids, movePost, callback);});};};diff --git a/src/socket.io/topics.js b/src/socket.io/topics.jsindex 17e2ef3684..4d183a1fb3 100644--- a/src/socket.io/topics.js+++ b/src/socket.io/topics.js@@ -120,64 +120,72 @@ SocketTopics.markCategoryTopicsRead = function(socket, cid, callback) {});};-SocketTopics.markAsUnreadForAll = function(socket, tid, callback) {- topics.markAsUnreadForAll(tid, function(err) {- if(err) {- return callback(err);- }+SocketTopics.markAsUnreadForAll = function(socket, tids, callback) {+ if(!Array.isArray(tids)) {+ return callback(new Error('[[error:invalid-tid]]'));+ }- db.sortedSetAdd('topics:recent', Date.now(), tid, function(err) {+ async.each(tids, function(tid, next) {+ topics.markAsUnreadForAll(tid, function(err) {if(err) {- return callback(err);+ return next(err);}- topics.pushUnreadCount();- callback();++ db.sortedSetAdd('topics:recent', Date.now(), tid, function(err) {+ if(err) {+ return next(err);+ }+ topics.pushUnreadCount();+ next();+ });});- });+ }, callback);};-SocketTopics.delete = function(socket, tid, callback) {- doTopicAction('delete', socket, tid, callback);+SocketTopics.delete = function(socket, tids, callback) {+ doTopicAction('delete', socket, tids, callback);};-SocketTopics.restore = function(socket, tid, callback) {- doTopicAction('restore', socket, tid, callback);+SocketTopics.restore = function(socket, tids, callback) {+ doTopicAction('restore', socket, tids, callback);};-SocketTopics.lock = function(socket, tid, callback) {- doTopicAction('lock', socket, tid, callback);+SocketTopics.lock = function(socket, tids, callback) {+ doTopicAction('lock', socket, tids, callback);};-SocketTopics.unlock = function(socket, tid, callback) {- doTopicAction('unlock', socket, tid, callback);+SocketTopics.unlock = function(socket, tids, callback) {+ doTopicAction('unlock', socket, tids, callback);};-SocketTopics.pin = function(socket, tid, callback) {- doTopicAction('pin', socket, tid, callback);+SocketTopics.pin = function(socket, tids, callback) {+ doTopicAction('pin', socket, tids, callback);};-SocketTopics.unpin = function(socket, tid, callback) {- doTopicAction('unpin', socket, tid, callback);+SocketTopics.unpin = function(socket, tids, callback) {+ doTopicAction('unpin', socket, tids, callback);};-function doTopicAction(action, socket, tid, callback) {- if(!tid) {+function doTopicAction(action, socket, tids, callback) {+ if(!tids) {return callback(new Error('[[error:invalid-tid]]'));}- threadTools.privileges(tid, socket.uid, function(err, privileges) {- if(err) {- return callback(err);- }+ async.each(tids, function(tid, next) {+ threadTools.privileges(tid, socket.uid, function(err, privileges) {+ if(err) {+ return next(err);+ }- if(!privileges || !privileges.editable) {- return callback(new Error('[[error:no-privileges]]'));- }+ if(!privileges || !privileges.editable) {+ return next(new Error('[[error:no-privileges]]'));+ }- if(threadTools[action]) {- threadTools[action](tid, socket.uid, callback);- }- });+ if(typeof threadTools[action] === 'function') {+ threadTools[action](tid, socket.uid, next);+ }+ });+ }, callback);}SocketTopics.createTopicFromPosts = function(socket, data, callback) {@@ -215,21 +223,45 @@ SocketTopics.movePost = function(socket, data, callback) {};SocketTopics.move = function(socket, data, callback) {- if(!data || !data.tid || !data.cid) {+ if(!data || !Array.isArray(data.tids) || !data.cid) {return callback(new Error('[[error:invalid-data]]'));}- threadTools.move(data.tid, data.cid, function(err) {- if(err) {- return callback(err);- }+ async.each(data.tids, function(tid, next) {+ var oldCid;+ async.waterfall([+ function(next) {+ threadTools.privileges(tid, socket.uid, next);+ },+ function(privileges, next) {+ if(!(privileges.admin || privileges.moderator)) {+ return next(new Error('[[error:no-privileges]]'));+ }+ next();+ },+ function(next) {+ topics.getTopicField(tid, 'cid', next);+ },+ function(cid, next) {+ oldCid = cid;+ threadTools.move(tid, data.cid, next);+ }+ ], function(err) {+ if(err) {+ return next(err);+ }- index.server.sockets.in('topic_' + data.tid).emit('event:topic_moved', {- tid: data.tid- });+ index.server.sockets.in('topic_' + tid).emit('event:topic_moved', {+ tid: tid+ });- callback(null);- });+ index.server.sockets.in('category_' + oldCid).emit('event:topic_moved', {+ tid: tid+ });++ next();+ });+ }, callback);};SocketTopics.followCheck = function(socket, tid, callback) {diff --git a/src/threadTools.js b/src/threadTools.jsindex d2de95bb3f..55bac851b4 100644--- a/src/threadTools.js+++ b/src/threadTools.js@@ -63,15 +63,14 @@ var winston = require('winston'),};function toggleDelete(tid, uid, isDelete, callback) {- topics.getTopicField(tid, 'deleted', function(err, deleted) {+ topics.getTopicFields(tid, ['cid', 'deleted'], function(err, topicData) {if(err) {return callback(err);}- if (parseInt(deleted, 10) && isDelete) {- return callback(new Error('[[error:topic-already-deleted]]'));- } else if (!parseInt(deleted, 10) && !isDelete) {- return callback(new Error('[[error:topic-already-restored]]'));+ var alreadyDeletedOrRestored = (parseInt(topicData.deleted, 10) && isDelete) || (!parseInt(topicData.deleted, 10) && !isDelete);+ if (alreadyDeletedOrRestored) {+ return callback(null, {tid: tid});}topics[isDelete ? 'delete' : 'restore'](tid, function(err) {@@ -88,7 +87,13 @@ var winston = require('winston'),websockets.emitTopicPostStats();websockets.in('topic_' + tid).emit(isDelete ? 'event:topic_deleted' : 'event:topic_restored', {- tid: tid+ tid: tid,+ isDelete: isDelete+ });++ websockets.in('category_' + topicData.cid).emit(isDelete ? 'event:topic_deleted' : 'event:topic_restored', {+ tid: tid,+ isDelete: isDelete});callback(null, {@@ -107,17 +112,30 @@ var winston = require('winston'),};function toggleLock(tid, uid, lock, callback) {- topics.setTopicField(tid, 'locked', lock ? 1 : 0);+ topics.getTopicField(tid, 'cid', function(err, cid) {+ if (err) {+ return callback(err);+ }- websockets.in('topic_' + tid).emit(lock ? 'event:topic_locked' : 'event:topic_unlocked', {- tid: tid- });+ topics.setTopicField(tid, 'locked', lock ? 1 : 0);++ websockets.in('topic_' + tid).emit(lock ? 'event:topic_locked' : 'event:topic_unlocked', {+ tid: tid,+ isLocked: lock+ });- if (typeof callback === 'function') {- callback(null, {- tid: tid+ websockets.in('category_' + cid).emit(lock ? 'event:topic_locked' : 'event:topic_unlocked', {+ tid: tid,+ isLocked: lock});- }++ if (typeof callback === 'function') {+ callback(null, {+ tid: tid,+ isLocked: lock+ });+ }+ });}ThreadTools.pin = function(tid, uid, callback) {@@ -129,20 +147,33 @@ var winston = require('winston'),};function togglePin(tid, uid, pin, callback) {- topics.setTopicField(tid, 'pinned', pin ? 1 : 0);- topics.getTopicFields(tid, ['cid', 'lastposttime'], function(err, topicData) {- db.sortedSetAdd('categories:' + topicData.cid + ':tid', pin ? Math.pow(2, 53) : topicData.lastposttime, tid);- });+ topics.getTopicField(tid, 'cid', function(err, cid) {+ if (err) {+ return callback(err);+ }- websockets.in('topic_' + tid).emit(pin ? 'event:topic_pinned' : 'event:topic_unpinned', {- tid: tid- });+ topics.setTopicField(tid, 'pinned', pin ? 1 : 0);+ topics.getTopicFields(tid, ['cid', 'lastposttime'], function(err, topicData) {+ db.sortedSetAdd('categories:' + topicData.cid + ':tid', pin ? Math.pow(2, 53) : topicData.lastposttime, tid);+ });- if (typeof callback === 'function') {- callback(null, {- tid: tid+ websockets.in('topic_' + tid).emit(pin ? 'event:topic_pinned' : 'event:topic_unpinned', {+ tid: tid,+ isPinned: pin});- }++ websockets.in('category_' + cid).emit(pin ? 'event:topic_pinned' : 'event:topic_unpinned', {+ tid: tid,+ isPinned: pin+ });++ if (typeof callback === 'function') {+ callback(null, {+ tid: tid,+ isPinned: pin+ });+ }+ });}ThreadTools.move = function(tid, cid, callback) {@@ -165,8 +196,6 @@ var winston = require('winston'),}var oldCid = topic.cid;- topics.setTopicField(tid, 'cid', cid);-if(!parseInt(topic.deleted, 10)) {categories.incrementCategoryFieldBy(oldCid, 'topic_count', -1);categories.incrementCategoryFieldBy(cid, 'topic_count', 1);@@ -174,7 +203,9 @@ var winston = require('winston'),categories.moveActiveUsers(tid, oldCid, cid);- categories.moveRecentReplies(tid, oldCid, cid, callback);+ categories.moveRecentReplies(tid, oldCid, cid);++ topics.setTopicField(tid, 'cid', cid, callback);});};