fix lightbox for single attachment display and download

pull/1387/head
Audric Ackermann 5 years ago
parent fcf13c7467
commit 2a155a0f43
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -620,11 +620,6 @@
onShowDetail: () => this.trigger('show-message-detail', this), onShowDetail: () => this.trigger('show-message-detail', this),
onDelete: () => this.trigger('delete', this), onDelete: () => this.trigger('delete', this),
onClickLinkPreview: url => this.trigger('navigate-to', url), onClickLinkPreview: url => this.trigger('navigate-to', url),
onClickAttachment: attachment =>
this.trigger('show-lightbox', {
attachment,
message: this,
}),
onDownload: isDangerous => onDownload: isDangerous =>
this.trigger('download', { this.trigger('download', {

@ -16,7 +16,7 @@ import { SessionRightPanelWithDetails } from './SessionRightPanel';
import { SessionTheme } from '../../../state/ducks/SessionTheme'; import { SessionTheme } from '../../../state/ducks/SessionTheme';
import { DefaultTheme } from 'styled-components'; import { DefaultTheme } from 'styled-components';
import { SessionConversationMessagesList } from './SessionConversationMessagesList'; import { SessionConversationMessagesList } from './SessionConversationMessagesList';
import { LightboxGallery } from '../../LightboxGallery'; import { LightboxGallery, MediaItemType } from '../../LightboxGallery';
import { Message } from '../../conversation/media-gallery/types/Message'; import { Message } from '../../conversation/media-gallery/types/Message';
import { AttachmentType } from '../../../types/Attachment'; import { AttachmentType } from '../../../types/Attachment';
@ -121,12 +121,13 @@ export class SessionConversation extends React.Component<Props, State> {
this.deleteSelectedMessages = this.deleteSelectedMessages.bind(this); this.deleteSelectedMessages = this.deleteSelectedMessages.bind(this);
this.replyToMessage = this.replyToMessage.bind(this); this.replyToMessage = this.replyToMessage.bind(this);
this.onClickAttachment = this.onClickAttachment.bind(this);
this.getMessages = this.getMessages.bind(this); this.getMessages = this.getMessages.bind(this);
// Keyboard navigation // Keyboard navigation
this.onKeyDown = this.onKeyDown.bind(this); this.onKeyDown = this.onKeyDown.bind(this);
this.showLightBox = this.showLightBox.bind(this); this.renderLightBox = this.renderLightBox.bind(this);
const conversationModel = window.ConversationController.getOrThrow( const conversationModel = window.ConversationController.getOrThrow(
this.state.conversationKey this.state.conversationKey
@ -224,7 +225,7 @@ export class SessionConversation extends React.Component<Props, State> {
{showMessageDetails && <>&nbsp</>} {showMessageDetails && <>&nbsp</>}
</div> </div>
{lightBoxOptions?.media && this.showLightBox(lightBoxOptions)} {lightBoxOptions?.media && this.renderLightBox(lightBoxOptions)}
<div className="conversation-messages"> <div className="conversation-messages">
<SessionConversationMessagesList {...messagesListProps} /> <SessionConversationMessagesList {...messagesListProps} />
@ -489,6 +490,7 @@ export class SessionConversation extends React.Component<Props, State> {
getMessages: this.getMessages, getMessages: this.getMessages,
replyToMessage: this.replyToMessage, replyToMessage: this.replyToMessage,
doneInitialScroll: this.state.doneInitialScroll, doneInitialScroll: this.state.doneInitialScroll,
onClickAttachment: this.onClickAttachment,
}; };
} }
@ -787,6 +789,20 @@ export class SessionConversation extends React.Component<Props, State> {
} }
} }
private onClickAttachment(attachment: any, message: any) {
const lightBoxOptions = {
media: [
{
objectURL: attachment.url,
contentType: attachment.contentType,
attachment,
},
],
attachment,
};
this.setState({ lightBoxOptions });
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~ KEYBOARD NAVIGATION ~~~~~~~~~~~~ // ~~~~~~~~~~~ KEYBOARD NAVIGATION ~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -830,11 +846,20 @@ export class SessionConversation extends React.Component<Props, State> {
// } // }
} }
private showLightBox(lightboxOptions: any) { private renderLightBox({
const { media, attachment } = lightboxOptions; media,
const selectedIndex = media.findIndex( attachment,
(mediaMessage: any) => mediaMessage.attachment.path === attachment.path }: {
); media: Array<MediaItemType>;
attachment: any;
}) {
const selectedIndex =
media.length > 1
? media.findIndex(
(mediaMessage: any) =>
mediaMessage.attachment.path === attachment.path
)
: 0;
return ( return (
<LightboxGallery <LightboxGallery
media={media} media={media}
@ -847,7 +872,7 @@ export class SessionConversation extends React.Component<Props, State> {
); );
} }
// THIS DOES NOT DOWNLOAD ANYTHING! // THIS DOES NOT DOWNLOAD ANYTHING! it just saves it where the user wants
private downloadAttachment({ private downloadAttachment({
attachment, attachment,
message, message,
@ -863,7 +888,7 @@ export class SessionConversation extends React.Component<Props, State> {
attachment, attachment,
document, document,
getAbsolutePath: getAbsoluteAttachmentPath, getAbsolutePath: getAbsoluteAttachmentPath,
timestamp: message.received_at || Date.now(), timestamp: message?.received_at || Date.now(),
}); });
} }
} }

@ -29,6 +29,7 @@ interface Props {
interval: number interval: number
) => Promise<{ previousTopMessage: string }>; ) => Promise<{ previousTopMessage: string }>;
replyToMessage: (messageId: number) => Promise<void>; replyToMessage: (messageId: number) => Promise<void>;
onClickAttachment: (attachment: any, message: any) => void;
} }
export class SessionConversationMessagesList extends React.Component< 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 // in a series of messages from the same user
item = messageProps item = messageProps
? this.renderMessage( ? this.renderMessage(
message,
messageProps, messageProps,
message.firstMessageOfSeries, message.firstMessageOfSeries,
multiSelectMode multiSelectMode
@ -156,6 +158,7 @@ export class SessionConversationMessagesList extends React.Component<
} }
public renderMessage( public renderMessage(
message: any,
messageProps: any, messageProps: any,
firstMessageOfSeries: boolean, firstMessageOfSeries: boolean,
multiSelectMode: boolean multiSelectMode: boolean
@ -176,6 +179,11 @@ export class SessionConversationMessagesList extends React.Component<
void this.props.replyToMessage(messageId); void this.props.replyToMessage(messageId);
}; };
messageProps.onClickAttachment = (attachment: any) => {
this.props.onClickAttachment(attachment, messageProps);
};
// messageProps.onDownload = ()
return <Message {...messageProps} />; return <Message {...messageProps} />;
} }

Loading…
Cancel
Save