From c762e527c27bbdbf3867dd01d8656aa4daabacd2 Mon Sep 17 00:00:00 2001 From: Royce59 Date: Sat, 11 Apr 2026 21:03:32 +0200 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=B5=D1=81=D1=82=D0=B0=D0=B1?= =?UTF-8?q?=D0=B8=D0=BB=D1=8C=D0=BD=D0=BE=D1=81=D1=82=D0=B8=20HTTP=20?= =?UTF-8?q?=D1=81=D0=BE=D0=B5=D0=B4=D0=B8=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MessageAttachments/MessageImage.tsx | 2 +- .../AttachmentProvider/useAttachment.ts | 5 ++-- .../usePrepareAttachment.ts | 24 +++++++++++++++---- app/providers/DialogProvider/useDialog.ts | 5 +++- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/app/components/MessageAttachments/MessageImage.tsx b/app/components/MessageAttachments/MessageImage.tsx index a035d06..bc664b2 100644 --- a/app/components/MessageAttachments/MessageImage.tsx +++ b/app/components/MessageAttachments/MessageImage.tsx @@ -150,7 +150,7 @@ export function MessageImage(props: AttachmentProps) { } - {(props.delivered == DeliveredMessageState.ERROR || (props.delivered != DeliveredMessageState.DELIVERED && + {(props.delivered == DeliveredMessageState.ERROR || error || (props.delivered != DeliveredMessageState.DELIVERED && !isMessageDeliveredByTime(props.timestamp || 0, props.attachments.length) )) && ( diff --git a/app/providers/AttachmentProvider/useAttachment.ts b/app/providers/AttachmentProvider/useAttachment.ts index 37d6277..97dbd14 100644 --- a/app/providers/AttachmentProvider/useAttachment.ts +++ b/app/providers/AttachmentProvider/useAttachment.ts @@ -36,7 +36,7 @@ export function useAttachment(attachment: Attachment, parentMessage: MessageProp const publicKey = usePublicKey(); const privatePlain = usePrivatePlain(); const {updateAttachmentInDialogCache} = useDialogsCache(); - const {info} = useConsoleLogger('useAttachment'); + const { info, error } = useConsoleLogger('useAttachment'); const {updateAttachmentsInMessagesByAttachmentId} = useDialog(); const {getDownloadsPath} = useCore(); const {hasGroup} = useGroups(); @@ -137,8 +137,7 @@ export function useAttachment(attachment: Attachment, parentMessage: MessageProp downloadedBlob = await downloadFile(attachment.id, downloadTag, attachment.transport.transport_server); } catch (e) { - console.info(e); - info("Error downloading attachment: " + attachment.id); + error("Error downloading attachment: " + attachment.id); setDownloadStatus(DownloadStatus.ERROR); return; } diff --git a/app/providers/AttachmentProvider/usePrepareAttachment.ts b/app/providers/AttachmentProvider/usePrepareAttachment.ts index afdc9c9..59ad705 100644 --- a/app/providers/AttachmentProvider/usePrepareAttachment.ts +++ b/app/providers/AttachmentProvider/usePrepareAttachment.ts @@ -17,7 +17,7 @@ export function usePrepareAttachment() { const {uploadFile} = useTransport(); const {updateDialog} = useDialogsList(); const {runQuery, getQuery} = useDatabase(); - const {info} = useConsoleLogger('usePrepareAttachment'); + const {info, error} = useConsoleLogger('usePrepareAttachment'); const {getDialogCache} = useDialogsCache(); const context = useContext(DialogContext); const transportServer = useTransportServer(); @@ -197,11 +197,19 @@ export function usePrepareAttachment() { const upid = attachment.id; info(`Uploading attachment with upid: ${upid}`); info(`Attachment content length: ${content.length}`); - let tag = await uploadFile(upid, content); - info(`Uploaded attachment with upid: ${upid}, received tag: ${tag}`); - if(intervalsRef.current != null){ - clearInterval(intervalsRef.current); + let tag = await uploadFile(upid, content).catch(() => { + error(`Network error while uploading attachment ${upid}`); + }); + if(!tag){ + /** + * При ошибке загрузки по сети + */ + stopUpdateTimeInUpAttachment(); + console.info("stop upd") + continue; } + info(`Uploaded attachment with upid: ${upid}, received tag: ${tag}`); + stopUpdateTimeInUpAttachment(); const preparedAttachment : Attachment = { ...attachment, transport: { @@ -220,6 +228,12 @@ export function usePrepareAttachment() { } } + const stopUpdateTimeInUpAttachment = () => { + if(intervalsRef.current != null){ + clearInterval(intervalsRef.current); + } + } + return { prepareAttachmentsToSend } diff --git a/app/providers/DialogProvider/useDialog.ts b/app/providers/DialogProvider/useDialog.ts index b5040df..f7f3901 100644 --- a/app/providers/DialogProvider/useDialog.ts +++ b/app/providers/DialogProvider/useDialog.ts @@ -148,7 +148,10 @@ export function useDialog() : { console.info("Sending key for message ", key.toString('hex')); console.info(attachemnts); let preparedToNetworkSendAttachements : Attachment[] = await prepareAttachmentsToSend(messageId, dialog, key.toString('hex'), attachemnts); - if(attachemnts.length <= 0 && message.trim() == ""){ + if(preparedToNetworkSendAttachements.length < attachemnts.length){ + /** + * Если не удалось нормально загрузить все вложения - тогда не отправляем сообщение + */ runQuery("UPDATE messages SET delivered = ? WHERE message_id = ?", [DeliveredMessageState.ERROR, messageId]); updateDialog(dialog); return;