From c4545381d760ee1a9885af7b56dfa045cee7cd94 Mon Sep 17 00:00:00 2001 From: Opliko <25460763+oplik0@users.noreply.github.com> Date: Fri, 8 May 2020 20:42:02 +0200 Subject: [PATCH] feat: Add hooks for user blocks (#8296) * Add hooks for user blocks * change naming * Fix the filter... fixes #8109 --- src/user/blocks.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/user/blocks.js b/src/user/blocks.js index 0065fd52e4..7a8423e83e 100644 --- a/src/user/blocks.js +++ b/src/user/blocks.js @@ -5,6 +5,7 @@ const LRU = require('lru-cache'); const db = require('../database'); const pubsub = require('../pubsub'); +const plugins = require('../plugins'); module.exports = function (User) { User.blocks = { @@ -63,6 +64,7 @@ module.exports = function (User) { await User.incrementUserFieldBy(uid, 'blocksCount', 1); User.blocks._cache.del(parseInt(uid, 10)); pubsub.publish('user:blocks:cache:del', parseInt(uid, 10)); + plugins.fireHook('action:user.blocks.add', { uid: uid, targetUid: targetUid }); }; User.blocks.remove = async function (targetUid, uid) { @@ -71,6 +73,7 @@ module.exports = function (User) { await User.decrementUserFieldBy(uid, 'blocksCount', 1); User.blocks._cache.del(parseInt(uid, 10)); pubsub.publish('user:blocks:cache:del', parseInt(uid, 10)); + plugins.fireHook('action:user.blocks.remove', { uid: uid, targetUid: targetUid }); }; User.blocks.applyChecks = async function (type, targetUid, uid) { @@ -115,7 +118,8 @@ module.exports = function (User) { set = set.filter(function (item) { return !blockedSet.has(parseInt(isPlain ? item : item[property], 10)); }); + const data = await plugins.fireHook('filter:user.blocks.filter', { set: set, property: property, uid: uid, blockedSet: blockedSet }); - return set; + return data.set; }; };