From 0d02241b46a19bccbcd5ffdeeb1249f242bd66db Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Fri, 4 Jul 2014 13:20:30 +0100 Subject: [PATCH] linked chat into the editor real time contorller --- .../app/coffee/Features/Chat/ChatController.coffee | 6 ++++-- .../UnitTests/coffee/Chat/ChatControllerTests.coffee | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/services/web/app/coffee/Features/Chat/ChatController.coffee b/services/web/app/coffee/Features/Chat/ChatController.coffee index 11393f986d..7d847d55b1 100644 --- a/services/web/app/coffee/Features/Chat/ChatController.coffee +++ b/services/web/app/coffee/Features/Chat/ChatController.coffee @@ -1,11 +1,13 @@ ChatHandler = require("./ChatHandler") +EditorRealTimeController = require("../Editor/EditorRealTimeController") module.exports = sendMessage: (project_id, user_id, messageContent, callback)-> - ChatHandler.sendMessage project_id, user_id, messageContent, (err)-> - callback() + ChatHandler.sendMessage project_id, user_id, messageContent, (err, builtMessge)-> + EditorRealTimeController.emitToRoom project_id, "new-chat-message", builtMessge, (err)-> + callback(err) getMessages: (project_id, query, callback)-> ChatHandler.getMessages project_id, query, (err)-> diff --git a/services/web/test/UnitTests/coffee/Chat/ChatControllerTests.coffee b/services/web/test/UnitTests/coffee/Chat/ChatControllerTests.coffee index 17c390ee2a..92c57e842b 100644 --- a/services/web/test/UnitTests/coffee/Chat/ChatControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Chat/ChatControllerTests.coffee @@ -15,10 +15,13 @@ describe "ChatController", -> sendMessage:sinon.stub() getMessages:sinon.stub() + @EditorRealTimeController = + emitToRoom:sinon.stub().callsArgWith(3) @ChatController = SandboxedModule.require modulePath, requires: "settings-sharelatex":@settings "logger-sharelatex": log:-> "./ChatHandler":@ChatHandler + "../Editor/EditorRealTimeController":@EditorRealTimeController @query = before:"some time" @@ -32,6 +35,15 @@ describe "ChatController", -> @ChatHandler.sendMessage.calledWith(@project_id, @user_id, @messageContent).should.equal true done() + it "should tell the editor real time controller about the update with the data from the chat handler", (done)-> + @chatMessage = + content:"hello world" + @ChatHandler.sendMessage.callsArgWith(3, null, @chatMessage) + @ChatController.sendMessage @project_id, @user_id, @messageContent, (err)=> + @EditorRealTimeController.emitToRoom.calledWith(@project_id, "new-chat-message", @chatMessage).should.equal true + done() + + describe "getMessages", -> it "should tell the chat handler about the request", (done)->