1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Fixed: itemContextMenu opened from bottom media control bar applying operations to the wrong item when items have no image metadata. Can manifest as the wrong song being added to a playlist, deleted, or receiving user supplied metadata, etc.

This commit is contained in:
callum 2022-08-27 13:50:58 +01:00
parent 89ec4f4e8a
commit 072e20b585

View file

@ -24,6 +24,7 @@ import { appRouter } from '../appRouter';
let currentTimeElement; let currentTimeElement;
let nowPlayingImageElement; let nowPlayingImageElement;
let nowPlayingImageUrl;
let nowPlayingTextElement; let nowPlayingTextElement;
let nowPlayingUserData; let nowPlayingUserData;
let muteButton; let muteButton;
@ -488,7 +489,6 @@ import { appRouter } from '../appRouter';
return null; return null;
} }
let currentImgUrl;
function updateNowPlayingInfo(state) { function updateNowPlayingInfo(state) {
const nowPlayingItem = state.NowPlayingItem; const nowPlayingItem = state.NowPlayingItem;
@ -524,54 +524,46 @@ import { appRouter } from '../appRouter';
height: imgHeight height: imgHeight
})) : null; })) : null;
let isRefreshing = false; if (url && url !== nowPlayingImageUrl) {
nowPlayingImageUrl = url;
if (url !== currentImgUrl) { imageLoader.lazyImage(nowPlayingImageElement, url);
currentImgUrl = url; nowPlayingImageElement.style.display = null;
isRefreshing = true; nowPlayingTextElement.style.marginLeft = null;
} else {
if (url) { nowPlayingImageElement.style.backgroundImage = '';
imageLoader.lazyImage(nowPlayingImageElement, url); nowPlayingImageElement.style.display = 'none';
nowPlayingImageElement.style.display = null; nowPlayingTextElement.style.marginLeft = '1em';
nowPlayingTextElement.style.marginLeft = null;
} else {
nowPlayingImageElement.style.backgroundImage = '';
nowPlayingImageElement.style.display = 'none';
nowPlayingTextElement.style.marginLeft = '1em';
}
} }
if (nowPlayingItem.Id) { if (nowPlayingItem.Id) {
if (isRefreshing) { const apiClient = ServerConnections.getApiClient(nowPlayingItem.ServerId);
const apiClient = ServerConnections.getApiClient(nowPlayingItem.ServerId); apiClient.getItem(apiClient.getCurrentUserId(), nowPlayingItem.Id).then(function (item) {
apiClient.getItem(apiClient.getCurrentUserId(), nowPlayingItem.Id).then(function (item) { const userData = item.UserData || {};
const userData = item.UserData || {}; const likes = userData.Likes == null ? '' : userData.Likes;
const likes = userData.Likes == null ? '' : userData.Likes; if (!layoutManager.mobile) {
if (!layoutManager.mobile) { let contextButton = nowPlayingBarElement.querySelector('.btnToggleContextMenu');
let contextButton = nowPlayingBarElement.querySelector('.btnToggleContextMenu'); // We remove the previous event listener by replacing the item in each update event
// We remove the previous event listener by replacing the item in each update event const contextButtonClone = contextButton.cloneNode(true);
const contextButtonClone = contextButton.cloneNode(true); contextButton.parentNode.replaceChild(contextButtonClone, contextButton);
contextButton.parentNode.replaceChild(contextButtonClone, contextButton); contextButton = nowPlayingBarElement.querySelector('.btnToggleContextMenu');
contextButton = nowPlayingBarElement.querySelector('.btnToggleContextMenu'); const options = {
const options = { play: false,
play: false, queue: false,
queue: false, stopPlayback: true,
stopPlayback: true, clearQueue: true,
clearQueue: true, positionTo: contextButton
positionTo: contextButton };
}; apiClient.getCurrentUser().then(function (user) {
apiClient.getCurrentUser().then(function (user) { contextButton.addEventListener('click', function () {
contextButton.addEventListener('click', function () { itemContextMenu.show(Object.assign({
itemContextMenu.show(Object.assign({ item: item,
item: item, user: user
user: user }, options));
}, options));
});
}); });
} });
nowPlayingUserData.innerHTML = '<button is="emby-ratingbutton" type="button" class="listItemButton mediaButton paper-icon-button-light" data-id="' + item.Id + '" data-serverid="' + item.ServerId + '" data-itemtype="' + item.Type + '" data-likes="' + likes + '" data-isfavorite="' + (userData.IsFavorite) + '"><span class="material-icons favorite" aria-hidden="true"></span></button>'; }
}); nowPlayingUserData.innerHTML = '<button is="emby-ratingbutton" type="button" class="listItemButton mediaButton paper-icon-button-light" data-id="' + item.Id + '" data-serverid="' + item.ServerId + '" data-itemtype="' + item.Type + '" data-likes="' + likes + '" data-isfavorite="' + (userData.IsFavorite) + '"><span class="material-icons favorite" aria-hidden="true"></span></button>';
} });
} else { } else {
nowPlayingUserData.innerHTML = ''; nowPlayingUserData.innerHTML = '';
} }