Can change conversation image

This commit is contained in:
Pierre HUBERT 2021-03-07 14:55:00 +01:00
parent d425734810
commit 255f3b0595
3 changed files with 63 additions and 3 deletions

View File

@ -722,8 +722,36 @@ const ConvChatWindow = {
this.submitUpdateForm(conversation); 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: "<br/><br/><p><strong>" + tr("Conversation image") + ": </strong></p>"
})
// 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");
}
})
}
}, },
/** /**

View File

@ -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 * Refresh a conversation
* *

View File

@ -265,7 +265,25 @@ const ConversationsUtils = {
el.remove(); 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; ComunicWeb.components.conversations.utils = ConversationsUtils;