Allow paste file and images into chat input form

7fe329b5cf2f6ea98bce8896a0d00992705fbecc

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +23 -5Showing whitespace changes
public/scripts/chats.js+23 -5
@@ -319,12 +319,10 @@ export function hasPendingFileAttachment() {
319319
320/**320/**
321 * Displays file information in the message sending form.321 * Displays file information in the message sending form.
322 * @param {File} file File object
322 * @returns {Promise<void>}323 * @returns {Promise<void>}
323 */324 */
324async function onFileAttach() {325async function onFileAttach(file) {
325 const fileInput = document.getElementById('file_form_input');
326 if (!(fileInput instanceof HTMLInputElement)) return;
327 const file = fileInput.files[0];
328 if (!file) return;326 if (!file) return;
329327
330 const isValid = await validateFile(file);328 const isValid = await validateFile(file);
@@ -1503,8 +1501,28 @@ jQuery(function () {
1503 $(document).on('click', '.mes_img_enlarge', enlargeMessageImage);1501 $(document).on('click', '.mes_img_enlarge', enlargeMessageImage);
1504 $(document).on('click', '.mes_img_delete', deleteMessageImage);1502 $(document).on('click', '.mes_img_delete', deleteMessageImage);
15051503
1506 $('#file_form_input').on('change', onFileAttach);1504 $('#file_form_input').on('change', async () => {
1505 const fileInput = document.getElementById('file_form_input');
1506 if (!(fileInput instanceof HTMLInputElement)) return;
1507 const file = fileInput.files[0];
1508 await onFileAttach(file);
1509 });
1507 $('#file_form').on('reset', function () {1510 $('#file_form').on('reset', function () {
1508 $('#file_form').addClass('displayNone');1511 $('#file_form').addClass('displayNone');
1509 });1512 });
1513
1514 document.getElementById('send_textarea').addEventListener('paste', async function (event) {
1515 if (event.clipboardData.files.length === 0) {
1516 return;
1517 }
1518
1519 event.preventDefault();
1520 event.stopPropagation();
1521
1522 const fileInput = document.getElementById('file_form_input');
1523 if (!(fileInput instanceof HTMLInputElement)) return;
1524
1525 fileInput.files = event.clipboardData.files;
1526 await onFileAttach(fileInput.files[0]);
1527 });
1510});1528});