relink lightbox from signal to our app

This commit is contained in:
Audric Ackermann 2020-10-19 15:23:35 +11:00
parent a76322c676
commit fcf13c7467
No known key found for this signature in database
GPG key ID: 999F434D76324AD4
5 changed files with 58 additions and 34 deletions

View file

@ -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() { deleteSelectedMessages() {
const ourPubkey = textsecure.storage.user.getNumber(); const ourPubkey = textsecure.storage.user.getNumber();
const selected = Array.from(this.model.selectedMessages); const selected = Array.from(this.model.selectedMessages);

View file

@ -8,8 +8,6 @@ import is from '@sindresorhus/is';
import * as GoogleChrome from '../util/GoogleChrome'; import * as GoogleChrome from '../util/GoogleChrome';
import * as MIME from '../types/MIME'; import * as MIME from '../types/MIME';
import { LocalizerType } from '../types/Util';
const Colors = { const Colors = {
TEXT_SECONDARY: '#bbb', TEXT_SECONDARY: '#bbb',
ICON_SECONDARY: '#ccc', ICON_SECONDARY: '#ccc',
@ -26,7 +24,6 @@ const colorSVG = (url: string, color: string) => {
interface Props { interface Props {
close: () => void; close: () => void;
contentType: MIME.MIMEType | undefined; contentType: MIME.MIMEType | undefined;
i18n: LocalizerType;
objectURL: string; objectURL: string;
caption?: string; caption?: string;
onNext?: () => void; onNext?: () => void;
@ -41,12 +38,15 @@ const styles = {
container: { container: {
display: 'flex', display: 'flex',
flexDirection: 'column', flexDirection: 'column',
position: 'absolute', position: 'fixed',
width: '100vw',
height: '100vh',
left: 0, left: 0,
zIndex: 5,
right: 0, right: 0,
top: 0, top: 0,
bottom: 0, bottom: 0,
backgroundColor: 'rgba(0, 0, 0, 0.9)', backgroundColor: 'rgba(0, 0, 0, 0.8)',
} as React.CSSProperties, } as React.CSSProperties,
mainContainer: { mainContainer: {
display: 'flex', display: 'flex',
@ -218,7 +218,6 @@ export class Lightbox extends React.Component<Props> {
onNext, onNext,
onPrevious, onPrevious,
onSave, onSave,
i18n,
} = this.props; } = this.props;
return ( return (
@ -232,7 +231,7 @@ export class Lightbox extends React.Component<Props> {
<div style={styles.controlsOffsetPlaceholder} /> <div style={styles.controlsOffsetPlaceholder} />
<div style={styles.objectContainer}> <div style={styles.objectContainer}>
{!is.undefined(contentType) {!is.undefined(contentType)
? this.renderObject({ objectURL, contentType, i18n }) ? this.renderObject({ objectURL, contentType })
: null} : null}
{caption ? <div style={styles.caption}>{caption}</div> : null} {caption ? <div style={styles.caption}>{caption}</div> : null}
</div> </div>
@ -266,17 +265,15 @@ export class Lightbox extends React.Component<Props> {
private readonly renderObject = ({ private readonly renderObject = ({
objectURL, objectURL,
contentType, contentType,
i18n,
}: { }: {
objectURL: string; objectURL: string;
contentType: MIME.MIMEType; contentType: MIME.MIMEType;
i18n: LocalizerType;
}) => { }) => {
const isImageTypeSupported = GoogleChrome.isImageTypeSupported(contentType); const isImageTypeSupported = GoogleChrome.isImageTypeSupported(contentType);
if (isImageTypeSupported) { if (isImageTypeSupported) {
return ( return (
<img <img
alt={i18n('lightboxImageAlt')} alt={window.i18n('lightboxImageAlt')}
style={styles.object} style={styles.object}
src={objectURL} src={objectURL}
onClick={this.onObjectClick} onClick={this.onObjectClick}

View file

@ -8,7 +8,6 @@ import { Lightbox } from './Lightbox';
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';
import { LocalizerType } from '../types/Util';
export interface MediaItemType { export interface MediaItemType {
objectURL?: string; objectURL?: string;
@ -21,7 +20,6 @@ export interface MediaItemType {
interface Props { interface Props {
close: () => void; close: () => void;
i18n: LocalizerType;
media: Array<MediaItemType>; media: Array<MediaItemType>;
onSave?: (options: { onSave?: (options: {
attachment: AttachmentType; attachment: AttachmentType;
@ -49,7 +47,7 @@ export class LightboxGallery extends React.Component<Props, State> {
} }
public render() { public render() {
const { close, media, onSave, i18n } = this.props; const { close, media, onSave } = this.props;
const { selectedIndex } = this.state; const { selectedIndex } = this.state;
const selectedMedia = media[selectedIndex]; const selectedMedia = media[selectedIndex];
@ -75,7 +73,6 @@ export class LightboxGallery extends React.Component<Props, State> {
objectURL={objectURL} objectURL={objectURL}
caption={captionCallback} caption={captionCallback}
contentType={selectedMedia.contentType} contentType={selectedMedia.contentType}
i18n={i18n}
/> />
); );
} }

View file

@ -6,8 +6,6 @@ import classNames from 'classnames';
import { SessionCompositionBox } from './SessionCompositionBox'; import { SessionCompositionBox } from './SessionCompositionBox';
import { getTimestamp } from './SessionConversationManager';
import { Constants } from '../../../session'; import { Constants } from '../../../session';
import { SessionKeyVerification } from '../SessionKeyVerification'; import { SessionKeyVerification } from '../SessionKeyVerification';
import _ from 'lodash'; import _ from 'lodash';
@ -18,6 +16,10 @@ 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 { Message } from '../../conversation/media-gallery/types/Message';
import { AttachmentType } from '../../../types/Attachment';
interface State { interface State {
conversationKey: string; conversationKey: string;
@ -54,6 +56,9 @@ interface State {
// quoted message // quoted message
quotedMessageTimestamp?: number; quotedMessageTimestamp?: number;
quotedMessageProps?: any; quotedMessageProps?: any;
// lightbox options
lightBoxOptions?: any;
} }
interface Props { interface Props {
@ -121,6 +126,8 @@ export class SessionConversation extends React.Component<Props, State> {
// Keyboard navigation // Keyboard navigation
this.onKeyDown = this.onKeyDown.bind(this); this.onKeyDown = this.onKeyDown.bind(this);
this.showLightBox = this.showLightBox.bind(this);
const conversationModel = window.ConversationController.getOrThrow( const conversationModel = window.ConversationController.getOrThrow(
this.state.conversationKey this.state.conversationKey
); );
@ -161,6 +168,7 @@ export class SessionConversation extends React.Component<Props, State> {
showRecordingView, showRecordingView,
showOptionsPane, showOptionsPane,
quotedMessageProps, quotedMessageProps,
lightBoxOptions,
} = this.state; } = this.state;
const selectionMode = !!this.state.selectedMessages.length; const selectionMode = !!this.state.selectedMessages.length;
@ -216,6 +224,8 @@ export class SessionConversation extends React.Component<Props, State> {
{showMessageDetails && <>&nbsp</>} {showMessageDetails && <>&nbsp</>}
</div> </div>
{lightBoxOptions?.media && this.showLightBox(lightBoxOptions)}
<div className="conversation-messages"> <div className="conversation-messages">
<SessionConversationMessagesList {...messagesListProps} /> <SessionConversationMessagesList {...messagesListProps} />
@ -541,7 +551,7 @@ export class SessionConversation extends React.Component<Props, State> {
}, },
onShowLightBox: (lightBoxOptions = {}) => { onShowLightBox: (lightBoxOptions = {}) => {
conversation.showChannelLightbox(lightBoxOptions); this.setState({ lightBoxOptions });
}, },
}; };
} }
@ -819,4 +829,41 @@ export class SessionConversation extends React.Component<Props, State> {
// default: // default:
// } // }
} }
private showLightBox(lightboxOptions: any) {
const { media, attachment } = lightboxOptions;
const selectedIndex = media.findIndex(
(mediaMessage: any) => mediaMessage.attachment.path === attachment.path
);
return (
<LightboxGallery
media={media}
close={() => {
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(),
});
}
} }

View file

@ -132,7 +132,6 @@ class SessionRightPanel extends React.Component<Props, State> {
} }
} }
// tslint:disable-next-line: underscore-consistent-invocation
const media = _.flatten( const media = _.flatten(
rawMedia.map((message: { attachments: any }) => { rawMedia.map((message: { attachments: any }) => {
const { attachments } = message; const { attachments } = message;