Улучшение протокола, чистка кода
This commit is contained in:
@@ -93,10 +93,6 @@ export function DialogInput() {
|
||||
transport: {
|
||||
transport_server: "",
|
||||
transport_tag: ""
|
||||
},
|
||||
encoding: {
|
||||
encoded_for: dialog,
|
||||
encoder: publicKey
|
||||
}
|
||||
}]);
|
||||
}
|
||||
@@ -128,10 +124,6 @@ export function DialogInput() {
|
||||
transport: {
|
||||
transport_server: "",
|
||||
transport_tag: ""
|
||||
},
|
||||
encoding: {
|
||||
encoded_for: dialog,
|
||||
encoder: publicKey
|
||||
}
|
||||
}]);
|
||||
if(editableDivRef.current){
|
||||
@@ -250,10 +242,6 @@ export function DialogInput() {
|
||||
transport: {
|
||||
transport_server: "",
|
||||
transport_tag: ""
|
||||
},
|
||||
encoding: {
|
||||
encoded_for: dialog,
|
||||
encoder: publicKey
|
||||
}
|
||||
}]);
|
||||
if(editableDivRef.current){
|
||||
@@ -298,10 +286,6 @@ export function DialogInput() {
|
||||
transport: {
|
||||
transport_server: "",
|
||||
transport_tag: ""
|
||||
},
|
||||
encoding: {
|
||||
encoded_for: dialog,
|
||||
encoder: publicKey
|
||||
}
|
||||
}]);
|
||||
}
|
||||
@@ -340,10 +324,6 @@ export function DialogInput() {
|
||||
transport: {
|
||||
transport_server: "",
|
||||
transport_tag: ""
|
||||
},
|
||||
encoding: {
|
||||
encoded_for: dialog,
|
||||
encoder: publicKey
|
||||
}
|
||||
}]);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import { useConsoleLogger } from "@/app/hooks/useConsoleLogger";
|
||||
import { useDialogsCache } from "../DialogProvider/useDialogsCache";
|
||||
import { AttachmentMeta, DialogContext } from "../DialogProvider/DialogProvider";
|
||||
import { useTransportServer } from "../TransportProvider/useTransportServer";
|
||||
import { usePublicKey } from "../AccountProvider/usePublicKey";
|
||||
|
||||
export function usePrepareAttachment() {
|
||||
const intervalsRef = useRef<NodeJS.Timeout>(null);
|
||||
@@ -22,7 +21,6 @@ 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);
|
||||
@@ -158,7 +156,7 @@ export function usePrepareAttachment() {
|
||||
* а так же из-за надежности доставки файлов через HTTP
|
||||
* @param attachments Attachments to prepare for sending
|
||||
*/
|
||||
const prepareAttachmentsToSend = async (message_id: string, dialog: string, password: string, attachments : Attachment[], rePrepared : boolean = false) : Promise<Attachment[]> => {
|
||||
const prepareAttachmentsToSend = async (message_id: string, dialog: string, password: string, attachments : Attachment[]) : Promise<Attachment[]> => {
|
||||
if(attachments.length <= 0){
|
||||
return [];
|
||||
}
|
||||
@@ -174,7 +172,7 @@ export function usePrepareAttachment() {
|
||||
continue;
|
||||
}
|
||||
if(attachment.type == AttachmentType.MESSAGES){
|
||||
let reply : MessageReply[] = JSON.parse(attachment.blob)
|
||||
let reply : MessageReply[] = JSON.parse(attachment.blob);
|
||||
for(let j = 0; j < reply.length; j++){
|
||||
for(let k = 0; k < reply[j].attachments.length; k++){
|
||||
reply[j].attachments[k].blob = "";
|
||||
@@ -194,16 +192,6 @@ export function usePrepareAttachment() {
|
||||
const blurhash = await base64ImageToBlurhash(attachment.blob);
|
||||
attachment.preview = blurhash;
|
||||
}
|
||||
// if(rePrepared && (attachment.encoding.encoded_for == dialog || attachment.encoding.encoder == dialog)){
|
||||
// /**
|
||||
// * Это пересланное сообщение и оно уже закодировано для этого диалога, или закодировано отправителем, значит не нужно его кодировать и загружать заново
|
||||
// */
|
||||
// prepared.push({
|
||||
// ...attachment,
|
||||
// blob: ""
|
||||
// });
|
||||
// continue;
|
||||
// }
|
||||
doTimestampUpdateImMessageWhileAttachmentsSend(message_id, dialog);
|
||||
const content = await encodeWithPassword(password, attachment.blob);
|
||||
const upid = attachment.id;
|
||||
@@ -220,10 +208,6 @@ export function usePrepareAttachment() {
|
||||
transport_server: transportServer || "",
|
||||
transport_tag: tag
|
||||
},
|
||||
encoding: {
|
||||
encoded_for: dialog,
|
||||
encoder: publicKey
|
||||
},
|
||||
preview: attachment.preview,
|
||||
blob: ""
|
||||
};
|
||||
|
||||
@@ -476,10 +476,6 @@ export function CallProvider(props : CallProviderProps) {
|
||||
transport_server: "",
|
||||
transport_tag: ""
|
||||
},
|
||||
encoding: {
|
||||
encoded_for: "",
|
||||
encoder: ""
|
||||
},
|
||||
blob: ""
|
||||
}], true);
|
||||
}
|
||||
|
||||
@@ -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, AttachmentTransport, AttachmentType, PacketMessage } from '@/app/providers/ProtocolProvider/protocol/packets/packet.message';
|
||||
import { Attachment, 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';
|
||||
@@ -47,7 +47,6 @@ export interface AttachmentMeta {
|
||||
type: AttachmentType;
|
||||
preview: string;
|
||||
transport: AttachmentTransport;
|
||||
encoding: AttachmentEncoding;
|
||||
}
|
||||
|
||||
export interface Message {
|
||||
@@ -969,8 +968,7 @@ export function DialogProvider(props: DialogProviderProps) {
|
||||
blob: blob,
|
||||
type: meta.type,
|
||||
preview: meta.preview,
|
||||
transport: meta.transport,
|
||||
encoding: meta.encoding
|
||||
transport: meta.transport
|
||||
});
|
||||
}
|
||||
return attachments;
|
||||
|
||||
@@ -107,7 +107,6 @@ export function useDeattachedSender() {
|
||||
id: attachment.id,
|
||||
type: attachment.type,
|
||||
preview: attachment.preview,
|
||||
encoding: attachment.encoding,
|
||||
transport: attachment.transport
|
||||
});
|
||||
if(attachment.type == AttachmentType.FILE){
|
||||
|
||||
@@ -118,8 +118,7 @@ export function useDialog() : {
|
||||
id: attachment.id,
|
||||
type: attachment.type,
|
||||
preview: attachment.preview,
|
||||
transport: attachment.transport,
|
||||
encoding: attachment.encoding
|
||||
transport: attachment.transport
|
||||
});
|
||||
if(attachment.type == AttachmentType.FILE){
|
||||
/**
|
||||
|
||||
@@ -130,7 +130,6 @@ export function useDialogFiber() {
|
||||
id: attachment.id,
|
||||
type: attachment.type,
|
||||
preview: attachment.preview,
|
||||
encoding: attachment.encoding,
|
||||
transport: attachment.transport
|
||||
});
|
||||
}
|
||||
@@ -289,7 +288,6 @@ export function useDialogFiber() {
|
||||
id: attachment.id,
|
||||
type: attachment.type,
|
||||
preview: attachment.preview,
|
||||
encoding: attachment.encoding,
|
||||
transport: attachment.transport
|
||||
});
|
||||
}
|
||||
|
||||
@@ -191,7 +191,6 @@ export function useSynchronize() {
|
||||
id: attachment.id,
|
||||
type: attachment.type,
|
||||
preview: attachment.preview,
|
||||
encoding: attachment.encoding,
|
||||
transport: attachment.transport
|
||||
});
|
||||
}
|
||||
@@ -375,7 +374,6 @@ export function useSynchronize() {
|
||||
id: attachment.id,
|
||||
type: attachment.type,
|
||||
preview: attachment.preview,
|
||||
encoding: attachment.encoding,
|
||||
transport: attachment.transport
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,19 +17,6 @@ export interface AttachmentTransport {
|
||||
transport_server: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Информация о кодировке вложения
|
||||
*/
|
||||
export interface AttachmentEncoding {
|
||||
/**
|
||||
* Для кого вложение закодировано (для какого диалога)
|
||||
*/
|
||||
encoded_for: string;
|
||||
/**
|
||||
* Кто кодировал вложение
|
||||
*/
|
||||
encoder: string;
|
||||
}
|
||||
|
||||
export interface Attachment {
|
||||
id: string;
|
||||
@@ -37,7 +24,6 @@ export interface Attachment {
|
||||
type: AttachmentType;
|
||||
preview: string;
|
||||
transport: AttachmentTransport;
|
||||
encoding: AttachmentEncoding;
|
||||
}
|
||||
|
||||
export class PacketMessage extends Packet {
|
||||
@@ -79,11 +65,7 @@ export class PacketMessage extends Packet {
|
||||
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, encoding});
|
||||
this.attachments.push({id, preview, type, blob, transport});
|
||||
}
|
||||
this.aesChachaKey = stream.readString();
|
||||
}
|
||||
@@ -106,8 +88,6 @@ export class PacketMessage extends Packet {
|
||||
stream.writeInt8(this.attachments[i].type);
|
||||
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);
|
||||
}
|
||||
stream.writeString(this.aesChachaKey);
|
||||
return stream;
|
||||
|
||||
Reference in New Issue
Block a user