parent
221f8ced1a
commit
002666d273
1 changed files with 20 additions and 10 deletions
|
|
@ -5,6 +5,7 @@ import {
|
|||
EventAttachmentUrlType,
|
||||
KeanuEvent,
|
||||
KeanuEventExtension,
|
||||
KeanuRoom,
|
||||
} from "./eventAttachment";
|
||||
import axios, { AxiosRequestConfig, AxiosResponse } from "axios";
|
||||
import { Counter, ModeOfOperation } from "aes-js";
|
||||
|
|
@ -48,11 +49,11 @@ export class AttachmentManager {
|
|||
.catch(() => {});
|
||||
}
|
||||
|
||||
public createUpload(room: Room) {
|
||||
public createUpload(room: KeanuRoom) {
|
||||
return createUploadBatch(this, room);
|
||||
}
|
||||
|
||||
public createAttachment(file: File, room: Room): Attachment {
|
||||
public createAttachment(file: File, room: KeanuRoom): Attachment {
|
||||
let a: Attachment = {
|
||||
status: "loading",
|
||||
file: file,
|
||||
|
|
@ -73,7 +74,7 @@ export class AttachmentManager {
|
|||
return ra;
|
||||
}
|
||||
|
||||
private async prepareUpload(attachment: Attachment, room: Room): Promise<Attachment> {
|
||||
private async prepareUpload(attachment: Attachment, room: KeanuRoom): Promise<Attachment> {
|
||||
const file = attachment.file;
|
||||
if (file.type.startsWith("image/")) {
|
||||
let url = URL.createObjectURL(file);
|
||||
|
|
@ -125,17 +126,26 @@ export class AttachmentManager {
|
|||
const isDirectRoom = (room: Room) => {
|
||||
// TODO - Use the is_direct accountData flag (m.direct). WE (as the client)
|
||||
// apprently need to set this...
|
||||
if (room && room.getJoinRule() == "invite" && room.getMembers().length == 2) {
|
||||
if (room && room.getJoinRule() == "invite" && room.getInvitedAndJoinedMemberCount() == 2) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
attachment.useCompressed =
|
||||
attachment.compressedFile !== undefined &&
|
||||
(attachment.proof === undefined ||
|
||||
!isDirectRoom(room) ||
|
||||
attachment.proof.integrity === undefined ||
|
||||
attachment.proof.integrity.c2pa === undefined);
|
||||
const isChannel = room.displayType == "im.keanu.room_type_channel";
|
||||
const isFileDrop = room.displayType == "im.keanu.room_type_file";
|
||||
|
||||
let useOriginal = false;
|
||||
if (isChannel) {
|
||||
useOriginal = false;
|
||||
} else if (isFileDrop) {
|
||||
useOriginal = true;
|
||||
} else {
|
||||
if (isDirectRoom(room) && attachment.proof?.integrity?.c2pa !== undefined) {
|
||||
useOriginal = true;
|
||||
}
|
||||
}
|
||||
|
||||
attachment.useCompressed = attachment.compressedFile !== undefined && !useOriginal;
|
||||
} catch (error) {
|
||||
console.error("Failed to get content credentials: " + error);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue