From 3ce0eeb509a06c7e3ecc1fd50882026b63f426cb Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 2 Apr 2020 19:30:11 +0200 Subject: [PATCH] Connect to message update events --- assets/js/common/ws.js | 4 +++ .../components/conversations/chatWindows.js | 27 +++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/assets/js/common/ws.js b/assets/js/common/ws.js index d27ce050..bc2c6d5f 100644 --- a/assets/js/common/ws.js +++ b/assets/js/common/ws.js @@ -198,6 +198,10 @@ class UserWebSocket { SendEvent("newConvMessage", msg.data); break; + case "updated_conv_message": + SendEvent("updatedConvMessage", msg.data); + break; + case "new_comment": SendEvent("new_comment", msg.data); break; diff --git a/assets/js/components/conversations/chatWindows.js b/assets/js/components/conversations/chatWindows.js index 0a087efc..b1f11968 100644 --- a/assets/js/components/conversations/chatWindows.js +++ b/assets/js/components/conversations/chatWindows.js @@ -995,11 +995,15 @@ const ConvChatWindow = { updateLink.addEventListener("click", function(){ ComunicWeb.components.conversations.messageEditor.open(message, function(newContent){ + /* + + DEPRECATED WITH WEBSOCKETS + //Apply and parse new message textMessage.innerHTML = removeHtmlTags(newContent); ComunicWeb.components.textParser.parse({ element: textMessage, - }); + });*/ }); }); @@ -1165,4 +1169,23 @@ const ConvChatWindow = { ComunicWeb.components.conversations.chatWindows = ConvChatWindow; //Register conversations cache cleaning function -ComunicWeb.common.cacheManager.registerCacheCleaner("ComunicWeb.components.conversations.chatWindows.unloadAll"); \ No newline at end of file +ComunicWeb.common.cacheManager.registerCacheCleaner("ComunicWeb.components.conversations.chatWindows.unloadAll"); + +// Register to messages update events +document.addEventListener("updatedConvMessage", (e) => { + const msg = e.detail; + + // Get message target + const target = document.querySelector("[data-chatwin-msg-id='"+msg.ID+"']"); + if(!target) + return; + + + // Get conversation info + const convInfo = ConvChatWindow.__conversationsCache["conversation-"+msg.convID]; + if(!convInfo) + return; + + + target.replaceWith(ConvChatWindow._get_message_element(convInfo, msg).rootElem) +}); \ No newline at end of file