diff --git a/services/web/app/src/Features/Chat/ChatController.js b/services/web/app/src/Features/Chat/ChatController.js index 56df5a82c2..fabd32fef2 100644 --- a/services/web/app/src/Features/Chat/ChatController.js +++ b/services/web/app/src/Features/Chat/ChatController.js @@ -1,4 +1,5 @@ const { expressify } = require('@overleaf/promise-utils') +const Modules = require('../../infrastructure/Modules') const ChatApiHandler = require('./ChatApiHandler') const EditorRealTimeController = require('../Editor/EditorRealTimeController') const SessionManager = require('../Authentication/SessionManager') @@ -24,6 +25,13 @@ async function sendMessage(req, res) { message.user = UserInfoController.formatPersonalInfo(user) message.clientId = clientId EditorRealTimeController.emitToRoom(projectId, 'new-chat-message', message) + + await Modules.promises.hooks.fire('chatMessageSent', { + projectId, + userId, + messageId: message.id, + }) + res.sendStatus(204) } diff --git a/services/web/test/unit/src/Chat/ChatControllerTests.js b/services/web/test/unit/src/Chat/ChatControllerTests.js index 15334fb47c..ab35eb21f4 100644 --- a/services/web/test/unit/src/Chat/ChatControllerTests.js +++ b/services/web/test/unit/src/Chat/ChatControllerTests.js @@ -21,6 +21,13 @@ describe('ChatController', function () { promises: {}, } this.UserInfoController = {} + this.Modules = { + promises: { + hooks: { + fire: sinon.stub().resolves(), + }, + }, + } this.ChatController = SandboxedModule.require(MODULE_PATH, { requires: { '@overleaf/settings': this.settings, @@ -30,6 +37,7 @@ describe('ChatController', function () { '../Authentication/SessionManager': this.SessionManager, '../User/UserInfoManager': this.UserInfoManager, '../User/UserInfoController': this.UserInfoController, + '../../infrastructure/Modules': this.Modules, }, }) this.req = {