mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-06 22:15:48 +01:00
switch .filter to uniq
This commit is contained in:
@@ -160,9 +160,7 @@ Notifications.push = function (notification, uids, callback) {
|
||||
uids = [uids];
|
||||
}
|
||||
|
||||
uids = uids.filter(function (uid, index, array) {
|
||||
return parseInt(uid, 10) && array.indexOf(uid) === index;
|
||||
});
|
||||
uids = _.uniq(uids);
|
||||
|
||||
if (!uids.length) {
|
||||
return callback();
|
||||
|
||||
@@ -273,9 +273,7 @@ module.exports = function (privileges) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
uids = uids.filter(function (uid, index, array) {
|
||||
return array.indexOf(uid) === index;
|
||||
});
|
||||
uids = _.uniq(uids);
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
@@ -286,14 +284,14 @@ module.exports = function (privileges) {
|
||||
isModerators: function (next) {
|
||||
user.isModerator(uids, cid, next);
|
||||
},
|
||||
isAdmin: function (next) {
|
||||
isAdmins: function (next) {
|
||||
user.isAdministrator(uids, next);
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
uids = uids.filter(function (uid, index) {
|
||||
return results.allowedTo[index] || results.isModerators[index] || results.isAdmin[index];
|
||||
return results.allowedTo[index] || results.isModerators[index] || results.isAdmins[index];
|
||||
});
|
||||
next(null, uids);
|
||||
},
|
||||
|
||||
@@ -82,11 +82,9 @@ module.exports = function (privileges) {
|
||||
},
|
||||
function (_topicsData, next) {
|
||||
topicsData = _topicsData;
|
||||
cids = topicsData.map(function (topic) {
|
||||
cids = _.uniq(topicsData.map(function (topic) {
|
||||
return topic.cid;
|
||||
}).filter(function (cid, index, array) {
|
||||
return cid && array.indexOf(cid) === index;
|
||||
});
|
||||
}));
|
||||
|
||||
privileges.categories.getBase(privilege, cids, uid, next);
|
||||
},
|
||||
@@ -121,15 +119,14 @@ module.exports = function (privileges) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
uids = uids.filter(function (uid, index, array) {
|
||||
return array.indexOf(uid) === index;
|
||||
});
|
||||
|
||||
uids = _.uniq(uids);
|
||||
var topicData;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
topics.getTopicFields(tid, ['tid', 'cid', 'deleted'], next);
|
||||
},
|
||||
function (topicData, next) {
|
||||
function (_topicData, next) {
|
||||
topicData = _topicData;
|
||||
async.parallel({
|
||||
disabled: function (next) {
|
||||
categories.getCategoryField(topicData.cid, 'disabled', next);
|
||||
@@ -143,18 +140,15 @@ module.exports = function (privileges) {
|
||||
isAdmins: function (next) {
|
||||
user.isAdministrator(uids, next);
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
uids = uids.filter(function (uid, index) {
|
||||
return parseInt(results.disabled, 10) !== 1 &&
|
||||
((results.allowedTo[index] && parseInt(topicData.deleted, 10) !== 1) || results.isAdmins[index] || results.isModerators[index]);
|
||||
});
|
||||
|
||||
next(null, uids);
|
||||
});
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user