diff --git a/assets/js/common/ws.js b/assets/js/common/ws.js index 4093a080..e915205e 100644 --- a/assets/js/common/ws.js +++ b/assets/js/common/ws.js @@ -202,6 +202,10 @@ class UserWebSocket { SendEvent("new_comment", msg.data); break; + case "comment_updated": + SendEvent("commentUpdated", msg.data); + break; + default: console.error("WS Unspported kind of message!", msg); break; diff --git a/assets/js/components/comments/editor.js b/assets/js/components/comments/editor.js index 42eb2f9f..6dec7681 100644 --- a/assets/js/components/comments/editor.js +++ b/assets/js/components/comments/editor.js @@ -29,10 +29,6 @@ ComunicWeb.components.comments.editor = { ComunicWeb.common.notificationSystem.showNotification(lang("comments_editor_err_update"), "danger"); return; } - - //Else perform next actions - //Reload the comment - ComunicWeb.components.comments.actions.reload(infos.ID, root); }); } diff --git a/assets/js/components/comments/ui.js b/assets/js/components/comments/ui.js index 34752e1d..e44e288f 100644 --- a/assets/js/components/comments/ui.js +++ b/assets/js/components/comments/ui.js @@ -112,6 +112,9 @@ const CommentsUI = { emptyElem(target); var commentContainer = target; } + + // Save comment ID for later use + commentContainer.setAttribute("data-comment-id", infos.ID) //Add user image @@ -312,4 +315,15 @@ document.addEventListener("new_comment", async (e) => { }); CommentsUI._show_comment(comment, await userInfo(comment.userID), newCommentTarget) +}) + +// Register to comments updates events +document.addEventListener("commentUpdated", async (e) => { + const comment = e.detail; + const target = document.querySelector("[data-comment-id='"+comment.ID+"']"); + + if(target == null) + return; + + CommentsUI._show_comment(comment, await userInfo(comment.userID), target) }) \ No newline at end of file