From 708d07a8856452c74186bffcc1e5082d1da7dcaa Mon Sep 17 00:00:00 2001 From: Karl Stolley Date: Fri, 26 Jul 2024 10:13:40 -0500 Subject: [PATCH] lightbox: Address edge case where media may be unavailable. --- web/src/lightbox.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/web/src/lightbox.ts b/web/src/lightbox.ts index 4f57227fb4..05d2e88c8e 100644 --- a/web/src/lightbox.ts +++ b/web/src/lightbox.ts @@ -652,6 +652,17 @@ export function initialize(): void { ); } + // If $original_media_element comes back empty, that means that + // something in the message list has changed (e.g., a moved or + // deleted message, or the deletion of a media element that was + // available when the lightbox opened). In that event, we continue + // to display whatever media is up in the lightbox, and remove + // the thumbnail from the media list. + if ($original_media_element.length === 0) { + $(this).remove(); + return; + } + open_image($original_media_element); if (!$(".image-list .image.selected").hasClass("lightbox_video") || !is_video) {