add another type for when an outgoing attachment was imported to app

This commit is contained in:
audric 2022-01-13 09:57:49 +11:00
parent 3338a3c75b
commit 131195e2de
4 changed files with 13 additions and 12 deletions

View file

@ -6,7 +6,7 @@ import { arrayBufferFromFile } from '../../types/Attachment';
import { AttachmentUtil, LinkPreviewUtil } from '../../util';
import { fetchLinkPreviewImage } from '../../util/linkPreviewFetch';
import { StagedLinkPreview } from './StagedLinkPreview';
import { getImageDimensions } from '../../types/attachments/VisualAttachment';
import { getImageDimensions, THUMBNAIL_SIDE } from '../../types/attachments/VisualAttachment';
export interface StagedLinkPreviewProps extends StagedLinkPreviewData {
onClose: (url: string) => void;
@ -69,7 +69,7 @@ export const getPreview = async (
type: fullSizeImage.contentType,
}),
},
{ maxSize: 100 * 1000 } // this is a preview image. No need for it to be crazy big. 100k is big enough
{ maxSide: THUMBNAIL_SIDE, maxSize: 100 * 1000 } // this is a preview image. No need for it to be crazy big. 100k is big enough
);
const data = await arrayBufferFromFile(withBlob.blob);

View file

@ -46,6 +46,7 @@ import { Flex } from '../../basic/Flex';
import { CaptionEditor } from '../../CaptionEditor';
import { StagedAttachmentList } from '../StagedAttachmentList';
import { processNewAttachment } from '../../../types/MessageAttachment';
import { StagedAttachmentImportedType } from '../../../util/attachmentsUtil';
export interface ReplyingToMessageProps {
convoId: string;
@ -71,7 +72,7 @@ export interface StagedAttachmentType extends AttachmentType {
export type SendMessageType = {
body: string;
attachments: Array<StagedAttachmentType> | undefined;
attachments: Array<StagedAttachmentImportedType> | undefined;
quote: any | undefined;
preview: any | undefined;
groupInvitation: { url: string | undefined; name: string } | undefined;
@ -866,7 +867,7 @@ class CompositionBoxInner extends React.Component<Props, State> {
}
// this function is called right before sending a message, to gather really the files behind attachments.
private async getFiles(): Promise<Array<StagedAttachmentType & { flags?: number }>> {
private async getFiles(): Promise<Array<StagedAttachmentImportedType>> {
const { stagedAttachments } = this.props;
if (_.isEmpty(stagedAttachments)) {

View file

@ -162,10 +162,10 @@ export function isVideoAttachment(attachment?: AttachmentType): boolean {
);
}
export function hasVideoScreenshot(attachments?: Array<AttachmentType>) {
export function hasVideoScreenshot(attachments?: Array<AttachmentType>): boolean {
const firstAttachment = attachments ? attachments[0] : null;
return firstAttachment && firstAttachment.screenshot && firstAttachment.screenshot.url;
return Boolean(firstAttachment?.screenshot?.url);
}
type DimensionsType = {

View file

@ -213,9 +213,14 @@ export async function autoScale<T extends { contentType: string; blob: Blob }>(
};
}
export type StagedAttachmentImportedType = Omit<
StagedAttachmentType,
'file' | 'url' | 'fileSize'
> & { flags?: number };
export async function getFileAndStoreLocally(
attachment: StagedAttachmentType
): Promise<(StagedAttachmentType & { flags?: number }) | null> {
): Promise<StagedAttachmentImportedType | null> {
if (!attachment) {
return null;
}
@ -244,15 +249,10 @@ export async function getFileAndStoreLocally(
contentType: attachment.contentType,
});
console.warn('attachmentSavedLocally', attachmentSavedLocally);
return {
caption: attachment.caption,
contentType: attachment.contentType,
fileName: attachment.fileName,
file: new File([blob], 'getFile-blob'),
fileSize: null,
url: '',
path: attachmentSavedLocally.path,
width: scaled.width,
height: scaled.height,