mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 17:16:14 +01:00
fix: regression from filter hook change
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const async = require('async');
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
const winston = require('winston');
|
const winston = require('winston');
|
||||||
const plugins = require('.');
|
const plugins = require('.');
|
||||||
|
const utils = require('../utils');
|
||||||
|
|
||||||
const Hooks = module.exports;
|
const Hooks = module.exports;
|
||||||
|
|
||||||
@@ -114,22 +116,37 @@ async function fireFilterHook(hook, hookList, params) {
|
|||||||
if (!Array.isArray(hookList) || !hookList.length) {
|
if (!Array.isArray(hookList) || !hookList.length) {
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
return await async.reduce(hookList, params, (params, hookObj, next) => {
|
||||||
for (const hookObj of hookList) {
|
|
||||||
if (typeof hookObj.method !== 'function') {
|
if (typeof hookObj.method !== 'function') {
|
||||||
if (global.env === 'development') {
|
if (global.env === 'development') {
|
||||||
winston.warn(`[plugins] Expected method for hook '${hook}' in plugin '${hookObj.id}' not found, skipping.`);
|
winston.warn(`[plugins] Expected method for hook '${hook}' in plugin '${hookObj.id}' not found, skipping.`);
|
||||||
}
|
}
|
||||||
} else {
|
return next(null, params);
|
||||||
let hookFn = hookObj.method;
|
|
||||||
if (hookFn.constructor && hookFn.constructor.name !== 'AsyncFunction') {
|
|
||||||
hookFn = util.promisify(hookFn);
|
|
||||||
}
|
|
||||||
// eslint-disable-next-line
|
|
||||||
params = await hookFn(params);
|
|
||||||
}
|
}
|
||||||
}
|
const returned = hookObj.method(params, next);
|
||||||
return params;
|
if (utils.isPromise(returned)) {
|
||||||
|
returned.then(
|
||||||
|
payload => setImmediate(next, null, payload),
|
||||||
|
err => setImmediate(next, err)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// breaks plugins that use a non-async function ie emoji-one parse.raw
|
||||||
|
// for (const hookObj of hookList) {
|
||||||
|
// if (typeof hookObj.method !== 'function') {
|
||||||
|
// if (global.env === 'development') {
|
||||||
|
// winston.warn(`[plugins] Expected method for hook '${hook}' in plugin '${hookObj.id}' not found, skipping.`);
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// let hookFn = hookObj.method;
|
||||||
|
// if (hookFn.constructor && hookFn.constructor.name !== 'AsyncFunction') {
|
||||||
|
// hookFn = util.promisify(hookFn);
|
||||||
|
// }
|
||||||
|
// // eslint-disable-next-line
|
||||||
|
// params = await hookFn(params);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fireActionHook(hook, hookList, params) {
|
async function fireActionHook(hook, hookList, params) {
|
||||||
|
|||||||
Reference in New Issue
Block a user