diff --git a/app/components/DialogInput/DialogInput.tsx b/app/components/DialogInput/DialogInput.tsx index 7814b9d..742ce7c 100644 --- a/app/components/DialogInput/DialogInput.tsx +++ b/app/components/DialogInput/DialogInput.tsx @@ -92,7 +92,10 @@ export function DialogInput() { preview: files[0].size + "::" + files[0].name, transport_server: "", transport_tag: "", - encoded_for: dialog + encoding: { + encoded_for: dialog, + encoder: publicKey + } }]); } }); @@ -122,7 +125,10 @@ export function DialogInput() { preview: "", transport_server: "", transport_tag: "", - encoded_for: dialog + encoding: { + encoded_for: dialog, + encoder: publicKey + } }]); if(editableDivRef.current){ editableDivRef.current.focus(); @@ -239,7 +245,10 @@ export function DialogInput() { preview: "", transport_server: "", transport_tag: "", - encoded_for: dialog + encoding: { + encoded_for: dialog, + encoder: publicKey + } }]); if(editableDivRef.current){ editableDivRef.current.focus(); @@ -282,7 +291,10 @@ export function DialogInput() { preview: "", transport_server: "", transport_tag: "", - encoded_for: dialog + encoding: { + encoded_for: dialog, + encoder: publicKey + } }]); } if(editableDivRef.current){ @@ -319,7 +331,10 @@ export function DialogInput() { preview: files[0].size + "::" + files[0].name, transport_server: "", transport_tag: "", - encoded_for: dialog + encoding: { + encoded_for: dialog, + encoder: publicKey + } }]); } diff --git a/app/providers/AttachmentProvider/usePrepareAttachment.ts b/app/providers/AttachmentProvider/usePrepareAttachment.ts index 466b1df..f89a55e 100644 --- a/app/providers/AttachmentProvider/usePrepareAttachment.ts +++ b/app/providers/AttachmentProvider/usePrepareAttachment.ts @@ -11,6 +11,7 @@ import { useConsoleLogger } from "@/app/hooks/useConsoleLogger"; import { useDialogsCache } from "../DialogProvider/useDialogsCache"; import { DialogContext } from "../DialogProvider/DialogProvider"; import { useTransportServer } from "../TransportProvider/useTransportServer"; +import { usePublicKey } from "../AccountProvider/usePublicKey"; export function usePrepareAttachment() { const intervalsRef = useRef(null); @@ -21,6 +22,7 @@ export function usePrepareAttachment() { const {getDialogCache} = useDialogsCache(); const context = useContext(DialogContext); const transportServer = useTransportServer(); + const publicKey = usePublicKey(); const updateTimestampInDialogCache = (dialog : string, message_id: string) => { const dialogCache = getDialogCache(dialog); @@ -117,9 +119,9 @@ export function usePrepareAttachment() { const blurhash = await base64ImageToBlurhash(attachment.blob); attachment.preview = blurhash; } - if(rePrepared && attachment.encoded_for == dialog){ + if(rePrepared && (attachment.encoding.encoded_for == dialog || attachment.encoding.encoder == dialog)){ /** - * Это пересланное сообщение и оно уже закодировано для этого диалога, значит не нужно его кодировать и загружать заново + * Это пересланное сообщение и оно уже закодировано для этого диалога, или закодировано отправителем, значит не нужно его кодировать и загружать заново */ prepared.push({ ...attachment, @@ -141,7 +143,10 @@ export function usePrepareAttachment() { ...attachment, transport_server: transportServer || "", transport_tag: tag, - encoded_for: dialog, + encoding: { + encoded_for: dialog, + encoder: publicKey + }, preview: attachment.preview, blob: "" }); diff --git a/app/providers/CallProvider/CallProvider.tsx b/app/providers/CallProvider/CallProvider.tsx index 6c571c5..01ec3c8 100644 --- a/app/providers/CallProvider/CallProvider.tsx +++ b/app/providers/CallProvider/CallProvider.tsx @@ -474,7 +474,10 @@ export function CallProvider(props : CallProviderProps) { type: AttachmentType.CALL, transport_server: "", transport_tag: "", - encoded_for: "", + encoding: { + encoded_for: "", + encoder: "" + }, blob: "" }], true); } diff --git a/app/providers/DialogProvider/DialogProvider.tsx b/app/providers/DialogProvider/DialogProvider.tsx index 5882f59..ea1d5a8 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, AttachmentType, PacketMessage } from '@/app/providers/ProtocolProvider/protocol/packets/packet.message'; +import { Attachment, AttachmentEncoding, 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'; @@ -47,7 +47,7 @@ export interface AttachmentMeta { type: AttachmentType; preview: string; transport_tag: string; - encoded_for: string; + encoding: AttachmentEncoding; transport_server: string; } @@ -962,7 +962,7 @@ export function DialogProvider(props: DialogProviderProps) { preview: meta.preview, transport_server: meta.transport_server, transport_tag: meta.transport_tag, - encoded_for: meta.encoded_for + encoding: meta.encoding }); } return attachments; diff --git a/app/providers/DialogProvider/useDialog.ts b/app/providers/DialogProvider/useDialog.ts index c9c1bb7..61fbbf1 100644 --- a/app/providers/DialogProvider/useDialog.ts +++ b/app/providers/DialogProvider/useDialog.ts @@ -121,7 +121,7 @@ export function useDialog() : { preview: attachment.preview, transport_server: attachment.transport_server, transport_tag: attachment.transport_tag, - encoded_for: dialog + encoding: attachment.encoding }); if(attachment.type == AttachmentType.FILE){ /** diff --git a/app/providers/DialogProvider/useSynchronize.ts b/app/providers/DialogProvider/useSynchronize.ts index 1aff118..cd5937a 100644 --- a/app/providers/DialogProvider/useSynchronize.ts +++ b/app/providers/DialogProvider/useSynchronize.ts @@ -191,7 +191,7 @@ export function useSynchronize() { id: attachment.id, type: attachment.type, preview: attachment.preview, - encoded_for: attachment.encoded_for, + encoding: attachment.encoding, transport_server: attachment.transport_server, transport_tag: attachment.transport_tag }); @@ -376,7 +376,7 @@ export function useSynchronize() { id: attachment.id, type: attachment.type, preview: attachment.preview, - encoded_for: attachment.encoded_for, + encoding: attachment.encoding, transport_server: attachment.transport_server, transport_tag: attachment.transport_tag }); diff --git a/app/providers/ProtocolProvider/protocol/packets/packet.message.ts b/app/providers/ProtocolProvider/protocol/packets/packet.message.ts index 52cad0d..24f1976 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 AttachmentEncoding { + /** + * Для кого вложение закодировано (для какого диалога) + */ + encoded_for: string; + /** + * Кто кодировал вложение + */ + encoder: string; +} + export interface Attachment { id: string; blob: string; @@ -16,10 +27,7 @@ export interface Attachment { preview: string; transport_tag: string; transport_server: string; - /** - * Обозначает, для кого закодировано это вложение, нужно для того, чтобы не кодировать и не загружать заново пересланные сообщения, если они уже были закодированы для этого диалога - */ - encoded_for: string; + encoding: AttachmentEncoding; } export class PacketMessage extends Packet { @@ -59,8 +67,11 @@ export class PacketMessage extends Packet { let type = stream.readInt8() as AttachmentType; let transport_tag = stream.readString(); let transport_server = stream.readString(); - let encoded_for = stream.readString(); - this.attachments.push({id, preview, type, blob, transport_tag, transport_server, encoded_for}); + const encoding : AttachmentEncoding = { + encoded_for: stream.readString(), + encoder: stream.readString() + } + this.attachments.push({id, preview, type, blob, transport_tag, transport_server, encoding}); } this.aesChachaKey = stream.readString(); } @@ -83,7 +94,8 @@ export class PacketMessage extends Packet { 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].encoded_for); + stream.writeString(this.attachments[i].encoding.encoded_for); + stream.writeString(this.attachments[i].encoding.encoder); } stream.writeString(this.aesChachaKey); return stream;