From c9cff515e5d659d9706a9407f2f7b4419da0f462 Mon Sep 17 00:00:00 2001 From: RoyceDa Date: Fri, 27 Mar 2026 20:07:40 +0200 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B4=D0=B0=D1=87?= =?UTF-8?q?=D0=B0=20chachakey=20=D0=B8=20=D0=BD=D0=B0=D1=87=D0=B0=D0=BB?= =?UTF-8?q?=D0=BE=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B3=D0=BE=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=BA=D0=BE=D0=BB=D0=B0=20=D0=B2=D0=BB=D0=BE?= =?UTF-8?q?=D0=B6=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/components/Messages/Message.tsx | 5 +++-- app/providers/AttachmentProvider/useAttachment.ts | 6 +++++- app/providers/DialogProvider/DialogProvider.tsx | 12 +++++++++++- app/providers/DialogProvider/useDialog.ts | 4 ++-- app/providers/DialogProvider/useDialogFiber.ts | 14 +++++++++----- app/providers/DialogProvider/useReplyMessages.ts | 1 + 6 files changed, 31 insertions(+), 11 deletions(-) diff --git a/app/components/Messages/Message.tsx b/app/components/Messages/Message.tsx index f61d620..88bc903 100644 --- a/app/components/Messages/Message.tsx +++ b/app/components/Messages/Message.tsx @@ -103,7 +103,8 @@ export function Message(props: MessageProps) { publicKey: user.publicKey, message: props.message, attachments: props.attachments.filter(a => a.type != AttachmentType.MESSAGES), - message_id: props.message_id + message_id: props.message_id, + }; const avatars = useAvatars(user.publicKey); @@ -214,7 +215,7 @@ export function Message(props: MessageProps) { fontSize: '13px', color: messageStyle == MessageStyle.BUBBLES ? (computedTheme == 'light' ? (props.parent?.from_me ? 'white' : 'black') : 'white') : (computedTheme == 'light' ? 'black' : 'white') }} ml={props.avatar_no_render ? 50 : undefined} onDoubleClick={(e) => e.stopPropagation()}> - + diff --git a/app/providers/AttachmentProvider/useAttachment.ts b/app/providers/AttachmentProvider/useAttachment.ts index 150af5d..c2a58d4 100644 --- a/app/providers/AttachmentProvider/useAttachment.ts +++ b/app/providers/AttachmentProvider/useAttachment.ts @@ -66,7 +66,8 @@ export function useAttachment(attachment: Attachment, parentMessage: MessageProp if(attachment.type == AttachmentType.FILE){ /** * Если это файл, то он хранится не в папке медиа, - * а в загрузках + * а в загрузках, статус скачивания определяем не только по названию файла, + * но и по его размеру (если размеры и название совпало, то считаем файл скаченным) */ const preview = getPreview(); const filesize = parseInt(preview.split("::")[0]); @@ -76,6 +77,9 @@ export function useAttachment(attachment: Attachment, parentMessage: MessageProp const exists = await fileExists(pathInDownloads, false); const existsLength = await size(pathInDownloads, false); if(exists && existsLength == filesize){ + /** + * Если название файла и его размер совпадают (и он существует), то считаем его скаченным + */ setDownloadStatus(DownloadStatus.DOWNLOADED); return; } diff --git a/app/providers/DialogProvider/DialogProvider.tsx b/app/providers/DialogProvider/DialogProvider.tsx index fd0e560..8786ba9 100644 --- a/app/providers/DialogProvider/DialogProvider.tsx +++ b/app/providers/DialogProvider/DialogProvider.tsx @@ -216,6 +216,16 @@ export function DialogProvider(props: DialogProviderProps) { readUpdated = true; } let decryptKey = ''; + if(message.from_me && message.chacha_key != "" && !message.chacha_key.startsWith("sync:")){ + /** + * Если это сообщение от нас, то проверяем, есть ли внутри chacha_key + */ + try{ + decryptKey = Buffer.from(await decodeWithPassword(privatePlain, message.chacha_key), 'binary').toString('utf-8'); + }catch(e) { + decryptKey = ""; + } + } if(message.from_me && message.chacha_key != "" && message.chacha_key.startsWith("sync:")){ /** * Если это сообщение от нас, то проверяем, есть ли внутри chacha_key, если есть, значит это @@ -629,7 +639,7 @@ export function DialogProvider(props: DialogProviderProps) { blob: attachment.type == AttachmentType.MESSAGES ? await decodeWithPassword(chachaDecryptedKey.toString('utf-8'), attachment.blob) : "" }); } - + console.info(attachments); const newMessage : Message = { from_public_key: fromPublicKey, to_public_key: toPublicKey, diff --git a/app/providers/DialogProvider/useDialog.ts b/app/providers/DialogProvider/useDialog.ts index 255e03d..c6aa6be 100644 --- a/app/providers/DialogProvider/useDialog.ts +++ b/app/providers/DialogProvider/useDialog.ts @@ -103,7 +103,7 @@ export function useDialog() : { content: content, timestamp: Date.now(), readed: publicKey == dialog ? 1 : 0, - chacha_key: "", + chacha_key: aesChachaKey, from_me: 1, plain_message: message, delivered: publicKey == dialog ? DeliveredMessageState.DELIVERED : DeliveredMessageState.WAITING, @@ -137,7 +137,7 @@ export function useDialog() : { await runQuery(` INSERT INTO messages (from_public_key, to_public_key, content, timestamp, read, chacha_key, from_me, plain_message, account, message_id, delivered, attachments) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) - `, [publicKey, dialog, content, Date.now(), publicKey == dialog ? 1 : 0, encryptedKey, 1, plainMessage, publicKey, messageId, publicKey == dialog ? DeliveredMessageState.DELIVERED : ( + `, [publicKey, dialog, content, Date.now(), publicKey == dialog ? 1 : 0, aesChachaKey, 1, plainMessage, publicKey, messageId, publicKey == dialog ? DeliveredMessageState.DELIVERED : ( protocolState != ProtocolState.CONNECTED ? DeliveredMessageState.ERROR : DeliveredMessageState.WAITING ), JSON.stringify(attachmentsMeta)]); updateDialog(dialog); diff --git a/app/providers/DialogProvider/useDialogFiber.ts b/app/providers/DialogProvider/useDialogFiber.ts index ebcf58d..b843d86 100644 --- a/app/providers/DialogProvider/useDialogFiber.ts +++ b/app/providers/DialogProvider/useDialogFiber.ts @@ -13,7 +13,7 @@ import { useDatabase } from "@/app/providers/DatabaseProvider/useDatabase"; import { usePrivatePlain } from "../AccountProvider/usePrivatePlain"; import { usePublicKey } from "../AccountProvider/usePublicKey"; import { chacha20Decrypt, decodeWithPassword, decrypt, encodeWithPassword, generateMd5 } from "@/app/workers/crypto/crypto"; -import { DeliveredMessageState, Message } from "./DialogProvider"; +import { AttachmentMeta, DeliveredMessageState, Message } from "./DialogProvider"; import { PacketRead } from "../ProtocolProvider/protocol/packets/packet.read"; import { PacketDelivery } from "../ProtocolProvider/protocol/packets/packet.delivery"; import { useConsoleLogger } from "@/app/hooks/useConsoleLogger"; @@ -104,7 +104,7 @@ export function useDialogFiber() { decryptedContent = ''; } - let attachmentsMeta: any[] = []; + let attachmentsMeta: AttachmentMeta[] = []; let messageAttachments: Attachment[] = []; for (let i = 0; i < packet.getAttachments().length; i++) { const attachment = packet.getAttachments()[i]; @@ -129,7 +129,9 @@ export function useDialogFiber() { attachmentsMeta.push({ id: attachment.id, type: attachment.type, - preview: attachment.preview + preview: attachment.preview, + encoding: attachment.encoding, + transport: attachment.transport }); } @@ -261,7 +263,7 @@ export function useDialogFiber() { const nonce = chachaDecryptedKey.slice(32); const decryptedContent = await chacha20Decrypt(content, nonce.toString('hex'), key.toString('hex')); - let attachmentsMeta: any[] = []; + let attachmentsMeta: AttachmentMeta[] = []; let messageAttachments: Attachment[] = []; for (let i = 0; i < packet.getAttachments().length; i++) { const attachment = packet.getAttachments()[i]; @@ -286,7 +288,9 @@ export function useDialogFiber() { attachmentsMeta.push({ id: attachment.id, type: attachment.type, - preview: attachment.preview + preview: attachment.preview, + encoding: attachment.encoding, + transport: attachment.transport }); } diff --git a/app/providers/DialogProvider/useReplyMessages.ts b/app/providers/DialogProvider/useReplyMessages.ts index 6083fdf..846a64c 100644 --- a/app/providers/DialogProvider/useReplyMessages.ts +++ b/app/providers/DialogProvider/useReplyMessages.ts @@ -19,6 +19,7 @@ export interface MessageReply { message: string; attachments: Attachment[]; message_id: string; + } export function useReplyMessages() {