Skip to content

Commit

Permalink
refactor: simpler check in user.blocks.filter
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Oct 30, 2020
1 parent 27016d2 commit a02ae6f
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/user/blocks.js
Expand Up @@ -100,14 +100,7 @@ module.exports = function (User) {
property = 'uid';
}

if (!Array.isArray(set) || !set.length || !set.every((item) => {
if (!item) {
return false;
}

const check = item.hasOwnProperty(property) ? item[property] : item;
return ['number', 'string'].includes(typeof check);
})) {
if (!Array.isArray(set) || !set.length) {
return set;
}

Expand All @@ -116,7 +109,7 @@ module.exports = function (User) {
const blockedSet = new Set(blocked_uids);

set = set.filter(function (item) {
return !blockedSet.has(parseInt(isPlain ? item : item[property], 10));
return !blockedSet.has(parseInt(isPlain ? item : (item && item[property]), 10));
});
const data = await plugins.fireHook('filter:user.blocks.filter', { set: set, property: property, uid: uid, blockedSet: blockedSet });

Expand Down

0 comments on commit a02ae6f

Please sign in to comment.