Node.js based forum software built for the modern web
return privileges in category
barisusakli01555cbb5c4d
diff --git a/public/src/forum/category.js b/public/src/forum/category.jsindex adb5bc34c7..8acd9543ce 100644--- a/public/src/forum/category.js+++ b/public/src/forum/category.js@@ -225,11 +225,13 @@ define(['composer', 'forum/pagination', 'share', 'navigator'], function(composer});}- Category.onTopicsLoaded = function(topics, callback) {- if(!topics || !topics.length) {+ Category.onTopicsLoaded = function(data, callback) {+ if(!data || !data.topics.length) {return;}+ var topics = data.topics;+function removeAlreadyAddedTopics() {topics = topics.filter(function(topic) {return $('#topics-container li[data-tid="' + topic.tid +'"]').length === 0;@@ -261,7 +263,7 @@ define(['composer', 'forum/pagination', 'share', 'navigator'], function(composerfindInsertionPoint();ajaxify.loadTemplate('category', function(categoryTemplate) {- var html = templates.parse(templates.getBlock(categoryTemplate, 'topics'), {topics: topics});+ var html = templates.parse(templates.getBlock(categoryTemplate, 'topics'), data);translator.translate(html, function(translatedHTML) {var container = $('#topics-container'),@@ -309,6 +311,7 @@ define(['composer', 'forum/pagination', 'share', 'navigator'], function(composercid: cid,after: after}, function (err, data) {+ console.log(data);loadingMoreTopics = false;if(err) {@@ -316,7 +319,7 @@ define(['composer', 'forum/pagination', 'share', 'navigator'], function(composer}if (data && data.topics.length) {- Category.onTopicsLoaded(data.topics, callback);+ Category.onTopicsLoaded(data, callback);$('#topics-container').attr('data-nextstart', data.nextStart);} else {diff --git a/src/controllers/categories.js b/src/controllers/categories.jsindex f30dcc13b3..07f6bf9ab0 100644--- a/src/controllers/categories.js+++ b/src/controllers/categories.js@@ -68,14 +68,14 @@ categoriesController.get = function(req, res, next) {async.waterfall([function(next) {categoryTools.privileges(cid, uid, function(err, categoryPrivileges) {- if (!err) {- if (!categoryPrivileges.read) {- next(new Error('[[error:no-privileges]]'));- } else {- next(null, categoryPrivileges);- }+ if (err) {+ return next(err);+ }++ if (!categoryPrivileges.read) {+ next(new Error('[[error:no-privileges]]'));} else {- next(err);+ next(null, categoryPrivileges);}});},diff --git a/src/socket.io/categories.js b/src/socket.io/categories.jsindex 80af126f29..3687424bd5 100644--- a/src/socket.io/categories.js+++ b/src/socket.io/categories.js@@ -1,6 +1,7 @@'use strict';-var categories = require('../categories'),+var async = require('async'),+ categories = require('../categories'),categoryTools = require('../categoryTools'),meta = require('./../meta'),user = require('./../user'),@@ -30,12 +31,29 @@ SocketCategories.loadMore = function(socket, data, callback) {return callback(new Error('[[error:invalid-data]]'));}- user.getSettings(socket.uid, function(err, settings) {+ async.parallel({+ privileges: function(next) {+ categoryTools.privileges(data.cid, socket.uid, next);+ },+ settings: function(next) {+ user.getSettings(socket.uid, next);+ }+ }, function(err, results) {+ if (err) {+ return callback(err);+ }var start = parseInt(data.after, 10),- end = start + settings.topicsPerPage - 1;+ end = start + results.settings.topicsPerPage - 1;++ categories.getCategoryTopics(data.cid, start, end, socket.uid, function(err, data) {+ if (err) {+ return callback(err);+ }- categories.getCategoryTopics(data.cid, start, end, socket.uid, callback);+ data.privileges = results.privileges;+ callback(null, data);+ });});};