From dd29fb8e533dd0a4f7d4c8127669ba1403fa85f5 Mon Sep 17 00:00:00 2001 From: Calvin Secrest Date: Sun, 31 Aug 2025 22:42:02 -0400 Subject: [PATCH] Fix broadcast block structure in communication controller --- backend/controllers/communication_controller.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/backend/controllers/communication_controller.js b/backend/controllers/communication_controller.js index d91c22b..311f402 100644 --- a/backend/controllers/communication_controller.js +++ b/backend/controllers/communication_controller.js @@ -6,22 +6,23 @@ exports.sendMessage = async (req, res) => { // Create and persist the message const msg = await Message.sendMessage(conversationId, { from, to, content, type, file }); - + // Stream tokenized parts over SSE if a broadcast function is available if (global.broadcast) { const tokens = (msg.content || '').split(/\s+/); tokens.forEach((token) => { global.broadcast('message', { type: 'token', id: msg.id, token }, conversationId); }); - + // Send the final message object after streaming tokens global.broadcast('message', { type: 'message', message: msg }, conversationId); - - // Fallback / additional emitter used elsewhere in the codebase + } + + // Fallback / additional emitter used elsewhere in the codebase if (global.emitMessage) { global.emitMessage(conversationId, msg); - } + res.status(201).json(msg); };