From 273081d0a649bb0cdb28babad7e4d7b0a7ef98f9 Mon Sep 17 00:00:00 2001 From: roanster007 Date: Wed, 1 Nov 2023 13:26:14 +0530 Subject: [PATCH] lightbox_view: Fix media title update on change in title. Presently in a session when an image or video title is updated, the same change is not reflected in the lightbox view of them, until a new session is made. This is because the metadata of the media is stored in Map for the session with the preview_src as keys, and hence, when title is changed the preview_src being same, the title change is not reflected inside lightbox view. This is fixed by modifing the asset_map (cache map) keys from preview_src to an array of preview_src, and the media title. Hence, when title is modified now, the keys won't map to the existing value, and hence new metadata would be shown. A new function get_asset_map_key_for_media() introduced to get the corresponing metadata from this asset_map by passing in the prview_src and media elements. Fixes #21311 --- web/src/lightbox.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/web/src/lightbox.js b/web/src/lightbox.js index b015708094..ea6510dad2 100644 --- a/web/src/lightbox.js +++ b/web/src/lightbox.js @@ -314,6 +314,13 @@ function display_video(payload) { $(".media-actions .open").attr("href", payload.url); } +function get_asset_map_key_for_media($preview_src, $media) { + return asset_map.get([ + $preview_src, + $media.parent().attr("aria-label") || $media.parent().attr("href"), + ]); +} + export function build_open_media_function(on_close) { if (on_close === undefined) { on_close = function () { @@ -327,7 +334,7 @@ export function build_open_media_function(on_close) { // if the asset_map already contains the metadata required to display the // asset, just recall that metadata. let $preview_src = $media.attr("src"); - let payload = asset_map.get($preview_src); + let payload = get_asset_map_key_for_media($preview_src, $media); if (payload === undefined) { if ($preview_src.endsWith("&size=full")) { // while fetching an image for canvas, `src` attribute supplies @@ -341,7 +348,7 @@ export function build_open_media_function(on_close) { // `data-thumbnail-src` attribute that we add to the // canvas elements. $preview_src = $preview_src.slice(0, -"full".length) + "thumbnail"; - payload = asset_map.get($preview_src); + payload = get_asset_map_key_for_media($preview_src, $media); } if (payload === undefined) { payload = parse_media_data($media); @@ -430,7 +437,7 @@ export function parse_media_data(media) { if (asset_map.has(preview_src)) { // check if media's data is already present in asset_map. - return asset_map.get(preview_src); + return get_asset_map_key_for_media(preview_src, $media); } // if wrapped in the .youtube-video class, it will be length = 1, and therefore @@ -497,7 +504,7 @@ export function parse_media_data(media) { url: util.is_valid_url(url) ? url : "", }; - asset_map.set(preview_src, payload); + asset_map.set([preview_src, $parent.attr("aria-label") || $parent.attr("href")], payload); return payload; }