Исправление нестабильности HTTP соединения
This commit is contained in:
@@ -150,7 +150,7 @@ export function MessageImage(props: AttachmentProps) {
|
|||||||
</Box>
|
</Box>
|
||||||
</Flex>
|
</Flex>
|
||||||
</Portal>}
|
</Portal>}
|
||||||
{(props.delivered == DeliveredMessageState.ERROR || (props.delivered != DeliveredMessageState.DELIVERED &&
|
{(props.delivered == DeliveredMessageState.ERROR || error || (props.delivered != DeliveredMessageState.DELIVERED &&
|
||||||
!isMessageDeliveredByTime(props.timestamp || 0, props.attachments.length)
|
!isMessageDeliveredByTime(props.timestamp || 0, props.attachments.length)
|
||||||
)) && (
|
)) && (
|
||||||
<Overlay center h={'100%'} radius={8} color="#000" opacity={0.85}>
|
<Overlay center h={'100%'} radius={8} color="#000" opacity={0.85}>
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ export function useAttachment(attachment: Attachment, parentMessage: MessageProp
|
|||||||
const publicKey = usePublicKey();
|
const publicKey = usePublicKey();
|
||||||
const privatePlain = usePrivatePlain();
|
const privatePlain = usePrivatePlain();
|
||||||
const {updateAttachmentInDialogCache} = useDialogsCache();
|
const {updateAttachmentInDialogCache} = useDialogsCache();
|
||||||
const {info} = useConsoleLogger('useAttachment');
|
const { info, error } = useConsoleLogger('useAttachment');
|
||||||
const {updateAttachmentsInMessagesByAttachmentId} = useDialog();
|
const {updateAttachmentsInMessagesByAttachmentId} = useDialog();
|
||||||
const {getDownloadsPath} = useCore();
|
const {getDownloadsPath} = useCore();
|
||||||
const {hasGroup} = useGroups();
|
const {hasGroup} = useGroups();
|
||||||
@@ -137,8 +137,7 @@ export function useAttachment(attachment: Attachment, parentMessage: MessageProp
|
|||||||
downloadedBlob = await downloadFile(attachment.id,
|
downloadedBlob = await downloadFile(attachment.id,
|
||||||
downloadTag, attachment.transport.transport_server);
|
downloadTag, attachment.transport.transport_server);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.info(e);
|
error("Error downloading attachment: " + attachment.id);
|
||||||
info("Error downloading attachment: " + attachment.id);
|
|
||||||
setDownloadStatus(DownloadStatus.ERROR);
|
setDownloadStatus(DownloadStatus.ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export function usePrepareAttachment() {
|
|||||||
const {uploadFile} = useTransport();
|
const {uploadFile} = useTransport();
|
||||||
const {updateDialog} = useDialogsList();
|
const {updateDialog} = useDialogsList();
|
||||||
const {runQuery, getQuery} = useDatabase();
|
const {runQuery, getQuery} = useDatabase();
|
||||||
const {info} = useConsoleLogger('usePrepareAttachment');
|
const {info, error} = useConsoleLogger('usePrepareAttachment');
|
||||||
const {getDialogCache} = useDialogsCache();
|
const {getDialogCache} = useDialogsCache();
|
||||||
const context = useContext(DialogContext);
|
const context = useContext(DialogContext);
|
||||||
const transportServer = useTransportServer();
|
const transportServer = useTransportServer();
|
||||||
@@ -197,11 +197,19 @@ export function usePrepareAttachment() {
|
|||||||
const upid = attachment.id;
|
const upid = attachment.id;
|
||||||
info(`Uploading attachment with upid: ${upid}`);
|
info(`Uploading attachment with upid: ${upid}`);
|
||||||
info(`Attachment content length: ${content.length}`);
|
info(`Attachment content length: ${content.length}`);
|
||||||
let tag = await uploadFile(upid, content);
|
let tag = await uploadFile(upid, content).catch(() => {
|
||||||
info(`Uploaded attachment with upid: ${upid}, received tag: ${tag}`);
|
error(`Network error while uploading attachment ${upid}`);
|
||||||
if(intervalsRef.current != null){
|
});
|
||||||
clearInterval(intervalsRef.current);
|
if(!tag){
|
||||||
|
/**
|
||||||
|
* При ошибке загрузки по сети
|
||||||
|
*/
|
||||||
|
stopUpdateTimeInUpAttachment();
|
||||||
|
console.info("stop upd")
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
info(`Uploaded attachment with upid: ${upid}, received tag: ${tag}`);
|
||||||
|
stopUpdateTimeInUpAttachment();
|
||||||
const preparedAttachment : Attachment = {
|
const preparedAttachment : Attachment = {
|
||||||
...attachment,
|
...attachment,
|
||||||
transport: {
|
transport: {
|
||||||
@@ -220,6 +228,12 @@ export function usePrepareAttachment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const stopUpdateTimeInUpAttachment = () => {
|
||||||
|
if(intervalsRef.current != null){
|
||||||
|
clearInterval(intervalsRef.current);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
prepareAttachmentsToSend
|
prepareAttachmentsToSend
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,7 +148,10 @@ export function useDialog() : {
|
|||||||
console.info("Sending key for message ", key.toString('hex'));
|
console.info("Sending key for message ", key.toString('hex'));
|
||||||
console.info(attachemnts);
|
console.info(attachemnts);
|
||||||
let preparedToNetworkSendAttachements : Attachment[] = await prepareAttachmentsToSend(messageId, dialog, key.toString('hex'), 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]);
|
runQuery("UPDATE messages SET delivered = ? WHERE message_id = ?", [DeliveredMessageState.ERROR, messageId]);
|
||||||
updateDialog(dialog);
|
updateDialog(dialog);
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user