mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-08 23:15:48 +01:00
refactor to use getCidsByPrivilege
switch to .includes
This commit is contained in:
@@ -95,7 +95,7 @@ Categories.getAllCategories = function (uid, callback) {
|
||||
], callback);
|
||||
};
|
||||
|
||||
Categories.getCategoriesByPrivilege = function (set, uid, privilege, callback) {
|
||||
Categories.getCidsByPrivilege = function (set, uid, privilege, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
db.getSortedSetRange(set, 0, -1, next);
|
||||
@@ -103,6 +103,14 @@ Categories.getCategoriesByPrivilege = function (set, uid, privilege, callback) {
|
||||
function (cids, next) {
|
||||
privileges.categories.filterCids(privilege, cids, uid, next);
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
Categories.getCategoriesByPrivilege = function (set, uid, privilege, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
Categories.getCidsByPrivilege(set, uid, privilege, next);
|
||||
},
|
||||
function (cids, next) {
|
||||
Categories.getCategories(cids, uid, next);
|
||||
},
|
||||
|
||||
@@ -315,7 +315,7 @@ function filterByTags(posts, hasTags) {
|
||||
var hasAllTags = false;
|
||||
if (post && post.topic && Array.isArray(post.topic.tags) && post.topic.tags.length) {
|
||||
hasAllTags = hasTags.every(function (tag) {
|
||||
return post.topic.tags.indexOf(tag) !== -1;
|
||||
return post.topic.tags.includes(tag);
|
||||
});
|
||||
}
|
||||
return hasAllTags;
|
||||
@@ -370,23 +370,15 @@ function getSearchCids(data, callback) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
if (data.categories.indexOf('all') !== -1) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
db.getSortedSetRange('categories:cid', 0, -1, next);
|
||||
},
|
||||
function (cids, next) {
|
||||
privileges.categories.filterCids('read', cids, data.uid, next);
|
||||
},
|
||||
], callback);
|
||||
return;
|
||||
if (data.categories.includes('all')) {
|
||||
return categories.getCidsByPrivilege('categories:cid', data.uid, 'read', callback);
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
async.parallel({
|
||||
watchedCids: function (next) {
|
||||
if (data.categories.indexOf('watched') !== -1) {
|
||||
if (data.categories.includes('watched')) {
|
||||
user.getWatchedCategories(data.uid, next);
|
||||
} else {
|
||||
next(null, []);
|
||||
|
||||
Reference in New Issue
Block a user