allow to save attachments even if there is multiple of them

This is a bit dirty for now

Relates #2229
pull/2252/head
Audric Ackermann 3 years ago
parent 1933bc8270
commit cae4d46492
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -23,6 +23,7 @@ type Props = {
playIconOverlay?: boolean; playIconOverlay?: boolean;
softCorners?: boolean; softCorners?: boolean;
forceSquare?: boolean; forceSquare?: boolean;
attachmentIndex?: number;
onClick?: (attachment: AttachmentTypeWithPath | AttachmentType) => void; onClick?: (attachment: AttachmentTypeWithPath | AttachmentType) => void;
onClickClose?: (attachment: AttachmentTypeWithPath | AttachmentType) => void; onClickClose?: (attachment: AttachmentTypeWithPath | AttachmentType) => void;
@ -45,6 +46,7 @@ export const Image = (props: Props) => {
playIconOverlay, playIconOverlay,
softCorners, softCorners,
forceSquare, forceSquare,
attachmentIndex,
url, url,
width, width,
} = props; } = props;
@ -87,6 +89,7 @@ export const Image = (props: Props) => {
maxHeight: `${height}px`, maxHeight: `${height}px`,
maxWidth: `${width}px`, maxWidth: `${width}px`,
}} }}
data-attachmentindex={attachmentIndex}
> >
{pending || loading ? ( {pending || loading ? (
<div <div

@ -47,6 +47,7 @@ export const ImageGrid = (props: Props) => {
url={isMessageVisible ? getThumbnailUrl(attachments[0]) : undefined} url={isMessageVisible ? getThumbnailUrl(attachments[0]) : undefined}
onClick={onClickAttachment} onClick={onClickAttachment}
onError={onError} onError={onError}
attachmentIndex={0}
/> />
</div> </div>
); );
@ -65,6 +66,7 @@ export const ImageGrid = (props: Props) => {
url={isMessageVisible ? getThumbnailUrl(attachments[0]) : undefined} url={isMessageVisible ? getThumbnailUrl(attachments[0]) : undefined}
onClick={onClickAttachment} onClick={onClickAttachment}
onError={onError} onError={onError}
attachmentIndex={0}
/> />
<Image <Image
alt={getAlt(attachments[1])} alt={getAlt(attachments[1])}
@ -76,6 +78,7 @@ export const ImageGrid = (props: Props) => {
url={isMessageVisible ? getThumbnailUrl(attachments[1]) : undefined} url={isMessageVisible ? getThumbnailUrl(attachments[1]) : undefined}
onClick={onClickAttachment} onClick={onClickAttachment}
onError={onError} onError={onError}
attachmentIndex={1}
/> />
</div> </div>
); );
@ -94,6 +97,7 @@ export const ImageGrid = (props: Props) => {
url={isMessageVisible ? getThumbnailUrl(attachments[0]) : undefined} url={isMessageVisible ? getThumbnailUrl(attachments[0]) : undefined}
onClick={onClickAttachment} onClick={onClickAttachment}
onError={onError} onError={onError}
attachmentIndex={0}
/> />
<div className="module-image-grid__column"> <div className="module-image-grid__column">
<Image <Image
@ -105,6 +109,7 @@ export const ImageGrid = (props: Props) => {
url={isMessageVisible ? getThumbnailUrl(attachments[1]) : undefined} url={isMessageVisible ? getThumbnailUrl(attachments[1]) : undefined}
onClick={onClickAttachment} onClick={onClickAttachment}
onError={onError} onError={onError}
attachmentIndex={1}
/> />
<Image <Image
alt={getAlt(attachments[2])} alt={getAlt(attachments[2])}
@ -116,6 +121,7 @@ export const ImageGrid = (props: Props) => {
url={isMessageVisible ? getThumbnailUrl(attachments[2]) : undefined} url={isMessageVisible ? getThumbnailUrl(attachments[2]) : undefined}
onClick={onClickAttachment} onClick={onClickAttachment}
onError={onError} onError={onError}
attachmentIndex={2}
/> />
</div> </div>
</div> </div>
@ -136,6 +142,7 @@ export const ImageGrid = (props: Props) => {
url={isMessageVisible ? getThumbnailUrl(attachments[0]) : undefined} url={isMessageVisible ? getThumbnailUrl(attachments[0]) : undefined}
onClick={onClickAttachment} onClick={onClickAttachment}
onError={onError} onError={onError}
attachmentIndex={0}
/> />
<Image <Image
alt={getAlt(attachments[1])} alt={getAlt(attachments[1])}
@ -146,6 +153,7 @@ export const ImageGrid = (props: Props) => {
url={isMessageVisible ? getThumbnailUrl(attachments[1]) : undefined} url={isMessageVisible ? getThumbnailUrl(attachments[1]) : undefined}
onClick={onClickAttachment} onClick={onClickAttachment}
onError={onError} onError={onError}
attachmentIndex={1}
/> />
</div> </div>
<div className="module-image-grid__row"> <div className="module-image-grid__row">
@ -159,6 +167,7 @@ export const ImageGrid = (props: Props) => {
url={isMessageVisible ? getThumbnailUrl(attachments[2]) : undefined} url={isMessageVisible ? getThumbnailUrl(attachments[2]) : undefined}
onClick={onClickAttachment} onClick={onClickAttachment}
onError={onError} onError={onError}
attachmentIndex={2}
/> />
<Image <Image
alt={getAlt(attachments[3])} alt={getAlt(attachments[3])}
@ -170,6 +179,7 @@ export const ImageGrid = (props: Props) => {
url={isMessageVisible ? getThumbnailUrl(attachments[3]) : undefined} url={isMessageVisible ? getThumbnailUrl(attachments[3]) : undefined}
onClick={onClickAttachment} onClick={onClickAttachment}
onError={onError} onError={onError}
attachmentIndex={3}
/> />
</div> </div>
</div> </div>
@ -193,6 +203,7 @@ export const ImageGrid = (props: Props) => {
url={isMessageVisible ? getThumbnailUrl(attachments[0]) : undefined} url={isMessageVisible ? getThumbnailUrl(attachments[0]) : undefined}
onClick={onClickAttachment} onClick={onClickAttachment}
onError={onError} onError={onError}
attachmentIndex={0}
/> />
<Image <Image
alt={getAlt(attachments[1])} alt={getAlt(attachments[1])}
@ -203,6 +214,7 @@ export const ImageGrid = (props: Props) => {
url={isMessageVisible ? getThumbnailUrl(attachments[1]) : undefined} url={isMessageVisible ? getThumbnailUrl(attachments[1]) : undefined}
onClick={onClickAttachment} onClick={onClickAttachment}
onError={onError} onError={onError}
attachmentIndex={1}
/> />
</div> </div>
<div className="module-image-grid__row"> <div className="module-image-grid__row">
@ -216,6 +228,7 @@ export const ImageGrid = (props: Props) => {
url={isMessageVisible ? getThumbnailUrl(attachments[2]) : undefined} url={isMessageVisible ? getThumbnailUrl(attachments[2]) : undefined}
onClick={onClickAttachment} onClick={onClickAttachment}
onError={onError} onError={onError}
attachmentIndex={2}
/> />
<Image <Image
alt={getAlt(attachments[3])} alt={getAlt(attachments[3])}
@ -227,6 +240,7 @@ export const ImageGrid = (props: Props) => {
url={isMessageVisible ? getThumbnailUrl(attachments[3]) : undefined} url={isMessageVisible ? getThumbnailUrl(attachments[3]) : undefined}
onClick={onClickAttachment} onClick={onClickAttachment}
onError={onError} onError={onError}
attachmentIndex={3}
/> />
<Image <Image
alt={getAlt(attachments[4])} alt={getAlt(attachments[4])}
@ -240,6 +254,7 @@ export const ImageGrid = (props: Props) => {
url={isMessageVisible ? getThumbnailUrl(attachments[4]) : undefined} url={isMessageVisible ? getThumbnailUrl(attachments[4]) : undefined}
onClick={onClickAttachment} onClick={onClickAttachment}
onError={onError} onError={onError}
attachmentIndex={4}
/> />
</div> </div>
</div> </div>

@ -73,7 +73,6 @@ export const MessageContextMenu = (props: Props) => {
const isOutgoing = direction === 'outgoing'; const isOutgoing = direction === 'outgoing';
const showRetry = status === 'error' && isOutgoing; const showRetry = status === 'error' && isOutgoing;
const isSent = status === 'sent' || status === 'read'; // a read message should be replyable const isSent = status === 'sent' || status === 'read'; // a read message should be replyable
const multipleAttachments = attachments && attachments.length > 1;
const onContextMenuShown = useCallback(() => { const onContextMenuShown = useCallback(() => {
window.contextMenuShown = true; window.contextMenuShown = true;
@ -120,13 +119,23 @@ export const MessageContextMenu = (props: Props) => {
const saveAttachment = useCallback( const saveAttachment = useCallback(
(e: any) => { (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(); e.event.stopPropagation();
if (!attachments?.length) { if (!attachments?.length) {
return; return;
} }
if (!targetAttachmentIndex) {
targetAttachmentIndex = 0;
}
if (targetAttachmentIndex > attachments.length) {
return;
}
const messageTimestamp = timestamp || serverTimestamp || 0; const messageTimestamp = timestamp || serverTimestamp || 0;
void saveAttachmentToDisk({ void saveAttachmentToDisk({
attachment: attachments[0], attachment: attachments[targetAttachmentIndex],
messageTimestamp, messageTimestamp,
messageSender: sender, messageSender: sender,
conversationId: convoId, conversationId: convoId,
@ -173,7 +182,7 @@ export const MessageContextMenu = (props: Props) => {
onHidden={onContextMenuHidden} onHidden={onContextMenuHidden}
animation={animation.fade} animation={animation.fade}
> >
{!multipleAttachments && attachments && attachments[0] ? ( {attachments?.length ? (
<Item onClick={saveAttachment}>{window.i18n('downloadAttachment')}</Item> <Item onClick={saveAttachment}>{window.i18n('downloadAttachment')}</Item>
) : null} ) : null}

Loading…
Cancel
Save