From 6a76061399ef9cde93619a8e85e2b6a66b384d51 Mon Sep 17 00:00:00 2001 From: RoyceDa Date: Fri, 13 Feb 2026 17:13:21 +0200 Subject: [PATCH] =?UTF-8?q?=D0=A2=D0=B5=D1=81=D1=82=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=8F=20=D1=81=D0=B8=D0=BD=D1=85=D1=80=D0=BE=D0=BD=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DialogProvider/useDialogFiber.ts | 5 ++- .../ProtocolProvider/ProtocolProvider.tsx | 38 +++++++++++++------ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/app/providers/DialogProvider/useDialogFiber.ts b/app/providers/DialogProvider/useDialogFiber.ts index ef06848..dc26e69 100644 --- a/app/providers/DialogProvider/useDialogFiber.ts +++ b/app/providers/DialogProvider/useDialogFiber.ts @@ -444,8 +444,10 @@ export function useDialogFiber() { */ return; } + console.info("PACKED_READ_SYNC"); + debugger; await runQuery(`UPDATE messages SET read = 1 WHERE from_public_key = ? AND to_public_key = ? AND account = ?`, - [fromPublicKey, toPublicKey, publicKey]); + [toPublicKey, fromPublicKey, publicKey]); console.info("updating with params ", [fromPublicKey, toPublicKey, publicKey]); updateDialog(toPublicKey); @@ -483,6 +485,7 @@ export function useDialogFiber() { */ return; } + console.info("PACKED_READ_IM"); await runQuery(`UPDATE messages SET read = 1 WHERE from_public_key = ? AND to_public_key = ? AND account = ?`, [toPublicKey, fromPublicKey, publicKey]); updateDialog(fromPublicKey); log("Read packet received from " + fromPublicKey + " for " + toPublicKey); diff --git a/app/providers/ProtocolProvider/ProtocolProvider.tsx b/app/providers/ProtocolProvider/ProtocolProvider.tsx index 4806c63..926ef70 100644 --- a/app/providers/ProtocolProvider/ProtocolProvider.tsx +++ b/app/providers/ProtocolProvider/ProtocolProvider.tsx @@ -45,8 +45,7 @@ export function ProtocolProvider(props : ProtocolProviderProps) { deviceOs: systemInfo.os } protocol.connect(); - //protocol.startHandshakeExchange(publicKey, privateKey, device); - protocol.on('connect', () => { + const connect = () => { console.info("Connected to server, starting handshake exchange"); protocol.startHandshakeExchange(publicKey, privateKey, device); /** @@ -54,24 +53,41 @@ export function ProtocolProvider(props : ProtocolProviderProps) { * так как при переподключении они слетают */ setOnlineSubscribes([]); - }); - protocol.on('reconnect', () => { + } + const reconnect = () => { log("Connection lost, reconnecting and starting handshake exchange"); setConnect(ProtocolState.RECONNECTING); - }); - protocol.on('handshake_start', () => { + } + const handshake_start = () => { log("Handshake exchange started"); setConnect(ProtocolState.HANDSHAKE_EXCHANGE); - }); - protocol.on('handshake_complete', () => { + } + const handshake_complete = () => { log("Handshake exchange complete"); setConnect(ProtocolState.CONNECTED); - }); - protocol.on('handshake_need_device_verification', () => { + } + const handshake_need_device_verification = () => { log("Handshake exchange needs device verification"); setConnect(ProtocolState.DEVICE_VERIFICATION_REQUIRED); navigate('/deviceconfirm'); - }); + } + protocol.on('connect', connect); + protocol.on('reconnect', reconnect); + protocol.on('handshake_start', handshake_start); + protocol.on('handshake_complete', handshake_complete); + protocol.on('handshake_need_device_verification', handshake_need_device_verification); + + return () => { + /** + * Отключаем все обработчики событий при размонтировании компонента, чтобы избежать + * утечек памяти и некорректного поведения при повторном монтировании + */ + protocol.off('connect', connect); + protocol.off('reconnect', reconnect); + protocol.off('handshake_start', handshake_start); + protocol.off('handshake_complete', handshake_complete); + protocol.off('handshake_need_device_verification', handshake_need_device_verification); + } }, [publicKey, privateKey, systemInfo.id]); return (