Skip to content

Commit

Permalink
showLightboxForMedia: Properly handle message events
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Nonnenberg <scott@signal.org>
  • Loading branch information
automated-signal and scottnonnenberg-signal committed Oct 25, 2022
1 parent 5e09bc8 commit ff9bf65
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion ts/views/conversation_view.tsx
Expand Up @@ -1738,8 +1738,21 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
mediaItem.attachment.path === selectedMediaItem.attachment.path
);

const mediaMessage = selectedMediaItem.message;
const message = window.MessageController.getById(mediaMessage.id);
if (!message) {
throw new Error(
`showLightboxForMedia: Message ${mediaMessage.id} missing!`
);
}

const close = () => {
closeLightbox();
this.stopListening(message, 'expired', closeLightbox);
};

showLightbox({
close: closeLightbox,
close,
i18n: window.i18n,
getConversation: getConversationSelector(window.reduxStore.getState()),
media,
Expand All @@ -1749,6 +1762,8 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
onSave,
selectedIndex: selectedIndex >= 0 ? selectedIndex : 0,
});

this.listenTo(message, 'expired', close);
}

showLightbox({
Expand Down

0 comments on commit ff9bf65

Please sign in to comment.