diff --git a/assets/css/components/conversations/windows.css b/assets/css/components/conversations/windows.css index 29396e8e..375fc95b 100644 --- a/assets/css/components/conversations/windows.css +++ b/assets/css/components/conversations/windows.css @@ -115,4 +115,8 @@ #conversationsElem .direct-chat-msg.not-last-message-from-user .direct-chat-img { margin-bottom: -5px; +} + +#conversationsElem .direct-chat-msg.open .dropdown-menu { + margin-top: -20px; } \ No newline at end of file diff --git a/assets/js/components/conversations/chatWindows.js b/assets/js/components/conversations/chatWindows.js index 6382c024..e7458c09 100644 --- a/assets/js/components/conversations/chatWindows.js +++ b/assets/js/components/conversations/chatWindows.js @@ -910,6 +910,68 @@ ComunicWeb.components.conversations.chatWindows = { element: textMessage, }); + + //Add message dropdown menu + messageContainer.className += " dropdown"; + + var dropdownToggle = createElem2({ + insertBefore: dateElem, + type: "i", + class: "hidden" + }); + dropdownToggle.setAttribute("data-toggle", "dropdown"); + + var dropdownMenu = createElem2({ + insertBefore: dateElem, + type: "ul", + class: "dropdown-menu" + }); + dropdownMenu.setAttribute("role", "menu"); + + messageTargetElem.addEventListener("dblclick", function(){ + $(dropdownToggle).dropdown("toggle"); + }); + + //Add message options + if(userIsPoster){ + + //Delete the message + var deleteLi = createElem2({ + type: "li", + appendTo: dropdownMenu + }); + + var deleteLink = createElem2({ + type: "a", + appendTo: deleteLi, + innerHTML: "Delete" + }); + + deleteLink.addEventListener("click", function(){ + ComunicWeb.common.messages.confirm( + "Do you really want to delete this message? The operation can not be reverted!", + function(confirm){ + if(!confirm) return; + + //Hide the message + messageTargetElem.style.display = "none"; + + //Execute the request + ComunicWeb.components.conversations.interface.DeleteSingleMessage( + message.ID, + function(result){ + if(!result){ + messageTargetElem.style.display = "block"; + notify("Could delete conversation message!", "danger"); + } + } + ); + } + ) + }); + + } + //Return information about the message return { userID: message.ID_user, diff --git a/assets/js/components/conversations/interface.js b/assets/js/components/conversations/interface.js index 3de7210c..082280cf 100644 --- a/assets/js/components/conversations/interface.js +++ b/assets/js/components/conversations/interface.js @@ -363,6 +363,27 @@ ComunicWeb.components.conversations.interface = { }, + /** + * Intend to delete a single conversation message + * + * @param {Number} messageID The ID of the message to delete + * @param {(success: Boolean) => any} callback Function to call once the + * conversation message has been deleted + */ + DeleteSingleMessage: function(messageID, callback){ + + ComunicWeb.common.api.makeAPIrequest( + "conversations/deleteMessage", + {"messageID": messageID}, + true, + + function(result){ + callback(result.error ? false : true); + } + ); + + }, + /** * Empty conversations cache *