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 (