diff --git a/.gitignore b/.gitignore index 1eb4509..ad8f2d6 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ LICENSE .env.local .env.development.local .env.test.local -.env.production.local \ No newline at end of file +.env.production.local +app/servers.ts \ No newline at end of file diff --git a/app/providers/DialogProvider/useDialogFiber.ts b/app/providers/DialogProvider/useDialogFiber.ts index d3619e5..ef06848 100644 --- a/app/providers/DialogProvider/useDialogFiber.ts +++ b/app/providers/DialogProvider/useDialogFiber.ts @@ -437,16 +437,17 @@ export function useDialogFiber() { return; } const fromPublicKey = packet.getFromPublicKey(); + const toPublicKey = packet.getToPublicKey(); if(fromPublicKey != publicKey){ /** - * Игнорируем если это не наше прочтение + * Игнорируем если это не синхронизация нашего прочтения */ return; } - - const toPublicKey = packet.getToPublicKey(); await runQuery(`UPDATE messages SET read = 1 WHERE from_public_key = ? AND to_public_key = ? AND account = ?`, - [toPublicKey, fromPublicKey, publicKey]); + [fromPublicKey, toPublicKey, publicKey]); + + console.info("updating with params ", [fromPublicKey, toPublicKey, publicKey]); updateDialog(toPublicKey); log("Read sync packet from other device"); addOrUpdateDialogCache(fromPublicKey, getDialogCache(fromPublicKey).map((message) => { @@ -460,7 +461,7 @@ export function useDialogFiber() { } return message; })); - }, [updateDialog]); + }, [updateDialog, publicKey]); /** * Обработчик прочтения личных сообщений @@ -475,6 +476,13 @@ export function useDialogFiber() { } const fromPublicKey = packet.getFromPublicKey(); const toPublicKey = packet.getToPublicKey(); + if(fromPublicKey == publicKey){ + /** + * Игнорируем если это наше прочтение + * которое получается при синхронизации + */ + return; + } 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); @@ -489,7 +497,7 @@ export function useDialogFiber() { } return message; })); - }, [updateDialog]); + }, [updateDialog, publicKey]); /** * Обработчик прочтения групповых сообщений */ diff --git a/app/providers/ProtocolProvider/protocol/protocol.ts b/app/providers/ProtocolProvider/protocol/protocol.ts index fb3a4b8..4874ef3 100644 --- a/app/providers/ProtocolProvider/protocol/protocol.ts +++ b/app/providers/ProtocolProvider/protocol/protocol.ts @@ -43,7 +43,7 @@ export default class Protocol extends EventEmitter { super(); this.serverAddress = serverAddress; this.loadAllSupportedPackets(); - this.connect(); + //this.connect(); let _this = this; this.waitPacket(0x00, (packet : PacketHandshake) => { diff --git a/app/servers.ts b/app/servers.ts index 406c14d..a736df8 100644 --- a/app/servers.ts +++ b/app/servers.ts @@ -1,6 +1,7 @@ export const SERVERS = [ //'wss://cdn.rosetta-im.com', - 'ws://10.211.55.2:3000' + //'ws://10.211.55.2:3000', + 'ws://127.0.0.1:8881' ]; export function selectServer(): string {