Новый протокол кодирования и декодирования вложений
This commit is contained in:
@@ -92,7 +92,10 @@ export function DialogInput() {
|
|||||||
preview: files[0].size + "::" + files[0].name,
|
preview: files[0].size + "::" + files[0].name,
|
||||||
transport_server: "",
|
transport_server: "",
|
||||||
transport_tag: "",
|
transport_tag: "",
|
||||||
encoded_for: dialog
|
encoding: {
|
||||||
|
encoded_for: dialog,
|
||||||
|
encoder: publicKey
|
||||||
|
}
|
||||||
}]);
|
}]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -122,7 +125,10 @@ export function DialogInput() {
|
|||||||
preview: "",
|
preview: "",
|
||||||
transport_server: "",
|
transport_server: "",
|
||||||
transport_tag: "",
|
transport_tag: "",
|
||||||
encoded_for: dialog
|
encoding: {
|
||||||
|
encoded_for: dialog,
|
||||||
|
encoder: publicKey
|
||||||
|
}
|
||||||
}]);
|
}]);
|
||||||
if(editableDivRef.current){
|
if(editableDivRef.current){
|
||||||
editableDivRef.current.focus();
|
editableDivRef.current.focus();
|
||||||
@@ -239,7 +245,10 @@ export function DialogInput() {
|
|||||||
preview: "",
|
preview: "",
|
||||||
transport_server: "",
|
transport_server: "",
|
||||||
transport_tag: "",
|
transport_tag: "",
|
||||||
encoded_for: dialog
|
encoding: {
|
||||||
|
encoded_for: dialog,
|
||||||
|
encoder: publicKey
|
||||||
|
}
|
||||||
}]);
|
}]);
|
||||||
if(editableDivRef.current){
|
if(editableDivRef.current){
|
||||||
editableDivRef.current.focus();
|
editableDivRef.current.focus();
|
||||||
@@ -282,7 +291,10 @@ export function DialogInput() {
|
|||||||
preview: "",
|
preview: "",
|
||||||
transport_server: "",
|
transport_server: "",
|
||||||
transport_tag: "",
|
transport_tag: "",
|
||||||
encoded_for: dialog
|
encoding: {
|
||||||
|
encoded_for: dialog,
|
||||||
|
encoder: publicKey
|
||||||
|
}
|
||||||
}]);
|
}]);
|
||||||
}
|
}
|
||||||
if(editableDivRef.current){
|
if(editableDivRef.current){
|
||||||
@@ -319,7 +331,10 @@ export function DialogInput() {
|
|||||||
preview: files[0].size + "::" + files[0].name,
|
preview: files[0].size + "::" + files[0].name,
|
||||||
transport_server: "",
|
transport_server: "",
|
||||||
transport_tag: "",
|
transport_tag: "",
|
||||||
encoded_for: dialog
|
encoding: {
|
||||||
|
encoded_for: dialog,
|
||||||
|
encoder: publicKey
|
||||||
|
}
|
||||||
}]);
|
}]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { useConsoleLogger } from "@/app/hooks/useConsoleLogger";
|
|||||||
import { useDialogsCache } from "../DialogProvider/useDialogsCache";
|
import { useDialogsCache } from "../DialogProvider/useDialogsCache";
|
||||||
import { DialogContext } from "../DialogProvider/DialogProvider";
|
import { DialogContext } from "../DialogProvider/DialogProvider";
|
||||||
import { useTransportServer } from "../TransportProvider/useTransportServer";
|
import { useTransportServer } from "../TransportProvider/useTransportServer";
|
||||||
|
import { usePublicKey } from "../AccountProvider/usePublicKey";
|
||||||
|
|
||||||
export function usePrepareAttachment() {
|
export function usePrepareAttachment() {
|
||||||
const intervalsRef = useRef<NodeJS.Timeout>(null);
|
const intervalsRef = useRef<NodeJS.Timeout>(null);
|
||||||
@@ -21,6 +22,7 @@ export function usePrepareAttachment() {
|
|||||||
const {getDialogCache} = useDialogsCache();
|
const {getDialogCache} = useDialogsCache();
|
||||||
const context = useContext(DialogContext);
|
const context = useContext(DialogContext);
|
||||||
const transportServer = useTransportServer();
|
const transportServer = useTransportServer();
|
||||||
|
const publicKey = usePublicKey();
|
||||||
|
|
||||||
const updateTimestampInDialogCache = (dialog : string, message_id: string) => {
|
const updateTimestampInDialogCache = (dialog : string, message_id: string) => {
|
||||||
const dialogCache = getDialogCache(dialog);
|
const dialogCache = getDialogCache(dialog);
|
||||||
@@ -117,9 +119,9 @@ export function usePrepareAttachment() {
|
|||||||
const blurhash = await base64ImageToBlurhash(attachment.blob);
|
const blurhash = await base64ImageToBlurhash(attachment.blob);
|
||||||
attachment.preview = blurhash;
|
attachment.preview = blurhash;
|
||||||
}
|
}
|
||||||
if(rePrepared && attachment.encoded_for == dialog){
|
if(rePrepared && (attachment.encoding.encoded_for == dialog || attachment.encoding.encoder == dialog)){
|
||||||
/**
|
/**
|
||||||
* Это пересланное сообщение и оно уже закодировано для этого диалога, значит не нужно его кодировать и загружать заново
|
* Это пересланное сообщение и оно уже закодировано для этого диалога, или закодировано отправителем, значит не нужно его кодировать и загружать заново
|
||||||
*/
|
*/
|
||||||
prepared.push({
|
prepared.push({
|
||||||
...attachment,
|
...attachment,
|
||||||
@@ -141,7 +143,10 @@ export function usePrepareAttachment() {
|
|||||||
...attachment,
|
...attachment,
|
||||||
transport_server: transportServer || "",
|
transport_server: transportServer || "",
|
||||||
transport_tag: tag,
|
transport_tag: tag,
|
||||||
|
encoding: {
|
||||||
encoded_for: dialog,
|
encoded_for: dialog,
|
||||||
|
encoder: publicKey
|
||||||
|
},
|
||||||
preview: attachment.preview,
|
preview: attachment.preview,
|
||||||
blob: ""
|
blob: ""
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -474,7 +474,10 @@ export function CallProvider(props : CallProviderProps) {
|
|||||||
type: AttachmentType.CALL,
|
type: AttachmentType.CALL,
|
||||||
transport_server: "",
|
transport_server: "",
|
||||||
transport_tag: "",
|
transport_tag: "",
|
||||||
|
encoding: {
|
||||||
encoded_for: "",
|
encoded_for: "",
|
||||||
|
encoder: ""
|
||||||
|
},
|
||||||
blob: ""
|
blob: ""
|
||||||
}], true);
|
}], true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { chacha20Decrypt, decodeWithPassword, decrypt, generateMd5 } from '@/app/workers/crypto/crypto';
|
import { chacha20Decrypt, decodeWithPassword, decrypt, generateMd5 } from '@/app/workers/crypto/crypto';
|
||||||
import { useDatabase } from '@/app/providers/DatabaseProvider/useDatabase';
|
import { useDatabase } from '@/app/providers/DatabaseProvider/useDatabase';
|
||||||
import { createContext, useEffect, useRef, useState } from 'react';
|
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 { usePrivatePlain } from '../AccountProvider/usePrivatePlain';
|
||||||
import { usePublicKey } from '../AccountProvider/usePublicKey';
|
import { usePublicKey } from '../AccountProvider/usePublicKey';
|
||||||
import { PacketRead } from '@/app/providers/ProtocolProvider/protocol/packets/packet.read';
|
import { PacketRead } from '@/app/providers/ProtocolProvider/protocol/packets/packet.read';
|
||||||
@@ -47,7 +47,7 @@ export interface AttachmentMeta {
|
|||||||
type: AttachmentType;
|
type: AttachmentType;
|
||||||
preview: string;
|
preview: string;
|
||||||
transport_tag: string;
|
transport_tag: string;
|
||||||
encoded_for: string;
|
encoding: AttachmentEncoding;
|
||||||
transport_server: string;
|
transport_server: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -962,7 +962,7 @@ export function DialogProvider(props: DialogProviderProps) {
|
|||||||
preview: meta.preview,
|
preview: meta.preview,
|
||||||
transport_server: meta.transport_server,
|
transport_server: meta.transport_server,
|
||||||
transport_tag: meta.transport_tag,
|
transport_tag: meta.transport_tag,
|
||||||
encoded_for: meta.encoded_for
|
encoding: meta.encoding
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return attachments;
|
return attachments;
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ export function useDialog() : {
|
|||||||
preview: attachment.preview,
|
preview: attachment.preview,
|
||||||
transport_server: attachment.transport_server,
|
transport_server: attachment.transport_server,
|
||||||
transport_tag: attachment.transport_tag,
|
transport_tag: attachment.transport_tag,
|
||||||
encoded_for: dialog
|
encoding: attachment.encoding
|
||||||
});
|
});
|
||||||
if(attachment.type == AttachmentType.FILE){
|
if(attachment.type == AttachmentType.FILE){
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ export function useSynchronize() {
|
|||||||
id: attachment.id,
|
id: attachment.id,
|
||||||
type: attachment.type,
|
type: attachment.type,
|
||||||
preview: attachment.preview,
|
preview: attachment.preview,
|
||||||
encoded_for: attachment.encoded_for,
|
encoding: attachment.encoding,
|
||||||
transport_server: attachment.transport_server,
|
transport_server: attachment.transport_server,
|
||||||
transport_tag: attachment.transport_tag
|
transport_tag: attachment.transport_tag
|
||||||
});
|
});
|
||||||
@@ -376,7 +376,7 @@ export function useSynchronize() {
|
|||||||
id: attachment.id,
|
id: attachment.id,
|
||||||
type: attachment.type,
|
type: attachment.type,
|
||||||
preview: attachment.preview,
|
preview: attachment.preview,
|
||||||
encoded_for: attachment.encoded_for,
|
encoding: attachment.encoding,
|
||||||
transport_server: attachment.transport_server,
|
transport_server: attachment.transport_server,
|
||||||
transport_tag: attachment.transport_tag
|
transport_tag: attachment.transport_tag
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,6 +9,17 @@ export enum AttachmentType {
|
|||||||
CALL = 4
|
CALL = 4
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface AttachmentEncoding {
|
||||||
|
/**
|
||||||
|
* Для кого вложение закодировано (для какого диалога)
|
||||||
|
*/
|
||||||
|
encoded_for: string;
|
||||||
|
/**
|
||||||
|
* Кто кодировал вложение
|
||||||
|
*/
|
||||||
|
encoder: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface Attachment {
|
export interface Attachment {
|
||||||
id: string;
|
id: string;
|
||||||
blob: string;
|
blob: string;
|
||||||
@@ -16,10 +27,7 @@ export interface Attachment {
|
|||||||
preview: string;
|
preview: string;
|
||||||
transport_tag: string;
|
transport_tag: string;
|
||||||
transport_server: string;
|
transport_server: string;
|
||||||
/**
|
encoding: AttachmentEncoding;
|
||||||
* Обозначает, для кого закодировано это вложение, нужно для того, чтобы не кодировать и не загружать заново пересланные сообщения, если они уже были закодированы для этого диалога
|
|
||||||
*/
|
|
||||||
encoded_for: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PacketMessage extends Packet {
|
export class PacketMessage extends Packet {
|
||||||
@@ -59,8 +67,11 @@ export class PacketMessage extends Packet {
|
|||||||
let type = stream.readInt8() as AttachmentType;
|
let type = stream.readInt8() as AttachmentType;
|
||||||
let transport_tag = stream.readString();
|
let transport_tag = stream.readString();
|
||||||
let transport_server = stream.readString();
|
let transport_server = stream.readString();
|
||||||
let encoded_for = stream.readString();
|
const encoding : AttachmentEncoding = {
|
||||||
this.attachments.push({id, preview, type, blob, transport_tag, transport_server, encoded_for});
|
encoded_for: stream.readString(),
|
||||||
|
encoder: stream.readString()
|
||||||
|
}
|
||||||
|
this.attachments.push({id, preview, type, blob, transport_tag, transport_server, encoding});
|
||||||
}
|
}
|
||||||
this.aesChachaKey = stream.readString();
|
this.aesChachaKey = stream.readString();
|
||||||
}
|
}
|
||||||
@@ -83,7 +94,8 @@ export class PacketMessage extends Packet {
|
|||||||
stream.writeInt8(this.attachments[i].type);
|
stream.writeInt8(this.attachments[i].type);
|
||||||
stream.writeString(this.attachments[i].transport_tag);
|
stream.writeString(this.attachments[i].transport_tag);
|
||||||
stream.writeString(this.attachments[i].transport_server);
|
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);
|
stream.writeString(this.aesChachaKey);
|
||||||
return stream;
|
return stream;
|
||||||
|
|||||||
Reference in New Issue
Block a user