2014-03-20 14:58:45 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
2014-04-16 14:30:36 -04:00
|
|
|
var async = require('async'),
|
|
|
|
|
categories = require('../categories'),
|
2014-05-15 20:49:47 -04:00
|
|
|
privileges = require('../privileges'),
|
2014-01-24 22:26:11 -05:00
|
|
|
meta = require('./../meta'),
|
2014-02-10 14:15:54 -05:00
|
|
|
user = require('./../user'),
|
2014-01-09 22:46:51 -05:00
|
|
|
|
|
|
|
|
SocketCategories = {};
|
|
|
|
|
|
2014-03-20 14:58:45 -04:00
|
|
|
SocketCategories.getRecentReplies = function(socket, cid, callback) {
|
2014-05-15 20:49:47 -04:00
|
|
|
privileges.categories.canRead(cid, socket.uid, function(err, canRead) {
|
2014-03-20 14:58:45 -04:00
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-15 20:49:47 -04:00
|
|
|
if (!canRead) {
|
2014-03-20 14:58:45 -04:00
|
|
|
return callback(null, []);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
categories.getRecentReplies(cid, socket.uid, 4, callback);
|
|
|
|
|
});
|
2014-01-09 22:46:51 -05:00
|
|
|
};
|
|
|
|
|
|
2014-01-16 15:16:12 -05:00
|
|
|
SocketCategories.get = function(socket, data, callback) {
|
2014-01-16 19:57:28 -05:00
|
|
|
categories.getAllCategories(0, callback);
|
2014-01-09 22:46:51 -05:00
|
|
|
};
|
|
|
|
|
|
2014-01-16 15:16:12 -05:00
|
|
|
SocketCategories.loadMore = function(socket, data, callback) {
|
2014-01-17 12:49:21 -05:00
|
|
|
if(!data) {
|
2014-04-09 21:22:37 -04:00
|
|
|
return callback(new Error('[[error:invalid-data]]'));
|
2014-01-17 12:49:21 -05:00
|
|
|
}
|
|
|
|
|
|
2014-04-16 14:30:36 -04:00
|
|
|
async.parallel({
|
|
|
|
|
privileges: function(next) {
|
2014-05-15 20:49:47 -04:00
|
|
|
privileges.categories.get(data.cid, socket.uid, next);
|
2014-04-16 14:30:36 -04:00
|
|
|
},
|
|
|
|
|
settings: function(next) {
|
|
|
|
|
user.getSettings(socket.uid, next);
|
|
|
|
|
}
|
|
|
|
|
}, function(err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
2014-01-24 22:26:11 -05:00
|
|
|
|
2014-02-10 14:15:54 -05:00
|
|
|
var start = parseInt(data.after, 10),
|
2014-04-16 14:30:36 -04:00
|
|
|
end = start + results.settings.topicsPerPage - 1;
|
|
|
|
|
|
|
|
|
|
categories.getCategoryTopics(data.cid, start, end, socket.uid, function(err, data) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
2014-01-26 17:23:28 -05:00
|
|
|
|
2014-04-16 14:30:36 -04:00
|
|
|
data.privileges = results.privileges;
|
|
|
|
|
callback(null, data);
|
|
|
|
|
});
|
2014-02-10 14:15:54 -05:00
|
|
|
});
|
2014-01-09 22:46:51 -05:00
|
|
|
};
|
|
|
|
|
|
2014-01-24 23:05:59 -05:00
|
|
|
SocketCategories.getPageCount = function(socket, cid, callback) {
|
2014-02-10 14:15:54 -05:00
|
|
|
categories.getPageCount(cid, socket.uid, callback);
|
|
|
|
|
};
|
2014-01-24 23:05:59 -05:00
|
|
|
|
2014-04-04 12:42:41 -04:00
|
|
|
SocketCategories.getTopicCount = function(socket, cid, callback) {
|
|
|
|
|
categories.getCategoryField(cid, 'topic_count', callback);
|
|
|
|
|
};
|
|
|
|
|
|
2014-04-10 20:31:57 +01:00
|
|
|
module.exports = SocketCategories;
|