From fcf13c7467989a232bc3dcfafe24989b44a344fa Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Mon, 19 Oct 2020 15:23:35 +1100 Subject: [PATCH] relink lightbox from signal to our app --- js/views/conversation_view.js | 16 ------ ts/components/Lightbox.tsx | 17 +++--- ts/components/LightboxGallery.tsx | 5 +- .../conversation/SessionConversation.tsx | 53 +++++++++++++++++-- .../conversation/SessionRightPanel.tsx | 1 - 5 files changed, 58 insertions(+), 34 deletions(-) diff --git a/js/views/conversation_view.js b/js/views/conversation_view.js index cf1a186f2..5dc3405b4 100644 --- a/js/views/conversation_view.js +++ b/js/views/conversation_view.js @@ -1245,22 +1245,6 @@ }); }, - // THIS DOES NOT DOWNLOAD ANYTHING! - downloadAttachment({ attachment, message, isDangerous }) { - if (isDangerous) { - const toast = new Whisper.DangerousFileTypeToast(); - toast.$el.appendTo(this.$el); - toast.render(); - return; - } - Signal.Types.Attachment.save({ - attachment, - document, - getAbsolutePath: getAbsoluteAttachmentPath, - timestamp: message.get ? message.get('sent_at') : message.sent_at, - }); - }, - deleteSelectedMessages() { const ourPubkey = textsecure.storage.user.getNumber(); const selected = Array.from(this.model.selectedMessages); diff --git a/ts/components/Lightbox.tsx b/ts/components/Lightbox.tsx index d244a9bbc..5c7c6854f 100644 --- a/ts/components/Lightbox.tsx +++ b/ts/components/Lightbox.tsx @@ -8,8 +8,6 @@ import is from '@sindresorhus/is'; import * as GoogleChrome from '../util/GoogleChrome'; import * as MIME from '../types/MIME'; -import { LocalizerType } from '../types/Util'; - const Colors = { TEXT_SECONDARY: '#bbb', ICON_SECONDARY: '#ccc', @@ -26,7 +24,6 @@ const colorSVG = (url: string, color: string) => { interface Props { close: () => void; contentType: MIME.MIMEType | undefined; - i18n: LocalizerType; objectURL: string; caption?: string; onNext?: () => void; @@ -41,12 +38,15 @@ const styles = { container: { display: 'flex', flexDirection: 'column', - position: 'absolute', + position: 'fixed', + width: '100vw', + height: '100vh', left: 0, + zIndex: 5, right: 0, top: 0, bottom: 0, - backgroundColor: 'rgba(0, 0, 0, 0.9)', + backgroundColor: 'rgba(0, 0, 0, 0.8)', } as React.CSSProperties, mainContainer: { display: 'flex', @@ -218,7 +218,6 @@ export class Lightbox extends React.Component { onNext, onPrevious, onSave, - i18n, } = this.props; return ( @@ -232,7 +231,7 @@ export class Lightbox extends React.Component {
{!is.undefined(contentType) - ? this.renderObject({ objectURL, contentType, i18n }) + ? this.renderObject({ objectURL, contentType }) : null} {caption ?
{caption}
: null}
@@ -266,17 +265,15 @@ export class Lightbox extends React.Component { private readonly renderObject = ({ objectURL, contentType, - i18n, }: { objectURL: string; contentType: MIME.MIMEType; - i18n: LocalizerType; }) => { const isImageTypeSupported = GoogleChrome.isImageTypeSupported(contentType); if (isImageTypeSupported) { return ( {i18n('lightboxImageAlt')} void; - i18n: LocalizerType; media: Array; onSave?: (options: { attachment: AttachmentType; @@ -49,7 +47,7 @@ export class LightboxGallery extends React.Component { } public render() { - const { close, media, onSave, i18n } = this.props; + const { close, media, onSave } = this.props; const { selectedIndex } = this.state; const selectedMedia = media[selectedIndex]; @@ -75,7 +73,6 @@ export class LightboxGallery extends React.Component { objectURL={objectURL} caption={captionCallback} contentType={selectedMedia.contentType} - i18n={i18n} /> ); } diff --git a/ts/components/session/conversation/SessionConversation.tsx b/ts/components/session/conversation/SessionConversation.tsx index 5f4ccd794..2712c7fca 100644 --- a/ts/components/session/conversation/SessionConversation.tsx +++ b/ts/components/session/conversation/SessionConversation.tsx @@ -6,8 +6,6 @@ import classNames from 'classnames'; import { SessionCompositionBox } from './SessionCompositionBox'; -import { getTimestamp } from './SessionConversationManager'; - import { Constants } from '../../../session'; import { SessionKeyVerification } from '../SessionKeyVerification'; import _ from 'lodash'; @@ -18,6 +16,10 @@ import { SessionRightPanelWithDetails } from './SessionRightPanel'; import { SessionTheme } from '../../../state/ducks/SessionTheme'; import { DefaultTheme } from 'styled-components'; import { SessionConversationMessagesList } from './SessionConversationMessagesList'; +import { LightboxGallery } from '../../LightboxGallery'; +import { Message } from '../../conversation/media-gallery/types/Message'; + +import { AttachmentType } from '../../../types/Attachment'; interface State { conversationKey: string; @@ -54,6 +56,9 @@ interface State { // quoted message quotedMessageTimestamp?: number; quotedMessageProps?: any; + + // lightbox options + lightBoxOptions?: any; } interface Props { @@ -121,6 +126,8 @@ export class SessionConversation extends React.Component { // Keyboard navigation this.onKeyDown = this.onKeyDown.bind(this); + this.showLightBox = this.showLightBox.bind(this); + const conversationModel = window.ConversationController.getOrThrow( this.state.conversationKey ); @@ -161,6 +168,7 @@ export class SessionConversation extends React.Component { showRecordingView, showOptionsPane, quotedMessageProps, + lightBoxOptions, } = this.state; const selectionMode = !!this.state.selectedMessages.length; @@ -216,6 +224,8 @@ export class SessionConversation extends React.Component { {showMessageDetails && <> }
+ {lightBoxOptions?.media && this.showLightBox(lightBoxOptions)} +
@@ -541,7 +551,7 @@ export class SessionConversation extends React.Component { }, onShowLightBox: (lightBoxOptions = {}) => { - conversation.showChannelLightbox(lightBoxOptions); + this.setState({ lightBoxOptions }); }, }; } @@ -819,4 +829,41 @@ export class SessionConversation extends React.Component { // default: // } } + + private showLightBox(lightboxOptions: any) { + const { media, attachment } = lightboxOptions; + const selectedIndex = media.findIndex( + (mediaMessage: any) => mediaMessage.attachment.path === attachment.path + ); + return ( + { + this.setState({ lightBoxOptions: undefined }); + }} + selectedIndex={selectedIndex} + onSave={this.downloadAttachment} + /> + ); + } + + // THIS DOES NOT DOWNLOAD ANYTHING! + private downloadAttachment({ + attachment, + message, + index, + }: { + attachment: AttachmentType; + message: Message; + index: number; + }) { + const { getAbsoluteAttachmentPath } = window.Signal.Migrations; + + window.Signal.Types.Attachment.save({ + attachment, + document, + getAbsolutePath: getAbsoluteAttachmentPath, + timestamp: message.received_at || Date.now(), + }); + } } diff --git a/ts/components/session/conversation/SessionRightPanel.tsx b/ts/components/session/conversation/SessionRightPanel.tsx index f3399019e..8ece88f54 100644 --- a/ts/components/session/conversation/SessionRightPanel.tsx +++ b/ts/components/session/conversation/SessionRightPanel.tsx @@ -132,7 +132,6 @@ class SessionRightPanel extends React.Component { } } - // tslint:disable-next-line: underscore-consistent-invocation const media = _.flatten( rawMedia.map((message: { attachments: any }) => { const { attachments } = message;