From a02ae6f5df063c24d52699c808aa00c12324649e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Thu, 29 Oct 2020 22:33:28 -0400 Subject: [PATCH] refactor: simpler check in user.blocks.filter --- src/user/blocks.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/user/blocks.js b/src/user/blocks.js index 7a8423e83e..3384aa6b7b 100644 --- a/src/user/blocks.js +++ b/src/user/blocks.js @@ -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; } @@ -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 });