diff --git a/client/src/app/+videos/+video-watch/video-watch-playlist.component.ts b/client/src/app/+videos/+video-watch/video-watch-playlist.component.ts index a70167da5..0a4d6bfd1 100644 --- a/client/src/app/+videos/+video-watch/video-watch-playlist.component.ts +++ b/client/src/app/+videos/+video-watch/video-watch-playlist.component.ts @@ -118,6 +118,9 @@ export class VideoWatchPlaylistComponent { updatePlaylistIndex (position: number) { if (this.playlistElements.length === 0 || !position) return + // Handle the reverse index + if (position < 0) position = this.playlist.videosLength + position + 1 + for (const playlistElement of this.playlistElements) { // >= if the previous videos were not valid if (playlistElement.video && playlistElement.position >= position) { diff --git a/client/src/app/+videos/+video-watch/video-watch.component.ts b/client/src/app/+videos/+video-watch/video-watch.component.ts index 5530dc8ad..107826824 100644 --- a/client/src/app/+videos/+video-watch/video-watch.component.ts +++ b/client/src/app/+videos/+video-watch/video-watch.component.ts @@ -188,7 +188,18 @@ export class VideoWatchComponent implements OnInit, OnDestroy { }) this.queryParamsSub = this.route.queryParams.subscribe(queryParams => { - this.playlistPosition = queryParams[ 'playlistPosition' ] + // Handle the ?playlistPosition + const positionParam = queryParams[ 'playlistPosition' ] + + this.playlistPosition = positionParam === 'last' + ? -1 // Handle the "last" index + : parseInt(positionParam, 10) + + if (isNaN(this.playlistPosition)) { + console.error(`playlistPosition query param '${positionParam}' was parsed as NaN, defaulting to 1.`) + this.playlistPosition = 1 + } + this.videoWatchPlaylist.updatePlaylistIndex(this.playlistPosition) const start = queryParams[ 'start' ]