Обновление протокола вложений
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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: ""
|
||||
|
||||
@@ -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
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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){
|
||||
|
||||
@@ -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
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user