From bdbc48590e4caf586f44a6635c9ef674d17b649e Mon Sep 17 00:00:00 2001 From: yougotwill Date: Thu, 15 Aug 2024 10:06:15 +1000 Subject: [PATCH] feat: consolidated attachment types --- ts/state/ducks/conversations.ts | 29 +++-------------- ts/types/Attachment.ts | 56 ++++++++++++++------------------- 2 files changed, 27 insertions(+), 58 deletions(-) diff --git a/ts/state/ducks/conversations.ts b/ts/state/ducks/conversations.ts index ad5064570..3f1a4a96f 100644 --- a/ts/state/ducks/conversations.ts +++ b/ts/state/ducks/conversations.ts @@ -25,6 +25,7 @@ import { PropsForCallNotification, PropsForInteractionNotification, } from './types'; +import { AttachmentType } from '../../types/Attachment'; export type MessageModelPropsWithoutConvoProps = { propsForMessage: PropsForMessageWithoutConvoProps; @@ -128,35 +129,13 @@ export type PropsForGroupInvitation = { messageId: string; }; -export type PropsForAttachment = { +export type PropsForAttachment = AttachmentType & { id: number; - contentType: string; - caption?: string; + isVoiceMessage: boolean; size: number; - width?: number; - height?: number; - duration?: string; - url: string; path: string; - fileSize: string | null; - isVoiceMessage: boolean; pending: boolean; - fileName: string; - error?: number; // if the download somhehow failed, this will be set to true and be 0-1 once saved in the db - screenshot: { - contentType: string; - width: number; - height: number; - url?: string; - path?: string; - } | null; - thumbnail: { - contentType: string; - width: number; - height: number; - url?: string; - path?: string; - } | null; + error?: number; // if the download somehow failed, this will be set to true and be 0 or 1 in the db }; export type PropsForQuote = { diff --git a/ts/types/Attachment.ts b/ts/types/Attachment.ts index 1154f6b64..aec9057b5 100644 --- a/ts/types/Attachment.ts +++ b/ts/types/Attachment.ts @@ -13,35 +13,40 @@ const MAX_HEIGHT = THUMBNAIL_SIDE; const MIN_WIDTH = THUMBNAIL_SIDE; const MIN_HEIGHT = THUMBNAIL_SIDE; -// Used for display +// Used for displaying attachments in the UI +export type AttachmentScreenshot = { + contentType: MIME.MIMEType; + height: number; + width: number; + url?: string; + path?: string; +}; + +export type AttachmentThumbnail = { + contentType: MIME.MIMEType; + height: number; + width: number; + url?: string; + path?: string; +}; export interface AttachmentType { - caption?: string; contentType: MIME.MIMEType; fileName: string; - /** Not included in protobuf, needs to be pulled from flags */ - isVoiceMessage?: boolean; /** For messages not already on disk, this will be a data url */ url: string; - videoUrl?: string; - size?: number; fileSize: string | null; pending?: boolean; + screenshot: AttachmentScreenshot | null; + thumbnail: AttachmentThumbnail | null; + caption?: string; + size?: number; width?: number; height?: number; duration?: string; - screenshot: { - height: number; - width: number; - url?: string; - contentType: MIME.MIMEType; - } | null; - thumbnail: { - height: number; - width: number; - url?: string; - contentType: MIME.MIMEType; - } | null; + videoUrl?: string; + /** Not included in protobuf, needs to be pulled from flags */ + isVoiceMessage?: boolean; } export interface AttachmentTypeWithPath extends AttachmentType { @@ -49,21 +54,6 @@ export interface AttachmentTypeWithPath extends AttachmentType { id: number; flags?: number; error?: any; - - screenshot: { - height: number; - width: number; - url?: string; - contentType: MIME.MIMEType; - path?: string; - } | null; - thumbnail: { - height: number; - width: number; - url?: string; - contentType: MIME.MIMEType; - path?: string; - } | null; } // UI-focused functions