Синхронизация и фикс двойного сокета

This commit is contained in:
RoyceDa
2026-02-08 18:14:32 +02:00
parent 44e8d685df
commit 350e10676c
4 changed files with 19 additions and 9 deletions

3
.gitignore vendored
View File

@@ -11,4 +11,5 @@ LICENSE
.env.local .env.local
.env.development.local .env.development.local
.env.test.local .env.test.local
.env.production.local .env.production.local
app/servers.ts

View File

@@ -437,16 +437,17 @@ export function useDialogFiber() {
return; return;
} }
const fromPublicKey = packet.getFromPublicKey(); const fromPublicKey = packet.getFromPublicKey();
const toPublicKey = packet.getToPublicKey();
if(fromPublicKey != publicKey){ if(fromPublicKey != publicKey){
/** /**
* Игнорируем если это не наше прочтение * Игнорируем если это не синхронизация нашего прочтения
*/ */
return; return;
} }
const toPublicKey = packet.getToPublicKey();
await runQuery(`UPDATE messages SET read = 1 WHERE from_public_key = ? AND to_public_key = ? AND account = ?`, 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); updateDialog(toPublicKey);
log("Read sync packet from other device"); log("Read sync packet from other device");
addOrUpdateDialogCache(fromPublicKey, getDialogCache(fromPublicKey).map((message) => { addOrUpdateDialogCache(fromPublicKey, getDialogCache(fromPublicKey).map((message) => {
@@ -460,7 +461,7 @@ export function useDialogFiber() {
} }
return message; return message;
})); }));
}, [updateDialog]); }, [updateDialog, publicKey]);
/** /**
* Обработчик прочтения личных сообщений * Обработчик прочтения личных сообщений
@@ -475,6 +476,13 @@ export function useDialogFiber() {
} }
const fromPublicKey = packet.getFromPublicKey(); const fromPublicKey = packet.getFromPublicKey();
const toPublicKey = packet.getToPublicKey(); 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]); await runQuery(`UPDATE messages SET read = 1 WHERE from_public_key = ? AND to_public_key = ? AND account = ?`, [toPublicKey, fromPublicKey, publicKey]);
updateDialog(fromPublicKey); updateDialog(fromPublicKey);
log("Read packet received from " + fromPublicKey + " for " + toPublicKey); log("Read packet received from " + fromPublicKey + " for " + toPublicKey);
@@ -489,7 +497,7 @@ export function useDialogFiber() {
} }
return message; return message;
})); }));
}, [updateDialog]); }, [updateDialog, publicKey]);
/** /**
* Обработчик прочтения групповых сообщений * Обработчик прочтения групповых сообщений
*/ */

View File

@@ -43,7 +43,7 @@ export default class Protocol extends EventEmitter {
super(); super();
this.serverAddress = serverAddress; this.serverAddress = serverAddress;
this.loadAllSupportedPackets(); this.loadAllSupportedPackets();
this.connect(); //this.connect();
let _this = this; let _this = this;
this.waitPacket(0x00, (packet : PacketHandshake) => { this.waitPacket(0x00, (packet : PacketHandshake) => {

View File

@@ -1,6 +1,7 @@
export const SERVERS = [ export const SERVERS = [
//'wss://cdn.rosetta-im.com', //'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 { export function selectServer(): string {