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