You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nodebb/src/socket.io/categories.js

69 lines
1.6 KiB
JavaScript

'use strict';
var async = require('async'),
categories = require('../categories'),
11 years ago
privileges = require('../privileges'),
meta = require('./../meta'),
user = require('./../user'),
SocketCategories = {};
SocketCategories.getRecentReplies = function(socket, cid, callback) {
11 years ago
privileges.categories.can('read', cid, socket.uid, function(err, canRead) {
if (err) {
return callback(err);
}
11 years ago
if (!canRead) {
return callback(null, []);
}
categories.getRecentReplies(cid, socket.uid, 4, callback);
});
};
SocketCategories.get = function(socket, data, callback) {
categories.getAllCategories(callback);
};
SocketCategories.loadMore = function(socket, data, callback) {
if(!data) {
11 years ago
return callback(new Error('[[error:invalid-data]]'));
}
async.parallel({
privileges: function(next) {
11 years ago
privileges.categories.get(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 + results.settings.topicsPerPage - 1;
categories.getCategoryTopics(data.cid, start, end, socket.uid, function(err, data) {
if (err) {
return callback(err);
}
data.privileges = results.privileges;
callback(null, data);
});
});
};
SocketCategories.getPageCount = function(socket, cid, callback) {
categories.getPageCount(cid, socket.uid, callback);
};
11 years ago
SocketCategories.getTopicCount = function(socket, cid, callback) {
categories.getCategoryField(cid, 'topic_count', callback);
};
module.exports = SocketCategories;