From 6f4e5438764f4d2b61b5b4a9d9366c9c70848b91 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 1 Apr 2020 14:19:56 +0200 Subject: [PATCH] Returns the message --- assets/js/common/ws.js | 4 ++++ assets/js/components/conversations/service.js | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/assets/js/common/ws.js b/assets/js/common/ws.js index 75553a09..7cc05614 100644 --- a/assets/js/common/ws.js +++ b/assets/js/common/ws.js @@ -190,6 +190,10 @@ class UserWebSocket { case "number_unread_conversations": SendEvent("newNumberUnreadConvs", msg.data) break; + + case "new_conv_message": + SendEvent("newConvMessage", msg.data); + break; default: console.error("WS Unspported kind of message!", msg); diff --git a/assets/js/components/conversations/service.js b/assets/js/components/conversations/service.js index 08d3f245..91d125fc 100644 --- a/assets/js/components/conversations/service.js +++ b/assets/js/components/conversations/service.js @@ -6,7 +6,7 @@ * @author Pierre HUBERT */ -ComunicWeb.components.conversations.service = { +const ConvService = { /** * @var {Object} __serviceCache The service cache @@ -130,6 +130,15 @@ ComunicWeb.components.conversations.service = { }, } +ComunicWeb.components.conversations.service = ConvService; + //Register service cache ComunicWeb.common.cacheManager.registerCacheCleaner("ComunicWeb.components.conversations.service.emptyCache"); +// Register to new messages +document.addEventListener("newConvMessage", (e) => { + const msg = e.detail; + + if(ConvService.__serviceCache.hasOwnProperty("conversation-" + msg.convID)) + ComunicWeb.components.conversations.chatWindows.addMessage(msg.convID, msg); +}) \ No newline at end of file