refactor to use getCidsByPrivilege

switch to .includes
v1.18.x
Barış Soner Uşaklı 7 years ago
parent f1a6537fc2
commit 87b6808c4e

@ -95,7 +95,7 @@ Categories.getAllCategories = function (uid, callback) {
], callback); ], callback);
}; };
Categories.getCategoriesByPrivilege = function (set, uid, privilege, callback) { Categories.getCidsByPrivilege = function (set, uid, privilege, callback) {
async.waterfall([ async.waterfall([
function (next) { function (next) {
db.getSortedSetRange(set, 0, -1, next); db.getSortedSetRange(set, 0, -1, next);
@ -103,6 +103,14 @@ Categories.getCategoriesByPrivilege = function (set, uid, privilege, callback) {
function (cids, next) { function (cids, next) {
privileges.categories.filterCids(privilege, cids, uid, 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) { function (cids, next) {
Categories.getCategories(cids, uid, next); Categories.getCategories(cids, uid, next);
}, },

@ -315,7 +315,7 @@ function filterByTags(posts, hasTags) {
var hasAllTags = false; var hasAllTags = false;
if (post && post.topic && Array.isArray(post.topic.tags) && post.topic.tags.length) { if (post && post.topic && Array.isArray(post.topic.tags) && post.topic.tags.length) {
hasAllTags = hasTags.every(function (tag) { hasAllTags = hasTags.every(function (tag) {
return post.topic.tags.indexOf(tag) !== -1; return post.topic.tags.includes(tag);
}); });
} }
return hasAllTags; return hasAllTags;
@ -370,23 +370,15 @@ function getSearchCids(data, callback) {
return callback(null, []); return callback(null, []);
} }
if (data.categories.indexOf('all') !== -1) { if (data.categories.includes('all')) {
async.waterfall([ return categories.getCidsByPrivilege('categories:cid', data.uid, 'read', callback);
function (next) {
db.getSortedSetRange('categories:cid', 0, -1, next);
},
function (cids, next) {
privileges.categories.filterCids('read', cids, data.uid, next);
},
], callback);
return;
} }
async.waterfall([ async.waterfall([
function (next) { function (next) {
async.parallel({ async.parallel({
watchedCids: function (next) { watchedCids: function (next) {
if (data.categories.indexOf('watched') !== -1) { if (data.categories.includes('watched')) {
user.getWatchedCategories(data.uid, next); user.getWatchedCategories(data.uid, next);
} else { } else {
next(null, []); next(null, []);

Loading…
Cancel
Save