diff --git a/ts/components/conversation/Image.tsx b/ts/components/conversation/Image.tsx index f2aed75a2..b1a81c417 100644 --- a/ts/components/conversation/Image.tsx +++ b/ts/components/conversation/Image.tsx @@ -23,6 +23,7 @@ type Props = { playIconOverlay?: boolean; softCorners?: boolean; forceSquare?: boolean; + attachmentIndex?: number; onClick?: (attachment: AttachmentTypeWithPath | AttachmentType) => void; onClickClose?: (attachment: AttachmentTypeWithPath | AttachmentType) => void; @@ -45,6 +46,7 @@ export const Image = (props: Props) => { playIconOverlay, softCorners, forceSquare, + attachmentIndex, url, width, } = props; @@ -87,6 +89,7 @@ export const Image = (props: Props) => { maxHeight: `${height}px`, maxWidth: `${width}px`, }} + data-attachmentindex={attachmentIndex} > {pending || loading ? (
{ url={isMessageVisible ? getThumbnailUrl(attachments[0]) : undefined} onClick={onClickAttachment} onError={onError} + attachmentIndex={0} />
); @@ -65,6 +66,7 @@ export const ImageGrid = (props: Props) => { url={isMessageVisible ? getThumbnailUrl(attachments[0]) : undefined} onClick={onClickAttachment} onError={onError} + attachmentIndex={0} /> {getAlt(attachments[1])} { url={isMessageVisible ? getThumbnailUrl(attachments[1]) : undefined} onClick={onClickAttachment} onError={onError} + attachmentIndex={1} /> ); @@ -94,6 +97,7 @@ export const ImageGrid = (props: Props) => { url={isMessageVisible ? getThumbnailUrl(attachments[0]) : undefined} onClick={onClickAttachment} onError={onError} + attachmentIndex={0} />
{ url={isMessageVisible ? getThumbnailUrl(attachments[1]) : undefined} onClick={onClickAttachment} onError={onError} + attachmentIndex={1} /> {getAlt(attachments[2])} { url={isMessageVisible ? getThumbnailUrl(attachments[2]) : undefined} onClick={onClickAttachment} onError={onError} + attachmentIndex={2} />
@@ -136,6 +142,7 @@ export const ImageGrid = (props: Props) => { url={isMessageVisible ? getThumbnailUrl(attachments[0]) : undefined} onClick={onClickAttachment} onError={onError} + attachmentIndex={0} /> {getAlt(attachments[1])} { url={isMessageVisible ? getThumbnailUrl(attachments[1]) : undefined} onClick={onClickAttachment} onError={onError} + attachmentIndex={1} />
@@ -159,6 +167,7 @@ export const ImageGrid = (props: Props) => { url={isMessageVisible ? getThumbnailUrl(attachments[2]) : undefined} onClick={onClickAttachment} onError={onError} + attachmentIndex={2} /> {getAlt(attachments[3])} { url={isMessageVisible ? getThumbnailUrl(attachments[3]) : undefined} onClick={onClickAttachment} onError={onError} + attachmentIndex={3} />
@@ -193,6 +203,7 @@ export const ImageGrid = (props: Props) => { url={isMessageVisible ? getThumbnailUrl(attachments[0]) : undefined} onClick={onClickAttachment} onError={onError} + attachmentIndex={0} /> {getAlt(attachments[1])} { url={isMessageVisible ? getThumbnailUrl(attachments[1]) : undefined} onClick={onClickAttachment} onError={onError} + attachmentIndex={1} />
@@ -216,6 +228,7 @@ export const ImageGrid = (props: Props) => { url={isMessageVisible ? getThumbnailUrl(attachments[2]) : undefined} onClick={onClickAttachment} onError={onError} + attachmentIndex={2} /> {getAlt(attachments[3])} { url={isMessageVisible ? getThumbnailUrl(attachments[3]) : undefined} onClick={onClickAttachment} onError={onError} + attachmentIndex={3} /> {getAlt(attachments[4])} { url={isMessageVisible ? getThumbnailUrl(attachments[4]) : undefined} onClick={onClickAttachment} onError={onError} + attachmentIndex={4} />
diff --git a/ts/components/conversation/message/message-content/MessageContextMenu.tsx b/ts/components/conversation/message/message-content/MessageContextMenu.tsx index 68cdb7265..80e91a2e7 100644 --- a/ts/components/conversation/message/message-content/MessageContextMenu.tsx +++ b/ts/components/conversation/message/message-content/MessageContextMenu.tsx @@ -73,7 +73,6 @@ export const MessageContextMenu = (props: Props) => { const isOutgoing = direction === 'outgoing'; const showRetry = status === 'error' && isOutgoing; const isSent = status === 'sent' || status === 'read'; // a read message should be replyable - const multipleAttachments = attachments && attachments.length > 1; const onContextMenuShown = useCallback(() => { window.contextMenuShown = true; @@ -120,13 +119,23 @@ export const MessageContextMenu = (props: Props) => { const saveAttachment = useCallback( (e: any) => { + // this is quite dirty but considering that we want the context menu of the message to show on click on the attachment + // and the context menu save attachment item to save the right attachment I did not find a better way for now. + let targetAttachmentIndex = e.triggerEvent.path[1].getAttribute('data-attachmentindex'); e.event.stopPropagation(); if (!attachments?.length) { return; } + + if (!targetAttachmentIndex) { + targetAttachmentIndex = 0; + } + if (targetAttachmentIndex > attachments.length) { + return; + } const messageTimestamp = timestamp || serverTimestamp || 0; void saveAttachmentToDisk({ - attachment: attachments[0], + attachment: attachments[targetAttachmentIndex], messageTimestamp, messageSender: sender, conversationId: convoId, @@ -173,7 +182,7 @@ export const MessageContextMenu = (props: Props) => { onHidden={onContextMenuHidden} animation={animation.fade} > - {!multipleAttachments && attachments && attachments[0] ? ( + {attachments?.length ? ( {window.i18n('downloadAttachment')} ) : null}