From 2d6878f1587c9e65dac4c5a24f59d290bfadb970 Mon Sep 17 00:00:00 2001 From: Asish Kumar Date: Thu, 9 Apr 2026 17:52:00 +0000 Subject: [PATCH] fix(chat): prevent sending messages before file uploads finish --- app/components/base/file-uploader-in-attachment/utils.ts | 2 +- app/components/chat/index.tsx | 6 ++++++ i18n/lang/app.en.ts | 2 ++ i18n/lang/app.es.ts | 2 ++ i18n/lang/app.fr.ts | 2 ++ i18n/lang/app.ja.ts | 2 ++ i18n/lang/app.vi.ts | 2 ++ i18n/lang/app.zh.ts | 1 + 8 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/components/base/file-uploader-in-attachment/utils.ts b/app/components/base/file-uploader-in-attachment/utils.ts index 3a0a22c..da147bb 100644 --- a/app/components/base/file-uploader-in-attachment/utils.ts +++ b/app/components/base/file-uploader-in-attachment/utils.ts @@ -97,7 +97,7 @@ export const getSupportFileType = (fileName: string, fileMimetype: string, isCus } export const getProcessedFiles = (files: FileEntity[]) => { - return files.filter(file => file.progress !== -1).map(fileItem => ({ + return files.filter(file => file.progress !== -1 && fileIsUploaded(file)).map(fileItem => ({ type: fileItem.supportFileType, transfer_method: fileItem.transferMethod, url: fileItem.url || '', diff --git a/app/components/chat/index.tsx b/app/components/chat/index.tsx index b5df141..fef567e 100644 --- a/app/components/chat/index.tsx +++ b/app/components/chat/index.tsx @@ -98,6 +98,12 @@ const Chat: FC = ({ const handleSend = () => { if (!valid() || (checkCanSend && !checkCanSend())) { return } + const hasPendingImageUploads = files.some(file => file.progress !== -1 && file.progress < 100) + const hasPendingAttachmentUploads = attachmentFiles.some(file => file.progress !== -1 && file.progress < 100) + if (hasPendingImageUploads || hasPendingAttachmentUploads) { + logError(t('app.errorMessage.waitForFileUpload')) + return + } const imageFiles: VisionFile[] = files.filter(file => file.progress !== -1).map(fileItem => ({ type: 'image', transfer_method: fileItem.type, diff --git a/i18n/lang/app.en.ts b/i18n/lang/app.en.ts index 02a405f..6697987 100644 --- a/i18n/lang/app.en.ts +++ b/i18n/lang/app.en.ts @@ -27,6 +27,8 @@ const translation = { valueOfVarRequired: 'Variables value can not be empty', waitForResponse: 'Please wait for the response to the previous message to complete.', + waitForFileUpload: + 'Please wait for all files to finish uploading before sending.', }, variableTable: { optional: 'Optional', diff --git a/i18n/lang/app.es.ts b/i18n/lang/app.es.ts index 5a7e363..650d9f1 100644 --- a/i18n/lang/app.es.ts +++ b/i18n/lang/app.es.ts @@ -27,6 +27,8 @@ const translation = { valueOfVarRequired: 'El valor de las variables no puede estar vacío', waitForResponse: 'Por favor espere a que la respuesta al mensaje anterior se complete.', + waitForFileUpload: + 'Espere a que todos los archivos terminen de cargarse antes de enviar.', }, } diff --git a/i18n/lang/app.fr.ts b/i18n/lang/app.fr.ts index b69fd03..318e859 100644 --- a/i18n/lang/app.fr.ts +++ b/i18n/lang/app.fr.ts @@ -27,6 +27,8 @@ const translation = { valueOfVarRequired: 'La valeur des variables ne peut pas être vide', waitForResponse: 'Veuillez attendre que la réponse au message précédent soit terminée.', + waitForFileUpload: + 'Veuillez attendre la fin du téléversement de tous les fichiers avant l’envoi.', }, variableTable: { optional: 'Facultatif', diff --git a/i18n/lang/app.ja.ts b/i18n/lang/app.ja.ts index d3115e5..8b036b4 100644 --- a/i18n/lang/app.ja.ts +++ b/i18n/lang/app.ja.ts @@ -27,6 +27,8 @@ const translation = { valueOfVarRequired: '変数の値は空にできません', waitForResponse: '前のメッセージの応答が完了するまでお待ちください。', + waitForFileUpload: + 'すべてのファイルのアップロードが完了してから送信してください。', }, variableTable: { optional: '任意', diff --git a/i18n/lang/app.vi.ts b/i18n/lang/app.vi.ts index 1920b58..c57e4cc 100644 --- a/i18n/lang/app.vi.ts +++ b/i18n/lang/app.vi.ts @@ -27,6 +27,8 @@ const translation = { valueOfVarRequired: 'Giá trị của biến không thể để trống', waitForResponse: 'Vui lòng đợi phản hồi từ tin nhắn trước khi gửi tin nhắn mới.', + waitForFileUpload: + 'Vui lòng đợi tất cả tệp tải lên xong trước khi gửi.', }, variableTable: { optional: 'Tùy chọn', diff --git a/i18n/lang/app.zh.ts b/i18n/lang/app.zh.ts index c03b8fc..974e3d4 100644 --- a/i18n/lang/app.zh.ts +++ b/i18n/lang/app.zh.ts @@ -22,6 +22,7 @@ const translation = { errorMessage: { valueOfVarRequired: '变量值必填', waitForResponse: '请等待上条信息响应完成', + waitForFileUpload: '请等待所有文件上传完成后再发送', }, variableTable: { optional: '可选',