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);
|
.loadWithObjectURL(Signal.Migrations.loadMessage);
|
||||||
const media = await loadMessages(rawMedia);
|
const media = await loadMessages(rawMedia);
|
||||||
|
|
||||||
|
const { getAbsoluteAttachmentPath } = Signal.Migrations;
|
||||||
const saveAttachment = async ({ message } = {}) => {
|
const saveAttachment = async ({ message } = {}) => {
|
||||||
const attachment = message.attachments[0];
|
const attachment = message.attachments[0];
|
||||||
const timestamp = message.received_at;
|
const timestamp = message.received_at;
|
||||||
Signal.Types.Attachment.save({
|
Signal.Types.Attachment.save({
|
||||||
attachment,
|
attachment,
|
||||||
document,
|
document,
|
||||||
getAbsolutePath: Signal.Migrations.getAbsoluteAttachmentPath,
|
getAbsolutePath: getAbsoluteAttachmentPath,
|
||||||
timestamp,
|
timestamp,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -622,14 +623,18 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'media': {
|
case 'media': {
|
||||||
|
const mediaWithObjectURL = media.map(mediaMessage =>
|
||||||
|
Object.assign(
|
||||||
|
{},
|
||||||
|
mediaMessage,
|
||||||
|
{ objectURL: getAbsoluteAttachmentPath(mediaMessage.attachments[0].path) }
|
||||||
|
));
|
||||||
const selectedIndex = media.findIndex(mediaMessage =>
|
const selectedIndex = media.findIndex(mediaMessage =>
|
||||||
mediaMessage.id === message.id);
|
mediaMessage.id === message.id);
|
||||||
const { getAbsoluteAttachmentPath } = Signal.Migrations;
|
|
||||||
this.lightboxGalleryView = new Whisper.ReactWrapperView({
|
this.lightboxGalleryView = new Whisper.ReactWrapperView({
|
||||||
Component: Signal.Components.LightboxGallery,
|
Component: Signal.Components.LightboxGallery,
|
||||||
props: {
|
props: {
|
||||||
getAbsoluteAttachmentPath,
|
messages: mediaWithObjectURL,
|
||||||
messages: media,
|
|
||||||
onSave: () => saveAttachment({ message }),
|
onSave: () => saveAttachment({ message }),
|
||||||
selectedIndex,
|
selectedIndex,
|
||||||
},
|
},
|
||||||
|
|
|
@ -14,7 +14,6 @@ interface Item {
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
close: () => void;
|
close: () => void;
|
||||||
getAbsoluteAttachmentPath: (relativePath: string) => string;
|
|
||||||
messages: Array<Message>;
|
messages: Array<Message>;
|
||||||
onSave?: ({ message }: { message: Message }) => void;
|
onSave?: ({ message }: { message: Message }) => void;
|
||||||
selectedIndex: number;
|
selectedIndex: number;
|
||||||
|
@ -25,7 +24,7 @@ interface State {
|
||||||
}
|
}
|
||||||
|
|
||||||
const messageToItem = (message: Message): Item => ({
|
const messageToItem = (message: Message): Item => ({
|
||||||
objectURL: message.attachments[0].path,
|
objectURL: message.objectURL,
|
||||||
contentType: message.attachments[0].contentType,
|
contentType: message.attachments[0].contentType,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -43,7 +42,7 @@ export class LightboxGallery extends React.Component<Props, State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
const { close, getAbsoluteAttachmentPath, messages, onSave } = this.props;
|
const { close, messages, onSave } = this.props;
|
||||||
const { selectedIndex } = this.state;
|
const { selectedIndex } = this.state;
|
||||||
|
|
||||||
const selectedMessage: Message = messages[selectedIndex];
|
const selectedMessage: Message = messages[selectedIndex];
|
||||||
|
@ -56,9 +55,7 @@ export class LightboxGallery extends React.Component<Props, State> {
|
||||||
const lastIndex = messages.length - 1;
|
const lastIndex = messages.length - 1;
|
||||||
const onNext = selectedIndex < lastIndex ? this.handleNext : undefined;
|
const onNext = selectedIndex < lastIndex ? this.handleNext : undefined;
|
||||||
|
|
||||||
const objectURL = selectedItem.objectURL
|
const objectURL = selectedItem.objectURL || 'images/alert-outline.svg';
|
||||||
? getAbsoluteAttachmentPath(selectedItem.objectURL)
|
|
||||||
: 'images/video.svg';
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Lightbox
|
<Lightbox
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue