Обновление протокола вложений
This commit is contained in:
@@ -90,8 +90,10 @@ export function DialogInput() {
|
|||||||
id: generateRandomKey(8),
|
id: generateRandomKey(8),
|
||||||
type: AttachmentType.FILE,
|
type: AttachmentType.FILE,
|
||||||
preview: files[0].size + "::" + files[0].name,
|
preview: files[0].size + "::" + files[0].name,
|
||||||
transport_server: "",
|
transport: {
|
||||||
transport_tag: "",
|
transport_server: "",
|
||||||
|
transport_tag: ""
|
||||||
|
},
|
||||||
encoding: {
|
encoding: {
|
||||||
encoded_for: dialog,
|
encoded_for: dialog,
|
||||||
encoder: publicKey
|
encoder: publicKey
|
||||||
@@ -123,8 +125,10 @@ export function DialogInput() {
|
|||||||
id: generateRandomKey(8),
|
id: generateRandomKey(8),
|
||||||
blob: JSON.stringify([...replyMessages.messages]),
|
blob: JSON.stringify([...replyMessages.messages]),
|
||||||
preview: "",
|
preview: "",
|
||||||
transport_server: "",
|
transport: {
|
||||||
transport_tag: "",
|
transport_server: "",
|
||||||
|
transport_tag: ""
|
||||||
|
},
|
||||||
encoding: {
|
encoding: {
|
||||||
encoded_for: dialog,
|
encoded_for: dialog,
|
||||||
encoder: publicKey
|
encoder: publicKey
|
||||||
@@ -243,8 +247,10 @@ export function DialogInput() {
|
|||||||
id: generateRandomKey(8),
|
id: generateRandomKey(8),
|
||||||
type: AttachmentType.AVATAR,
|
type: AttachmentType.AVATAR,
|
||||||
preview: "",
|
preview: "",
|
||||||
transport_server: "",
|
transport: {
|
||||||
transport_tag: "",
|
transport_server: "",
|
||||||
|
transport_tag: ""
|
||||||
|
},
|
||||||
encoding: {
|
encoding: {
|
||||||
encoded_for: dialog,
|
encoded_for: dialog,
|
||||||
encoder: publicKey
|
encoder: publicKey
|
||||||
@@ -289,8 +295,10 @@ export function DialogInput() {
|
|||||||
id: attachmentId,
|
id: attachmentId,
|
||||||
type: AttachmentType.IMAGE,
|
type: AttachmentType.IMAGE,
|
||||||
preview: "",
|
preview: "",
|
||||||
transport_server: "",
|
transport: {
|
||||||
transport_tag: "",
|
transport_server: "",
|
||||||
|
transport_tag: ""
|
||||||
|
},
|
||||||
encoding: {
|
encoding: {
|
||||||
encoded_for: dialog,
|
encoded_for: dialog,
|
||||||
encoder: publicKey
|
encoder: publicKey
|
||||||
@@ -329,8 +337,10 @@ export function DialogInput() {
|
|||||||
id: attachmentId,
|
id: attachmentId,
|
||||||
type: AttachmentType.FILE,
|
type: AttachmentType.FILE,
|
||||||
preview: files[0].size + "::" + files[0].name,
|
preview: files[0].size + "::" + files[0].name,
|
||||||
transport_server: "",
|
transport: {
|
||||||
transport_tag: "",
|
transport_server: "",
|
||||||
|
transport_tag: ""
|
||||||
|
},
|
||||||
encoding: {
|
encoding: {
|
||||||
encoded_for: dialog,
|
encoded_for: dialog,
|
||||||
encoder: publicKey
|
encoder: publicKey
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ export function useAttachment(attachment: Attachment, parentMessage: MessageProp
|
|||||||
const uploadedPercentage = useUploadStatus(attachment.id);
|
const uploadedPercentage = useUploadStatus(attachment.id);
|
||||||
const downloadPercentage = useDownloadStatus(attachment.id);
|
const downloadPercentage = useDownloadStatus(attachment.id);
|
||||||
const [downloadStatus, setDownloadStatus] = useMemory("attachment-downloaded-status-" + attachment.id, DownloadStatus.PENDING, true);
|
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 {readFile, writeFile, fileExists, size} = useFileStorage();
|
||||||
const { downloadFile } = useTransport();
|
const { downloadFile } = useTransport();
|
||||||
const publicKey = usePublicKey();
|
const publicKey = usePublicKey();
|
||||||
@@ -56,7 +56,7 @@ export function useAttachment(attachment: Attachment, parentMessage: MessageProp
|
|||||||
if (downloadStatus == DownloadStatus.DOWNLOADED) {
|
if (downloadStatus == DownloadStatus.DOWNLOADED) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(attachment.transport_tag == ""){
|
if(attachment.transport.transport_tag == ""){
|
||||||
/**
|
/**
|
||||||
* Транспортного тега нет только у сообщений отправленных нами, значит он точно наш
|
* Транспортного тега нет только у сообщений отправленных нами, значит он точно наш
|
||||||
*/
|
*/
|
||||||
@@ -130,7 +130,7 @@ export function useAttachment(attachment: Attachment, parentMessage: MessageProp
|
|||||||
let downloadedBlob = '';
|
let downloadedBlob = '';
|
||||||
try {
|
try {
|
||||||
downloadedBlob = await downloadFile(attachment.id,
|
downloadedBlob = await downloadFile(attachment.id,
|
||||||
downloadTag, attachment.transport_server);
|
downloadTag, attachment.transport.transport_server);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.info(e);
|
console.info(e);
|
||||||
info("Error downloading attachment: " + attachment.id);
|
info("Error downloading attachment: " + attachment.id);
|
||||||
|
|||||||
@@ -141,8 +141,10 @@ export function usePrepareAttachment() {
|
|||||||
}
|
}
|
||||||
prepared.push({
|
prepared.push({
|
||||||
...attachment,
|
...attachment,
|
||||||
transport_server: transportServer || "",
|
transport: {
|
||||||
transport_tag: tag,
|
transport_server: transportServer || "",
|
||||||
|
transport_tag: tag
|
||||||
|
},
|
||||||
encoding: {
|
encoding: {
|
||||||
encoded_for: dialog,
|
encoded_for: dialog,
|
||||||
encoder: publicKey
|
encoder: publicKey
|
||||||
|
|||||||
@@ -472,8 +472,10 @@ export function CallProvider(props : CallProviderProps) {
|
|||||||
id: generateRandomKey(16),
|
id: generateRandomKey(16),
|
||||||
preview: duration.toString(),
|
preview: duration.toString(),
|
||||||
type: AttachmentType.CALL,
|
type: AttachmentType.CALL,
|
||||||
transport_server: "",
|
transport: {
|
||||||
transport_tag: "",
|
transport_server: "",
|
||||||
|
transport_tag: ""
|
||||||
|
},
|
||||||
encoding: {
|
encoding: {
|
||||||
encoded_for: "",
|
encoded_for: "",
|
||||||
encoder: ""
|
encoder: ""
|
||||||
|
|||||||
@@ -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, 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 { 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';
|
||||||
@@ -46,9 +46,8 @@ export interface AttachmentMeta {
|
|||||||
id: string;
|
id: string;
|
||||||
type: AttachmentType;
|
type: AttachmentType;
|
||||||
preview: string;
|
preview: string;
|
||||||
transport_tag: string;
|
transport: AttachmentTransport;
|
||||||
encoding: AttachmentEncoding;
|
encoding: AttachmentEncoding;
|
||||||
transport_server: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Message {
|
export interface Message {
|
||||||
@@ -960,8 +959,7 @@ export function DialogProvider(props: DialogProviderProps) {
|
|||||||
blob: blob,
|
blob: blob,
|
||||||
type: meta.type,
|
type: meta.type,
|
||||||
preview: meta.preview,
|
preview: meta.preview,
|
||||||
transport_server: meta.transport_server,
|
transport: meta.transport,
|
||||||
transport_tag: meta.transport_tag,
|
|
||||||
encoding: meta.encoding
|
encoding: meta.encoding
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,8 +119,7 @@ export function useDialog() : {
|
|||||||
id: attachment.id,
|
id: attachment.id,
|
||||||
type: attachment.type,
|
type: attachment.type,
|
||||||
preview: attachment.preview,
|
preview: attachment.preview,
|
||||||
transport_server: attachment.transport_server,
|
transport: attachment.transport,
|
||||||
transport_tag: attachment.transport_tag,
|
|
||||||
encoding: attachment.encoding
|
encoding: attachment.encoding
|
||||||
});
|
});
|
||||||
if(attachment.type == AttachmentType.FILE){
|
if(attachment.type == AttachmentType.FILE){
|
||||||
|
|||||||
@@ -192,8 +192,7 @@ export function useSynchronize() {
|
|||||||
type: attachment.type,
|
type: attachment.type,
|
||||||
preview: attachment.preview,
|
preview: attachment.preview,
|
||||||
encoding: attachment.encoding,
|
encoding: attachment.encoding,
|
||||||
transport_server: attachment.transport_server,
|
transport: attachment.transport
|
||||||
transport_tag: attachment.transport_tag
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -377,8 +376,7 @@ export function useSynchronize() {
|
|||||||
type: attachment.type,
|
type: attachment.type,
|
||||||
preview: attachment.preview,
|
preview: attachment.preview,
|
||||||
encoding: attachment.encoding,
|
encoding: attachment.encoding,
|
||||||
transport_server: attachment.transport_server,
|
transport: attachment.transport
|
||||||
transport_tag: attachment.transport_tag
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,17 @@ export enum AttachmentType {
|
|||||||
CALL = 4
|
CALL = 4
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Информация о транспортировке вложения, нужна для загрузки и скачивания вложений с транспортного сервера
|
||||||
|
*/
|
||||||
|
export interface AttachmentTransport {
|
||||||
|
transport_tag: string;
|
||||||
|
transport_server: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Информация о кодировке вложения
|
||||||
|
*/
|
||||||
export interface AttachmentEncoding {
|
export interface AttachmentEncoding {
|
||||||
/**
|
/**
|
||||||
* Для кого вложение закодировано (для какого диалога)
|
* Для кого вложение закодировано (для какого диалога)
|
||||||
@@ -25,8 +36,7 @@ export interface Attachment {
|
|||||||
blob: string;
|
blob: string;
|
||||||
type: AttachmentType;
|
type: AttachmentType;
|
||||||
preview: string;
|
preview: string;
|
||||||
transport_tag: string;
|
transport: AttachmentTransport;
|
||||||
transport_server: string;
|
|
||||||
encoding: AttachmentEncoding;
|
encoding: AttachmentEncoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,13 +75,15 @@ export class PacketMessage extends Packet {
|
|||||||
let preview = stream.readString();
|
let preview = stream.readString();
|
||||||
let blob = stream.readString();
|
let blob = stream.readString();
|
||||||
let type = stream.readInt8() as AttachmentType;
|
let type = stream.readInt8() as AttachmentType;
|
||||||
let transport_tag = stream.readString();
|
const transport : AttachmentTransport = {
|
||||||
let transport_server = stream.readString();
|
transport_tag: stream.readString(),
|
||||||
|
transport_server: stream.readString()
|
||||||
|
}
|
||||||
const encoding : AttachmentEncoding = {
|
const encoding : AttachmentEncoding = {
|
||||||
encoded_for: stream.readString(),
|
encoded_for: stream.readString(),
|
||||||
encoder: 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();
|
this.aesChachaKey = stream.readString();
|
||||||
}
|
}
|
||||||
@@ -92,8 +104,8 @@ export class PacketMessage extends Packet {
|
|||||||
stream.writeString(this.attachments[i].preview);
|
stream.writeString(this.attachments[i].preview);
|
||||||
stream.writeString(this.attachments[i].blob);
|
stream.writeString(this.attachments[i].blob);
|
||||||
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.transport_tag);
|
||||||
stream.writeString(this.attachments[i].transport_server);
|
stream.writeString(this.attachments[i].transport.transport_server);
|
||||||
stream.writeString(this.attachments[i].encoding.encoded_for);
|
stream.writeString(this.attachments[i].encoding.encoded_for);
|
||||||
stream.writeString(this.attachments[i].encoding.encoder);
|
stream.writeString(this.attachments[i].encoding.encoder);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user