From 94ba13954160981fc883bc0b2e5c03058a8e3983 Mon Sep 17 00:00:00 2001 From: RoyceDa Date: Fri, 27 Mar 2026 15:58:16 +0200 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=80=D0=BE=D1=82=D0=BE=D0=BA=D0=BE?= =?UTF-8?q?=D0=BB=D0=B0=20=D0=B2=D0=BB=D0=BE=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/DialogInput/DialogInput.tsx | 30 ++++++++++++------- .../AttachmentProvider/useAttachment.ts | 6 ++-- .../usePrepareAttachment.ts | 6 ++-- app/providers/CallProvider/CallProvider.tsx | 6 ++-- .../DialogProvider/DialogProvider.tsx | 8 ++--- app/providers/DialogProvider/useDialog.ts | 3 +- .../DialogProvider/useSynchronize.ts | 6 ++-- .../protocol/packets/packet.message.ts | 26 +++++++++++----- 8 files changed, 56 insertions(+), 35 deletions(-) diff --git a/app/components/DialogInput/DialogInput.tsx b/app/components/DialogInput/DialogInput.tsx index 742ce7c..2850c4c 100644 --- a/app/components/DialogInput/DialogInput.tsx +++ b/app/components/DialogInput/DialogInput.tsx @@ -90,8 +90,10 @@ export function DialogInput() { id: generateRandomKey(8), type: AttachmentType.FILE, preview: files[0].size + "::" + files[0].name, - transport_server: "", - transport_tag: "", + transport: { + transport_server: "", + transport_tag: "" + }, encoding: { encoded_for: dialog, encoder: publicKey @@ -123,8 +125,10 @@ export function DialogInput() { id: generateRandomKey(8), blob: JSON.stringify([...replyMessages.messages]), preview: "", - transport_server: "", - transport_tag: "", + transport: { + transport_server: "", + transport_tag: "" + }, encoding: { encoded_for: dialog, encoder: publicKey @@ -243,8 +247,10 @@ export function DialogInput() { id: generateRandomKey(8), type: AttachmentType.AVATAR, preview: "", - transport_server: "", - transport_tag: "", + transport: { + transport_server: "", + transport_tag: "" + }, encoding: { encoded_for: dialog, encoder: publicKey @@ -289,8 +295,10 @@ export function DialogInput() { id: attachmentId, type: AttachmentType.IMAGE, preview: "", - transport_server: "", - transport_tag: "", + transport: { + transport_server: "", + transport_tag: "" + }, encoding: { encoded_for: dialog, encoder: publicKey @@ -329,8 +337,10 @@ export function DialogInput() { id: attachmentId, type: AttachmentType.FILE, preview: files[0].size + "::" + files[0].name, - transport_server: "", - transport_tag: "", + transport: { + transport_server: "", + transport_tag: "" + }, encoding: { encoded_for: dialog, encoder: publicKey diff --git a/app/providers/AttachmentProvider/useAttachment.ts b/app/providers/AttachmentProvider/useAttachment.ts index d336eec..150af5d 100644 --- a/app/providers/AttachmentProvider/useAttachment.ts +++ b/app/providers/AttachmentProvider/useAttachment.ts @@ -30,7 +30,7 @@ export function useAttachment(attachment: Attachment, parentMessage: MessageProp const uploadedPercentage = useUploadStatus(attachment.id); const downloadPercentage = useDownloadStatus(attachment.id); const [downloadStatus, setDownloadStatus] = useMemory("attachment-downloaded-status-" + attachment.id, DownloadStatus.PENDING, true); - const [downloadTag, setDownloadTag] = useState(attachment.transport_tag || ""); + const [downloadTag, setDownloadTag] = useState(attachment.transport.transport_tag || ""); const {readFile, writeFile, fileExists, size} = useFileStorage(); const { downloadFile } = useTransport(); const publicKey = usePublicKey(); @@ -56,7 +56,7 @@ export function useAttachment(attachment: Attachment, parentMessage: MessageProp if (downloadStatus == DownloadStatus.DOWNLOADED) { return; } - if(attachment.transport_tag == ""){ + if(attachment.transport.transport_tag == ""){ /** * Транспортного тега нет только у сообщений отправленных нами, значит он точно наш */ @@ -130,7 +130,7 @@ export function useAttachment(attachment: Attachment, parentMessage: MessageProp let downloadedBlob = ''; try { downloadedBlob = await downloadFile(attachment.id, - downloadTag, attachment.transport_server); + downloadTag, attachment.transport.transport_server); } catch (e) { console.info(e); info("Error downloading attachment: " + attachment.id); diff --git a/app/providers/AttachmentProvider/usePrepareAttachment.ts b/app/providers/AttachmentProvider/usePrepareAttachment.ts index f89a55e..5c96c17 100644 --- a/app/providers/AttachmentProvider/usePrepareAttachment.ts +++ b/app/providers/AttachmentProvider/usePrepareAttachment.ts @@ -141,8 +141,10 @@ export function usePrepareAttachment() { } prepared.push({ ...attachment, - transport_server: transportServer || "", - transport_tag: tag, + transport: { + transport_server: transportServer || "", + transport_tag: tag + }, encoding: { encoded_for: dialog, encoder: publicKey diff --git a/app/providers/CallProvider/CallProvider.tsx b/app/providers/CallProvider/CallProvider.tsx index 01ec3c8..2d1bbd0 100644 --- a/app/providers/CallProvider/CallProvider.tsx +++ b/app/providers/CallProvider/CallProvider.tsx @@ -472,8 +472,10 @@ export function CallProvider(props : CallProviderProps) { id: generateRandomKey(16), preview: duration.toString(), type: AttachmentType.CALL, - transport_server: "", - transport_tag: "", + transport: { + transport_server: "", + transport_tag: "" + }, encoding: { encoded_for: "", encoder: "" diff --git a/app/providers/DialogProvider/DialogProvider.tsx b/app/providers/DialogProvider/DialogProvider.tsx index ea1d5a8..fd0e560 100644 --- a/app/providers/DialogProvider/DialogProvider.tsx +++ b/app/providers/DialogProvider/DialogProvider.tsx @@ -1,7 +1,7 @@ import { chacha20Decrypt, decodeWithPassword, decrypt, generateMd5 } from '@/app/workers/crypto/crypto'; import { useDatabase } from '@/app/providers/DatabaseProvider/useDatabase'; import { createContext, useEffect, useRef, useState } from 'react'; -import { Attachment, AttachmentEncoding, AttachmentType, PacketMessage } from '@/app/providers/ProtocolProvider/protocol/packets/packet.message'; +import { Attachment, AttachmentEncoding, AttachmentTransport, AttachmentType, PacketMessage } from '@/app/providers/ProtocolProvider/protocol/packets/packet.message'; import { usePrivatePlain } from '../AccountProvider/usePrivatePlain'; import { usePublicKey } from '../AccountProvider/usePublicKey'; import { PacketRead } from '@/app/providers/ProtocolProvider/protocol/packets/packet.read'; @@ -46,9 +46,8 @@ export interface AttachmentMeta { id: string; type: AttachmentType; preview: string; - transport_tag: string; + transport: AttachmentTransport; encoding: AttachmentEncoding; - transport_server: string; } export interface Message { @@ -960,8 +959,7 @@ export function DialogProvider(props: DialogProviderProps) { blob: blob, type: meta.type, preview: meta.preview, - transport_server: meta.transport_server, - transport_tag: meta.transport_tag, + transport: meta.transport, encoding: meta.encoding }); } diff --git a/app/providers/DialogProvider/useDialog.ts b/app/providers/DialogProvider/useDialog.ts index 61fbbf1..255e03d 100644 --- a/app/providers/DialogProvider/useDialog.ts +++ b/app/providers/DialogProvider/useDialog.ts @@ -119,8 +119,7 @@ export function useDialog() : { id: attachment.id, type: attachment.type, preview: attachment.preview, - transport_server: attachment.transport_server, - transport_tag: attachment.transport_tag, + transport: attachment.transport, encoding: attachment.encoding }); if(attachment.type == AttachmentType.FILE){ diff --git a/app/providers/DialogProvider/useSynchronize.ts b/app/providers/DialogProvider/useSynchronize.ts index cd5937a..a553b9d 100644 --- a/app/providers/DialogProvider/useSynchronize.ts +++ b/app/providers/DialogProvider/useSynchronize.ts @@ -192,8 +192,7 @@ export function useSynchronize() { type: attachment.type, preview: attachment.preview, encoding: attachment.encoding, - transport_server: attachment.transport_server, - transport_tag: attachment.transport_tag + transport: attachment.transport }); } @@ -377,8 +376,7 @@ export function useSynchronize() { type: attachment.type, preview: attachment.preview, encoding: attachment.encoding, - transport_server: attachment.transport_server, - transport_tag: attachment.transport_tag + transport: attachment.transport }); } diff --git a/app/providers/ProtocolProvider/protocol/packets/packet.message.ts b/app/providers/ProtocolProvider/protocol/packets/packet.message.ts index 24f1976..e42f995 100644 --- a/app/providers/ProtocolProvider/protocol/packets/packet.message.ts +++ b/app/providers/ProtocolProvider/protocol/packets/packet.message.ts @@ -9,6 +9,17 @@ export enum AttachmentType { CALL = 4 } +/** + * Информация о транспортировке вложения, нужна для загрузки и скачивания вложений с транспортного сервера + */ +export interface AttachmentTransport { + transport_tag: string; + transport_server: string; +} + +/** + * Информация о кодировке вложения + */ export interface AttachmentEncoding { /** * Для кого вложение закодировано (для какого диалога) @@ -25,8 +36,7 @@ export interface Attachment { blob: string; type: AttachmentType; preview: string; - transport_tag: string; - transport_server: string; + transport: AttachmentTransport; encoding: AttachmentEncoding; } @@ -65,13 +75,15 @@ export class PacketMessage extends Packet { let preview = stream.readString(); let blob = stream.readString(); let type = stream.readInt8() as AttachmentType; - let transport_tag = stream.readString(); - let transport_server = stream.readString(); + const transport : AttachmentTransport = { + transport_tag: stream.readString(), + transport_server: stream.readString() + } const encoding : AttachmentEncoding = { encoded_for: stream.readString(), encoder: stream.readString() } - this.attachments.push({id, preview, type, blob, transport_tag, transport_server, encoding}); + this.attachments.push({id, preview, type, blob, transport, encoding}); } this.aesChachaKey = stream.readString(); } @@ -92,8 +104,8 @@ export class PacketMessage extends Packet { stream.writeString(this.attachments[i].preview); stream.writeString(this.attachments[i].blob); stream.writeInt8(this.attachments[i].type); - stream.writeString(this.attachments[i].transport_tag); - stream.writeString(this.attachments[i].transport_server); + stream.writeString(this.attachments[i].transport.transport_tag); + stream.writeString(this.attachments[i].transport.transport_server); stream.writeString(this.attachments[i].encoding.encoded_for); stream.writeString(this.attachments[i].encoding.encoder); }