Pre-process media for LightboxGallery
This commit is contained in:
parent
110b58230b
commit
fccbf70d57
2 changed files with 12 additions and 10 deletions
|
@ -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,
|
||||
},
|
||||
|
|
|
@ -14,7 +14,6 @@ interface Item {
|
|||
|
||||
interface Props {
|
||||
close: () => void;
|
||||
getAbsoluteAttachmentPath: (relativePath: string) => string;
|
||||
messages: Array<Message>;
|
||||
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<Props, State> {
|
|||
}
|
||||
|
||||
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<Props, State> {
|
|||
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 (
|
||||
<Lightbox
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue