From fccbf70d570b25ebd7db5c73e92f3a8dc424b57d Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Mon, 30 Apr 2018 11:59:26 -0400 Subject: [PATCH] Pre-process media for `LightboxGallery` --- js/views/conversation_view.js | 13 +++++++++---- ts/components/LightboxGallery.tsx | 9 +++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/js/views/conversation_view.js b/js/views/conversation_view.js index 704ba03f5..44bbf8747 100644 --- a/js/views/conversation_view.js +++ b/js/views/conversation_view.js @@ -603,13 +603,14 @@ .loadWithObjectURL(Signal.Migrations.loadMessage); const media = await loadMessages(rawMedia); + const { getAbsoluteAttachmentPath } = Signal.Migrations; const saveAttachment = async ({ message } = {}) => { const attachment = message.attachments[0]; const timestamp = message.received_at; Signal.Types.Attachment.save({ attachment, document, - getAbsolutePath: Signal.Migrations.getAbsoluteAttachmentPath, + getAbsolutePath: getAbsoluteAttachmentPath, timestamp, }); }; @@ -622,14 +623,18 @@ } case 'media': { + const mediaWithObjectURL = media.map(mediaMessage => + Object.assign( + {}, + mediaMessage, + { objectURL: getAbsoluteAttachmentPath(mediaMessage.attachments[0].path) } + )); const selectedIndex = media.findIndex(mediaMessage => mediaMessage.id === message.id); - const { getAbsoluteAttachmentPath } = Signal.Migrations; this.lightboxGalleryView = new Whisper.ReactWrapperView({ Component: Signal.Components.LightboxGallery, props: { - getAbsoluteAttachmentPath, - messages: media, + messages: mediaWithObjectURL, onSave: () => saveAttachment({ message }), selectedIndex, }, diff --git a/ts/components/LightboxGallery.tsx b/ts/components/LightboxGallery.tsx index ae6a822a2..39b7b4eb0 100644 --- a/ts/components/LightboxGallery.tsx +++ b/ts/components/LightboxGallery.tsx @@ -14,7 +14,6 @@ interface Item { interface Props { close: () => void; - getAbsoluteAttachmentPath: (relativePath: string) => string; messages: Array; onSave?: ({ message }: { message: Message }) => void; selectedIndex: number; @@ -25,7 +24,7 @@ interface State { } const messageToItem = (message: Message): Item => ({ - objectURL: message.attachments[0].path, + objectURL: message.objectURL, contentType: message.attachments[0].contentType, }); @@ -43,7 +42,7 @@ export class LightboxGallery extends React.Component { } public render() { - const { close, getAbsoluteAttachmentPath, messages, onSave } = this.props; + const { close, messages, onSave } = this.props; const { selectedIndex } = this.state; const selectedMessage: Message = messages[selectedIndex]; @@ -56,9 +55,7 @@ export class LightboxGallery extends React.Component { const lastIndex = messages.length - 1; const onNext = selectedIndex < lastIndex ? this.handleNext : undefined; - const objectURL = selectedItem.objectURL - ? getAbsoluteAttachmentPath(selectedItem.objectURL) - : 'images/video.svg'; + const objectURL = selectedItem.objectURL || 'images/alert-outline.svg'; return (