diff --git a/js/models/messages.js b/js/models/messages.js index 77987e0ea..3b9af8484 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -620,11 +620,6 @@ onShowDetail: () => this.trigger('show-message-detail', this), onDelete: () => this.trigger('delete', this), onClickLinkPreview: url => this.trigger('navigate-to', url), - onClickAttachment: attachment => - this.trigger('show-lightbox', { - attachment, - message: this, - }), onDownload: isDangerous => this.trigger('download', { diff --git a/ts/components/session/conversation/SessionConversation.tsx b/ts/components/session/conversation/SessionConversation.tsx index 2712c7fca..d8cd3162b 100644 --- a/ts/components/session/conversation/SessionConversation.tsx +++ b/ts/components/session/conversation/SessionConversation.tsx @@ -16,7 +16,7 @@ import { SessionRightPanelWithDetails } from './SessionRightPanel'; import { SessionTheme } from '../../../state/ducks/SessionTheme'; import { DefaultTheme } from 'styled-components'; import { SessionConversationMessagesList } from './SessionConversationMessagesList'; -import { LightboxGallery } from '../../LightboxGallery'; +import { LightboxGallery, MediaItemType } from '../../LightboxGallery'; import { Message } from '../../conversation/media-gallery/types/Message'; import { AttachmentType } from '../../../types/Attachment'; @@ -121,12 +121,13 @@ export class SessionConversation extends React.Component { this.deleteSelectedMessages = this.deleteSelectedMessages.bind(this); this.replyToMessage = this.replyToMessage.bind(this); + this.onClickAttachment = this.onClickAttachment.bind(this); this.getMessages = this.getMessages.bind(this); // Keyboard navigation this.onKeyDown = this.onKeyDown.bind(this); - this.showLightBox = this.showLightBox.bind(this); + this.renderLightBox = this.renderLightBox.bind(this); const conversationModel = window.ConversationController.getOrThrow( this.state.conversationKey @@ -224,7 +225,7 @@ export class SessionConversation extends React.Component { {showMessageDetails && <> } - {lightBoxOptions?.media && this.showLightBox(lightBoxOptions)} + {lightBoxOptions?.media && this.renderLightBox(lightBoxOptions)}
@@ -489,6 +490,7 @@ export class SessionConversation extends React.Component { getMessages: this.getMessages, replyToMessage: this.replyToMessage, doneInitialScroll: this.state.doneInitialScroll, + onClickAttachment: this.onClickAttachment, }; } @@ -787,6 +789,20 @@ export class SessionConversation extends React.Component { } } + private onClickAttachment(attachment: any, message: any) { + const lightBoxOptions = { + media: [ + { + objectURL: attachment.url, + contentType: attachment.contentType, + attachment, + }, + ], + attachment, + }; + this.setState({ lightBoxOptions }); + } + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~ KEYBOARD NAVIGATION ~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -830,11 +846,20 @@ export class SessionConversation extends React.Component { // } } - private showLightBox(lightboxOptions: any) { - const { media, attachment } = lightboxOptions; - const selectedIndex = media.findIndex( - (mediaMessage: any) => mediaMessage.attachment.path === attachment.path - ); + private renderLightBox({ + media, + attachment, + }: { + media: Array; + attachment: any; + }) { + const selectedIndex = + media.length > 1 + ? media.findIndex( + (mediaMessage: any) => + mediaMessage.attachment.path === attachment.path + ) + : 0; return ( { ); } - // THIS DOES NOT DOWNLOAD ANYTHING! + // THIS DOES NOT DOWNLOAD ANYTHING! it just saves it where the user wants private downloadAttachment({ attachment, message, @@ -863,7 +888,7 @@ export class SessionConversation extends React.Component { attachment, document, getAbsolutePath: getAbsoluteAttachmentPath, - timestamp: message.received_at || Date.now(), + timestamp: message?.received_at || Date.now(), }); } } diff --git a/ts/components/session/conversation/SessionConversationMessagesList.tsx b/ts/components/session/conversation/SessionConversationMessagesList.tsx index fb4d5b6c1..60f0685f7 100644 --- a/ts/components/session/conversation/SessionConversationMessagesList.tsx +++ b/ts/components/session/conversation/SessionConversationMessagesList.tsx @@ -29,6 +29,7 @@ interface Props { interval: number ) => Promise<{ previousTopMessage: string }>; replyToMessage: (messageId: number) => Promise; + onClickAttachment: (attachment: any, message: any) => void; } export class SessionConversationMessagesList extends React.Component< @@ -135,6 +136,7 @@ export class SessionConversationMessagesList extends React.Component< // in a series of messages from the same user item = messageProps ? this.renderMessage( + message, messageProps, message.firstMessageOfSeries, multiSelectMode @@ -156,6 +158,7 @@ export class SessionConversationMessagesList extends React.Component< } public renderMessage( + message: any, messageProps: any, firstMessageOfSeries: boolean, multiSelectMode: boolean @@ -176,6 +179,11 @@ export class SessionConversationMessagesList extends React.Component< void this.props.replyToMessage(messageId); }; + messageProps.onClickAttachment = (attachment: any) => { + this.props.onClickAttachment(attachment, messageProps); + }; + // messageProps.onDownload = () + return ; }