Can delete conversation messages

This commit is contained in:
Pierre HUBERT 2019-01-11 17:57:55 +01:00
parent 41354be949
commit f8e8454b86
3 changed files with 87 additions and 0 deletions

View File

@ -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;
}

View File

@ -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,

View File

@ -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
*