Allow paste file and images into chat input form

7fe329b5cf2f6ea98bce8896a0d00992705fbecc

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

1 files changed, +23 -5Ignore whitespace
public/scripts/chats.js+23 -5
@@ -319,12 +319,10 @@ export function hasPendingFileAttachment() {
319319
320320/**
321321 * Displays file information in the message sending form.
322+ * @param {File} file File object
322323 * @returns {Promise<void>}
323324 */
324325async function onFileAttach(file) {
325- const fileInput = document.getElementById('file_form_input');
326- if (!(fileInput instanceof HTMLInputElement)) return;
327- const file = fileInput.files[0];
328326 if (!file) return;
329327
330328 const isValid = await validateFile(file);
@@ -1503,8 +1501,28 @@ jQuery(function () {
15031501 $(document).on('click', '.mes_img_enlarge', enlargeMessageImage);
15041502 $(document).on('click', '.mes_img_delete', deleteMessageImage);
15051503
15061504 $('#file_form_input').on('change', onFileAttachasync (); => {
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+ });
15071510 $('#file_form').on('reset', function () {
15081511 $('#file_form').addClass('displayNone');
15091512 });
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+ });
15101528});