Files
NodeBB/src/socket.io/categories.js

77 lines
1.8 KiB
JavaScript
Raw Normal View History

'use strict';
2014-04-16 14:30:36 -04:00
var async = require('async'),
2014-06-27 15:35:53 -04:00
db = require('../database'),
2014-04-16 14:30:36 -04:00
categories = require('../categories'),
2014-05-15 20:49:47 -04:00
privileges = require('../privileges'),
2014-06-27 15:35:53 -04:00
user = require('../user'),
SocketCategories = {};
SocketCategories.getRecentReplies = function(socket, cid, callback) {
2014-05-17 18:59:34 -04:00
privileges.categories.can('read', cid, socket.uid, function(err, canRead) {
if (err) {
return callback(err);
}
2014-05-15 20:49:47 -04:00
if (!canRead) {
return callback(null, []);
}
categories.getRecentReplies(cid, socket.uid, 4, callback);
});
};
SocketCategories.get = function(socket, data, callback) {
2014-05-27 12:44:28 -04:00
categories.getAllCategories(callback);
};
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);
}
if (!results.privileges.read) {
return callback(new Error('[[error:no-privileges]]'));
}
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-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-06-27 15:35:53 -04:00
SocketCategories.lastTopicIndex = function(socket, cid, callback) {
db.sortedSetCard('categories:' + cid + ':tid', callback);
};
2014-04-10 20:31:57 +01:00
module.exports = SocketCategories;