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

51 lines
1.2 KiB
JavaScript

var categories = require('../categories'),
meta = require('./../meta'),
SocketCategories = {};
SocketCategories.getRecentReplies = function(socket, tid, callback) {
categories.getRecentReplies(tid, socket.uid, 4, callback);
};
SocketCategories.get = function(socket, data, callback) {
categories.getAllCategories(0, callback);
};
SocketCategories.loadMore = function(socket, data, callback) {
if(!data) {
return callback(new Error('invalid data'));
}
var topicsPerPage = parseInt(meta.config.topicsPerPage, 10) || 20;
var start = data.after,
end = start + topicsPerPage - 1;
categories.getCategoryTopics(data.cid, start, end, socket.uid, function(err, topics) {
callback(err, {
topics: topics
});
});
};
SocketCategories.loadPage = function(socket, data, callback) {
if(!data) {
return callback(new Error('invalid data'));
}
var topicsPerPage = parseInt(meta.config.topicsPerPage, 10) || 20;
var start = (data.page - 1) * topicsPerPage,
end = start + topicsPerPage - 1;
console.log('start to end' ,start, end);
categories.getCategoryTopics(data.cid, start, end, socket.uid, function(err, topics) {
console.log('getting topics', topics.length);
callback(err, {
topics: topics
});
});
}
module.exports = SocketCategories;