mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-17 03:01:08 +01:00
moved privilege check out of getRecentReplies
it was being called twice in api/home
This commit is contained in:
@@ -9,30 +9,20 @@ var async = require('async'),
|
|||||||
|
|
||||||
module.exports = function(Categories) {
|
module.exports = function(Categories) {
|
||||||
Categories.getRecentReplies = function(cid, uid, count, callback) {
|
Categories.getRecentReplies = function(cid, uid, count, callback) {
|
||||||
if(count === 0 || !count) {
|
if(!parseInt(count, 10)) {
|
||||||
return callback(null, []);
|
return callback(null, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
CategoryTools.privileges(cid, uid, function(err, privileges) {
|
db.getSortedSetRevRange('categories:recent_posts:cid:' + cid, 0, count - 1, function(err, pids) {
|
||||||
if(err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!privileges.read) {
|
if (!pids || !pids.length) {
|
||||||
return callback(null, []);
|
return callback(null, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
db.getSortedSetRevRange('categories:recent_posts:cid:' + cid, 0, count - 1, function(err, pids) {
|
posts.getPostSummaryByPids(pids, true, callback);
|
||||||
if (err) {
|
|
||||||
return callback(err, []);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!pids || !pids.length) {
|
|
||||||
return callback(null, []);
|
|
||||||
}
|
|
||||||
|
|
||||||
posts.getPostSummaryByPids(pids, true, callback);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,24 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
var categories = require('../categories'),
|
var categories = require('../categories'),
|
||||||
|
categoryTools = require('../categoryTools'),
|
||||||
meta = require('./../meta'),
|
meta = require('./../meta'),
|
||||||
user = require('./../user'),
|
user = require('./../user'),
|
||||||
|
|
||||||
SocketCategories = {};
|
SocketCategories = {};
|
||||||
|
|
||||||
SocketCategories.getRecentReplies = function(socket, tid, callback) {
|
SocketCategories.getRecentReplies = function(socket, cid, callback) {
|
||||||
categories.getRecentReplies(tid, socket.uid, 4, callback);
|
categoryTools.privileges(cid, socket.uid, function(err, privileges) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (privileges && !privileges.read) {
|
||||||
|
return callback(null, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
categories.getRecentReplies(cid, socket.uid, 4, callback);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketCategories.get = function(socket, data, callback) {
|
SocketCategories.get = function(socket, data, callback) {
|
||||||
|
|||||||
Reference in New Issue
Block a user