diff --git a/assets/js/components/conversations/chatWindows.js b/assets/js/components/conversations/chatWindows.js
index 38bcb518..159792c0 100644
--- a/assets/js/components/conversations/chatWindows.js
+++ b/assets/js/components/conversations/chatWindows.js
@@ -722,8 +722,36 @@ const ConvChatWindow = {
this.submitUpdateForm(conversation);
};
- //Success
- return true;
+
+ // Add conversation image section
+ if (conversation.infos.members.find(m => m.user_id == userID()).is_admin) {
+
+ const convImageSection = createElem2({
+ appendTo: settingsForm.rootElem,
+ type: "div",
+ innerHTML: "
" + tr("Conversation image") + ":
" + }) + + + // Upload a new image + const newConvImagebutton = createElem2({ + appendTo: convImageSection, + type: "button", + class: "btn btn-default", + innerHTML: tr("Upload a new conversation image") + }); + + newConvImagebutton.addEventListener("click", async e => { + e.preventDefault(); + try { + await ConversationsUtils.uploadNewConversationImage(conversation.infos.id); + ConvChatWindow.reload(conversation) + } catch(e) { + console.error(e); + notify(tr("Failed to change conversation image!"), "danger"); + } + }) + } }, /** diff --git a/assets/js/components/conversations/interface.js b/assets/js/components/conversations/interface.js index 32ec044b..c63b415b 100644 --- a/assets/js/components/conversations/interface.js +++ b/assets/js/components/conversations/interface.js @@ -268,6 +268,20 @@ const ConversationsInterface = { } }, + /** + * Send a new conversation image + * + * @param {number} convID The ID of the target conversation + * @param {HTMLInputElement} input The file to send + */ + sendNewConversationImage: async function(convID, input) { + let fd = new FormData(); + fd.append("convID", convID); + fd.append("file", input.files[0], input.files[0].name); + + await APIClient.execFormData("conversations/change_image", fd, true) + }, + /** * Refresh a conversation * diff --git a/assets/js/components/conversations/utils.js b/assets/js/components/conversations/utils.js index 4f81bdf8..021f539a 100644 --- a/assets/js/components/conversations/utils.js +++ b/assets/js/components/conversations/utils.js @@ -265,7 +265,25 @@ const ConversationsUtils = { el.remove(); }); - } + }, + + + /** + * Upload a new conversation image + */ + uploadNewConversationImage: async function(convID) { + let input = document.createElement("input"); + input.type = "file"; + + input.click(); + + // Wait for file + await new Promise((res, rej) => input.addEventListener("change", e => res())); + + if(input.files.length == 0) return; + + await ConversationsInterface.sendNewConversationImage(convID, input); + }, } ComunicWeb.components.conversations.utils = ConversationsUtils;