From 76b435ee7637af708373ca4fd7a86be3fa9ce948 Mon Sep 17 00:00:00 2001 From: RoyceDa Date: Sat, 31 Jan 2026 22:27:36 +0200 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B8=D0=BD=D1=85=D1=80=D0=BE=D0=BD?= =?UTF-8?q?=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D1=81=D0=BE=D0=BE=D0=B1?= =?UTF-8?q?=D1=89=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=B2=20=D0=B0=D0=BA=D1=82?= =?UTF-8?q?=D0=B8=D0=B2=D0=BD=D0=BE=D0=BC=20=D0=B4=D0=B8=D0=B0=D0=BB=D0=BE?= =?UTF-8?q?=D0=B3=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DialogProvider/DialogProvider.tsx | 54 +++++++++++++++++++ .../DialogProvider/useDialogFiber.ts | 2 - 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/app/providers/DialogProvider/DialogProvider.tsx b/app/providers/DialogProvider/DialogProvider.tsx index 70c6c94..ef383fb 100644 --- a/app/providers/DialogProvider/DialogProvider.tsx +++ b/app/providers/DialogProvider/DialogProvider.tsx @@ -350,6 +350,60 @@ export function DialogProvider(props: DialogProviderProps) { })); }, [props.dialog]); + /** + * Нам приходят сообщения от себя самих же при синхронизации + * нужно обрабатывать их особым образом соотвественно + * + * Метод нужен для синхронизации своих сообщений + */ + usePacket(0x06, async (packet: PacketMessage) => { + const fromPublicKey = packet.getFromPublicKey(); + const toPublicKey = packet.getToPublicKey(); + const aesChachaKey = packet.getAesChachaKey(); + const content = packet.getContent(); + const timestamp = packet.getTimestamp(); + const messageId = packet.getMessageId(); + + + if(fromPublicKey != publicKey){ + /** + * Игнорируем если это не сообщение от нас + */ + return; + } + const chachaDecryptedKey = Buffer.from(await decodeWithPassword(privatePlain, aesChachaKey), "binary"); + const key = chachaDecryptedKey.slice(0, 32); + const nonce = chachaDecryptedKey.slice(32); + const decryptedContent = await chacha20Decrypt(content, nonce.toString('hex'), key.toString('hex')); + + let attachments: Attachment[] = []; + for(let i = 0; i < packet.getAttachments().length; i++) { + const attachment = packet.getAttachments()[i]; + attachments.push({ + id: attachment.id, + preview: attachment.preview, + type: attachment.type, + blob: attachment.type == AttachmentType.MESSAGES ? await decodeWithPassword(chachaDecryptedKey.toString('utf-8'), attachment.blob) : "" + }); + } + + const newMessage: Message = { + from_public_key: fromPublicKey, + to_public_key: toPublicKey, + content: content, + timestamp: timestamp, + readed: 0, //сообщение прочитано + chacha_key: chachaDecryptedKey.toString('utf-8'), + from_me: 1, //сообщение от нас + plain_message: (decryptedContent as string), + delivered: DeliveredMessageState.DELIVERED, + message_id: messageId, + attachments: attachments + }; + + setMessages((prev) => ([...prev, newMessage])); + }, [privatePlain]); + /** * Обработчик для личных сообщений */ diff --git a/app/providers/DialogProvider/useDialogFiber.ts b/app/providers/DialogProvider/useDialogFiber.ts index 26e08eb..8daa29a 100644 --- a/app/providers/DialogProvider/useDialogFiber.ts +++ b/app/providers/DialogProvider/useDialogFiber.ts @@ -18,7 +18,6 @@ import { PacketRead } from "../ProtocolProvider/protocol/packets/packet.read"; import { PacketDelivery } from "../ProtocolProvider/protocol/packets/packet.delivery"; import { useConsoleLogger } from "@/app/hooks/useConsoleLogger"; import { useViewPanelsState, ViewPanelsState } from "@/app/hooks/useViewPanelsState"; -import { generateRandomKeyFormSeed } from "@/app/utils/utils"; import { useFileStorage } from "@/app/hooks/useFileStorage"; import { useDialogsList } from "../DialogListProvider/useDialogsList"; import { useGroups } from "./useGroups"; @@ -58,7 +57,6 @@ export function useDialogFiber() { info("Starting passive fiber for dialog packets"); }, []); - /** * Нам приходят сообщения от себя самих же при синхронизации * нужно обрабатывать их особым образом соотвественно