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