showLightboxForMedia: Properly handle message events

This commit is contained in:
Scott Nonnenberg 2022-10-24 17:56:51 -07:00 committed by GitHub
parent 0134990275
commit 4f3280b415
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1738,8 +1738,21 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
mediaItem.attachment.path === selectedMediaItem.attachment.path 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({ showLightbox({
close: closeLightbox, close,
i18n: window.i18n, i18n: window.i18n,
getConversation: getConversationSelector(window.reduxStore.getState()), getConversation: getConversationSelector(window.reduxStore.getState()),
media, media,
@ -1749,6 +1762,8 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
onSave, onSave,
selectedIndex: selectedIndex >= 0 ? selectedIndex : 0, selectedIndex: selectedIndex >= 0 ? selectedIndex : 0,
}); });
this.listenTo(message, 'expired', close);
} }
showLightbox({ showLightbox({