mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-14 11:51:47 +00:00
fix(music-together): fix user profile in queue
This commit is contained in:
@ -125,10 +125,12 @@ export default createPlugin<
|
|||||||
if (this.connection?.mode === 'host') {
|
if (this.connection?.mode === 'host') {
|
||||||
const videoList: VideoData[] =
|
const videoList: VideoData[] =
|
||||||
this.queue?.flatItems.map(
|
this.queue?.flatItems.map(
|
||||||
(it) =>
|
(it, index) =>
|
||||||
({
|
({
|
||||||
videoId: it!.videoId,
|
videoId: it!.videoId,
|
||||||
ownerId: this.connection!.id,
|
ownerId:
|
||||||
|
this.queue?.videoList[index]?.ownerId ??
|
||||||
|
this.connection!.id,
|
||||||
}) satisfies VideoData,
|
}) satisfies VideoData,
|
||||||
) ?? [];
|
) ?? [];
|
||||||
|
|
||||||
@ -212,6 +214,7 @@ export default createPlugin<
|
|||||||
event: ConnectionEventUnion,
|
event: ConnectionEventUnion,
|
||||||
conn?: DataConnection | null,
|
conn?: DataConnection | null,
|
||||||
) => {
|
) => {
|
||||||
|
console.log('event', event, this.queue?.videoList);
|
||||||
this.ignoreChange = true;
|
this.ignoreChange = true;
|
||||||
|
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
|
|||||||
@ -3,8 +3,9 @@ import { mapQueueItem } from './utils';
|
|||||||
|
|
||||||
import { t } from '@/i18n';
|
import { t } from '@/i18n';
|
||||||
|
|
||||||
|
import { getDefaultProfile, type Profile, type VideoData } from '../types';
|
||||||
|
|
||||||
import type { ConnectionEventUnion } from '@/plugins/music-together/connection';
|
import type { ConnectionEventUnion } from '@/plugins/music-together/connection';
|
||||||
import type { Profile, VideoData } from '../types';
|
|
||||||
import type { QueueItem } from '@/types/datahost-get-state';
|
import type { QueueItem } from '@/types/datahost-get-state';
|
||||||
import type { QueueElement, Store } from '@/types/queue';
|
import type { QueueElement, Store } from '@/types/queue';
|
||||||
|
|
||||||
@ -177,37 +178,46 @@ export class Queue {
|
|||||||
if (!items) return false;
|
if (!items) return false;
|
||||||
|
|
||||||
this.internalDispatch = true;
|
this.internalDispatch = true;
|
||||||
this._videoList = mapQueueItem(
|
this._videoList = this._videoList.map(
|
||||||
(it) =>
|
(it) =>
|
||||||
({
|
({
|
||||||
videoId: it!.videoId,
|
videoId: it.videoId,
|
||||||
ownerId: this.owner!.id,
|
ownerId: it.ownerId ?? this.owner!.id,
|
||||||
}) satisfies VideoData,
|
}) satisfies VideoData,
|
||||||
this.queue.queue.getItems(),
|
|
||||||
);
|
|
||||||
this._videoList.splice(
|
|
||||||
index ?? this._videoList.length,
|
|
||||||
0,
|
|
||||||
...videos.map((it) => ({
|
|
||||||
...it,
|
|
||||||
ownerId: it.ownerId ?? this.owner?.id,
|
|
||||||
})),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const state = this.queue.queue.store.store.getState();
|
||||||
|
|
||||||
this.queue?.dispatch({
|
this.queue?.dispatch({
|
||||||
type: 'ADD_ITEMS',
|
type: 'ADD_ITEMS',
|
||||||
payload: {
|
payload: {
|
||||||
nextQueueItemId:
|
nextQueueItemId: state.queue.nextQueueItemId,
|
||||||
this.queue.queue.store.store.getState().queue.nextQueueItemId,
|
|
||||||
index:
|
index:
|
||||||
index ??
|
index ??
|
||||||
this.queue.queue.store.store.getState().queue.items.length ??
|
(state.queue.items.length ? state.queue.items.length - 1 : null) ??
|
||||||
0,
|
0,
|
||||||
items,
|
items,
|
||||||
shuffleEnabled: false,
|
shuffleEnabled: false,
|
||||||
shouldAssignIds: true,
|
shouldAssignIds: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const insertedItem = this._videoList[index ?? this._videoList.length];
|
||||||
|
if (
|
||||||
|
!insertedItem ||
|
||||||
|
(insertedItem.videoId !== videos[0].videoId &&
|
||||||
|
insertedItem.ownerId !== videos[0].ownerId)
|
||||||
|
) {
|
||||||
|
this._videoList.splice(
|
||||||
|
index ?? this._videoList.length,
|
||||||
|
0,
|
||||||
|
...videos.map((it) => ({
|
||||||
|
...it,
|
||||||
|
ownerId: it.ownerId ?? this.owner?.id,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.internalDispatch = false;
|
this.internalDispatch = false;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.initQueue();
|
this.initQueue();
|
||||||
@ -364,7 +374,15 @@ export class Queue {
|
|||||||
}
|
}
|
||||||
).items,
|
).items,
|
||||||
);
|
);
|
||||||
this._videoList.push(
|
this._videoList.splice(
|
||||||
|
event.payload && Object.hasOwn(event.payload, 'index')
|
||||||
|
? (
|
||||||
|
event.payload as {
|
||||||
|
index: number;
|
||||||
|
}
|
||||||
|
).index
|
||||||
|
: this._videoList.length,
|
||||||
|
0,
|
||||||
...videoList.map((it) => ({
|
...videoList.map((it) => ({
|
||||||
...it,
|
...it,
|
||||||
ownerId: it.ownerId ?? this.owner?.id,
|
ownerId: it.ownerId ?? this.owner?.id,
|
||||||
@ -516,14 +534,16 @@ export class Queue {
|
|||||||
|
|
||||||
allQueue.forEach((queue) => {
|
allQueue.forEach((queue) => {
|
||||||
const list = Array.from(
|
const list = Array.from(
|
||||||
queue?.querySelectorAll<HTMLElement>('ytmusic-player-queue-item') ?? [],
|
queue?.querySelectorAll<HTMLElement>(
|
||||||
|
'#contents > ytmusic-player-queue-item,#contents > ytmusic-playlist-panel-video-wrapper-renderer > #primary-renderer > ytmusic-player-queue-item',
|
||||||
|
) ?? [],
|
||||||
);
|
);
|
||||||
|
|
||||||
list.forEach((item, index: number | undefined) => {
|
list.forEach((item, index: number | undefined) => {
|
||||||
if (typeof index !== 'number') return;
|
if (typeof index !== 'number') return;
|
||||||
|
|
||||||
const id = this._videoList[index]?.ownerId;
|
const id = this._videoList[index]?.ownerId;
|
||||||
const data = this.getProfile(id);
|
let data = this.getProfile(id);
|
||||||
|
|
||||||
const profile =
|
const profile =
|
||||||
item.querySelector<HTMLImageElement>('.music-together-owner') ??
|
item.querySelector<HTMLImageElement>('.music-together-owner') ??
|
||||||
@ -539,6 +559,10 @@ export class Queue {
|
|||||||
name.textContent =
|
name.textContent =
|
||||||
data?.name ?? t('plugins.music-together.internal.unknown-user');
|
data?.name ?? t('plugins.music-together.internal.unknown-user');
|
||||||
|
|
||||||
|
if (!data?.name && !data?.handleId) {
|
||||||
|
data = getDefaultProfile(data?.id ?? '');
|
||||||
|
}
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
profile.dataset.thumbnail = data.thumbnail ?? '';
|
profile.dataset.thumbnail = data.thumbnail ?? '';
|
||||||
profile.dataset.name = data.name ?? '';
|
profile.dataset.name = data.name ?? '';
|
||||||
|
|||||||
Reference in New Issue
Block a user