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
This commit is contained in:
roanster007 2023-11-01 13:26:14 +05:30 committed by Tim Abbott
parent e8fe6f873e
commit 273081d0a6
1 changed files with 11 additions and 4 deletions

View File

@ -314,6 +314,13 @@ function display_video(payload) {
$(".media-actions .open").attr("href", payload.url); $(".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) { export function build_open_media_function(on_close) {
if (on_close === undefined) { if (on_close === undefined) {
on_close = function () { 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 // if the asset_map already contains the metadata required to display the
// asset, just recall that metadata. // asset, just recall that metadata.
let $preview_src = $media.attr("src"); 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 (payload === undefined) {
if ($preview_src.endsWith("&size=full")) { if ($preview_src.endsWith("&size=full")) {
// while fetching an image for canvas, `src` attribute supplies // 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 // `data-thumbnail-src` attribute that we add to the
// canvas elements. // canvas elements.
$preview_src = $preview_src.slice(0, -"full".length) + "thumbnail"; $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) { if (payload === undefined) {
payload = parse_media_data($media); payload = parse_media_data($media);
@ -430,7 +437,7 @@ export function parse_media_data(media) {
if (asset_map.has(preview_src)) { if (asset_map.has(preview_src)) {
// check if media's data is already present in asset_map. // 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 // 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 : "", 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; return payload;
} }