mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-12-24 09:58:51 +00:00
Can change conversation image
This commit is contained in:
parent
d425734810
commit
255f3b0595
@ -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: "<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");
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user