diff --git a/ts/components/ForwardMessageModal.stories.tsx b/ts/components/ForwardMessageModal.stories.tsx index beb8f3daff..050003a226 100644 --- a/ts/components/ForwardMessageModal.stories.tsx +++ b/ts/components/ForwardMessageModal.stories.tsx @@ -8,7 +8,7 @@ import { action } from '@storybook/addon-actions'; import { text } from '@storybook/addon-knobs'; import enMessages from '../../_locales/en/messages.json'; -import type { AttachmentDraftType } from '../types/Attachment'; +import type { AttachmentType } from '../types/Attachment'; import type { PropsType } from './ForwardMessageModal'; import { ForwardMessageModal } from './ForwardMessageModal'; import { IMAGE_JPEG, VIDEO_MP4, stringToMIMEType } from '../types/MIME'; @@ -16,9 +16,9 @@ import { getDefaultConversation } from '../test-both/helpers/getDefaultConversat import { setupI18n } from '../util/setupI18n'; import { StorybookThemeContext } from '../../.storybook/StorybookThemeContext'; -const createDraftAttachment = ( - props: Partial = {} -): AttachmentDraftType => ({ +const createAttachment = ( + props: Partial = {} +): AttachmentType => ({ pending: false, path: 'fileName.jpg', contentType: stringToMIMEType( @@ -83,7 +83,7 @@ story.add('link preview', () => { date: Date.now(), domain: 'https://www.signal.org', url: 'signal.org', - image: createDraftAttachment({ + image: createAttachment({ url: '/fixtures/kitten-4-112-112.jpg', contentType: IMAGE_JPEG, }), @@ -101,15 +101,15 @@ story.add('media attachments', () => { ; + attachments?: Array; candidateConversations: ReadonlyArray; doForwardMessage: ( selectedContacts: Array, messageBody?: string, - attachments?: Array, + attachments?: Array, linkPreview?: LinkPreviewType ) => void; getPreferredBadge: PreferredBadgeSelectorType; @@ -102,7 +102,7 @@ export const ForwardMessageModal: FunctionComponent = ({ filterAndSortConversationsByRecent(candidateConversations, '') ); const [attachmentsToForward, setAttachmentsToForward] = useState< - Array + Array >(attachments || []); const [isEditingMessage, setIsEditingMessage] = useState(false); const [messageBodyText, setMessageBodyText] = useState(messageBody || ''); @@ -325,7 +325,7 @@ export const ForwardMessageModal: FunctionComponent = ({ { + onCloseAttachment={(attachment: AttachmentType) => { const newAttachments = attachmentsToForward.filter( currentAttachment => currentAttachment !== attachment ); diff --git a/ts/components/conversation/AttachmentList.stories.tsx b/ts/components/conversation/AttachmentList.stories.tsx index ef4692969e..25464fda46 100644 --- a/ts/components/conversation/AttachmentList.stories.tsx +++ b/ts/components/conversation/AttachmentList.stories.tsx @@ -6,6 +6,7 @@ import * as React from 'react'; import { action } from '@storybook/addon-actions'; import { storiesOf } from '@storybook/react'; +import type { AttachmentDraftType } from '../../types/Attachment'; import type { Props } from './AttachmentList'; import { AttachmentList } from './AttachmentList'; import { @@ -24,7 +25,9 @@ const i18n = setupI18n('en', enMessages); const story = storiesOf('Components/Conversation/AttachmentList', module); -const createProps = (overrideProps: Partial = {}): Props => ({ +const createProps = ( + overrideProps: Partial> = {} +): Props => ({ attachments: overrideProps.attachments || [], i18n, onAddAttachment: action('onAddAttachment'), diff --git a/ts/components/conversation/AttachmentList.tsx b/ts/components/conversation/AttachmentList.tsx index ac6006b97f..a39d399e58 100644 --- a/ts/components/conversation/AttachmentList.tsx +++ b/ts/components/conversation/AttachmentList.tsx @@ -7,7 +7,10 @@ import { Image } from './Image'; import { StagedGenericAttachment } from './StagedGenericAttachment'; import { StagedPlaceholderAttachment } from './StagedPlaceholderAttachment'; import type { LocalizerType } from '../../types/Util'; -import type { AttachmentDraftType } from '../../types/Attachment'; +import type { + AttachmentType, + AttachmentDraftType, +} from '../../types/Attachment'; import { areAllAttachmentsVisual, canDisplayImage, @@ -15,14 +18,14 @@ import { isVideoAttachment, } from '../../types/Attachment'; -export type Props = Readonly<{ - attachments: ReadonlyArray; +export type Props = Readonly<{ + attachments: ReadonlyArray; canEditImages?: boolean; i18n: LocalizerType; onAddAttachment?: () => void; - onClickAttachment?: (attachment: AttachmentDraftType) => void; + onClickAttachment?: (attachment: T) => void; onClose?: () => void; - onCloseAttachment: (attachment: AttachmentDraftType) => void; + onCloseAttachment: (attachment: T) => void; }>; const IMAGE_WIDTH = 120; @@ -32,15 +35,21 @@ const IMAGE_HEIGHT = 120; const BLANK_VIDEO_THUMBNAIL = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAA3bvkkAAAACklEQVR42mNiAAAABgADm78GJQAAAABJRU5ErkJggg=='; -function getUrl(attachment: AttachmentDraftType): string | undefined { +function getUrl( + attachment: AttachmentType | AttachmentDraftType +): string | undefined { if (attachment.pending) { return undefined; } + if ('screenshot' in attachment) { + return attachment.screenshot?.url || attachment.url; + } + return attachment.url; } -export const AttachmentList = ({ +export const AttachmentList = ({ attachments, canEditImages, i18n, @@ -48,7 +57,7 @@ export const AttachmentList = ({ onClickAttachment, onCloseAttachment, onClose, -}: Props): JSX.Element | null => { +}: Props): JSX.Element | null => { if (!attachments.length) { return null; } diff --git a/ts/state/smart/ForwardMessageModal.tsx b/ts/state/smart/ForwardMessageModal.tsx index c3525ff5b1..62558b5208 100644 --- a/ts/state/smart/ForwardMessageModal.tsx +++ b/ts/state/smart/ForwardMessageModal.tsx @@ -14,14 +14,14 @@ import { getLinkPreview } from '../selectors/linkPreviews'; import { getIntl, getTheme } from '../selectors/user'; import { getEmojiSkinTone } from '../selectors/items'; import { selectRecentEmojis } from '../selectors/emojis'; -import type { AttachmentDraftType } from '../../types/Attachment'; +import type { AttachmentType } from '../../types/Attachment'; export type SmartForwardMessageModalProps = { - attachments?: Array; + attachments?: Array; doForwardMessage: ( selectedContacts: Array, messageBody?: string, - attachments?: Array, + attachments?: Array, linkPreview?: LinkPreviewType ) => void; isSticker: boolean; diff --git a/ts/views/conversation_view.ts b/ts/views/conversation_view.ts index 7b67dc8b44..06bfc2805a 100644 --- a/ts/views/conversation_view.ts +++ b/ts/views/conversation_view.ts @@ -7,7 +7,7 @@ import { batch as batchDispatch } from 'react-redux'; import { debounce, flatten, omit, throttle } from 'lodash'; import { render } from 'mustache'; -import type { AttachmentDraftType, AttachmentType } from '../types/Attachment'; +import type { AttachmentType } from '../types/Attachment'; import { isGIF } from '../types/Attachment'; import * as Attachment from '../types/Attachment'; import type { StickerPackType as StickerPackDBType } from '../sql/Interface'; @@ -1265,31 +1265,16 @@ export class ConversationView extends window.Backbone.View { } const attachments = getAttachmentsForMessage(message.attributes); - const draftAttachments = attachments - .map((item: AttachmentType): AttachmentDraftType | null => { - const { path } = item; - if (!path) { - return null; - } - - return { - ...item, - path, - pending: false as const, - screenshotPath: item.screenshot?.path, - }; - }) - .filter(isNotNil); this.forwardMessageModal = new Whisper.ReactWrapperView({ JSX: window.Signal.State.Roots.createForwardMessageModal( window.reduxStore, { - attachments: draftAttachments, + attachments, doForwardMessage: async ( conversationIds: Array, messageBody?: string, - includedAttachments?: Array, + includedAttachments?: Array, linkPreview?: LinkPreviewType ) => { try { @@ -1338,7 +1323,7 @@ export class ConversationView extends window.Backbone.View { message: MessageModel, conversationIds: Array, messageBody?: string, - attachments?: Array, + attachments?: Array, linkPreview?: LinkPreviewType ): Promise { log.info(`maybeForwardMessage/${message.idForLogging()}: Starting...`);