Skip to content

Node.js based forum software built for the modern web

fix: init topic events from webserver.js

Julian Lamb81508c4e2f1
diff --git a/src/topics/events.js b/src/topics/events.js
index 713199594b..a5a28da265 100644
--- a/src/topics/events.js
+++ b/src/topics/events.js
@@ -43,16 +43,11 @@ Events._types = {
},
};
-async function init() {
- if (!plugins.hooks) {
- return setImmediate(init);
- }
-
+Events.init = async () => {
// Allow plugins to define additional topic event types
const { types } = await plugins.hooks.fire('filter:topicEvents.init', { types: Events._types });
Events._types = types;
-}
-init();
+};
Events.get = async (tid) => {
const topics = require('.');
diff --git a/src/webserver.js b/src/webserver.js
index a75549420a..c9509b30f8 100644
--- a/src/webserver.js
+++ b/src/webserver.js
@@ -31,6 +31,7 @@ const meta = require('./meta');
const logger = require('./logger');
const plugins = require('./plugins');
const flags = require('./flags');
+const topicEvents = require('./topics/events');
const routes = require('./routes');
const auth = require('./routes/authentication');
@@ -106,6 +107,7 @@ async function initializeNodeBB() {
await meta.blacklist.load();
await flags.init();
await analytics.init();
+ await topicEvents.init();
}
function setupExpressApp(app) {
diff --git a/test/topicEvents.js b/test/topicEvents.js
index 84cd9701f0..889a73e5d5 100644
--- a/test/topicEvents.js
+++ b/test/topicEvents.js
@@ -55,24 +55,6 @@ describe('Topic Events', () => {
quux: 'quux',
});
});
-
- it('should do nothing if called a second time', async () => {
- await plugins.hooks.register('core', {
- hook: 'filter:topicEvents.init',
- method: async ({ types }) => {
- types.bar = {
- icon: 'bar',
- text: 'baz',
- quux: 'quux',
- };
-
- return { types };
- },
- });
-
- await topics.events.init();
- assert(!topics.events._types.bar); // bar is explicitly not available
- });
});
describe('.log()', () => {