add ...playlist.elements.loaded hook (#4387)
* client: add ...playlist.elements.loaded hook closes #4385 * fix linting error * client: add playlist metadata to video-watch hooks * Prefer using a filter for playlist elements hook Co-authored-by: Chocobozzz <me@florianbigard.com>
This commit is contained in:
parent
8d8a037e3f
commit
c3bb04413e
|
@ -155,7 +155,7 @@ export class MyVideoPlaylistElementsComponent implements OnInit, OnDestroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
private loadElements () {
|
private loadElements () {
|
||||||
this.videoPlaylistService.getPlaylistVideos(this.videoPlaylistId, this.pagination)
|
this.videoPlaylistService.getPlaylistVideos({ videoPlaylistId: this.videoPlaylistId, componentPagination: this.pagination })
|
||||||
.subscribe(({ total, data }) => {
|
.subscribe(({ total, data }) => {
|
||||||
this.playlistElements = this.playlistElements.concat(data)
|
this.playlistElements = this.playlistElements.concat(data)
|
||||||
this.pagination.totalItems = total
|
this.pagination.totalItems = total
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
import { Component, EventEmitter, Input, Output } from '@angular/core'
|
import { Component, EventEmitter, Input, Output } from '@angular/core'
|
||||||
import { Router } from '@angular/router'
|
import { Router } from '@angular/router'
|
||||||
import { AuthService, ComponentPagination, LocalStorageService, Notifier, SessionStorageService, UserService } from '@app/core'
|
import {
|
||||||
|
AuthService,
|
||||||
|
ComponentPagination,
|
||||||
|
HooksService,
|
||||||
|
LocalStorageService,
|
||||||
|
Notifier,
|
||||||
|
SessionStorageService,
|
||||||
|
UserService
|
||||||
|
} from '@app/core'
|
||||||
import { VideoPlaylist, VideoPlaylistElement, VideoPlaylistService } from '@app/shared/shared-video-playlist'
|
import { VideoPlaylist, VideoPlaylistElement, VideoPlaylistService } from '@app/shared/shared-video-playlist'
|
||||||
import { peertubeLocalStorage, peertubeSessionStorage } from '@root-helpers/peertube-web-storage'
|
import { peertubeLocalStorage, peertubeSessionStorage } from '@root-helpers/peertube-web-storage'
|
||||||
import { VideoPlaylistPrivacy } from '@shared/models'
|
import { VideoPlaylistPrivacy } from '@shared/models'
|
||||||
|
@ -34,6 +42,7 @@ export class VideoWatchPlaylistComponent {
|
||||||
currentPlaylistPosition: number
|
currentPlaylistPosition: number
|
||||||
|
|
||||||
constructor (
|
constructor (
|
||||||
|
private hooks: HooksService,
|
||||||
private userService: UserService,
|
private userService: UserService,
|
||||||
private auth: AuthService,
|
private auth: AuthService,
|
||||||
private notifier: Notifier,
|
private notifier: Notifier,
|
||||||
|
@ -87,9 +96,16 @@ export class VideoWatchPlaylistComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
loadPlaylistElements (playlist: VideoPlaylist, redirectToFirst = false, position?: number) {
|
loadPlaylistElements (playlist: VideoPlaylist, redirectToFirst = false, position?: number) {
|
||||||
this.videoPlaylist.getPlaylistVideos(playlist.uuid, this.playlistPagination)
|
const obs = this.hooks.wrapObsFun(
|
||||||
.subscribe(({ total, data }) => {
|
this.videoPlaylist.getPlaylistVideos.bind(this.videoPlaylist),
|
||||||
this.playlistElements = this.playlistElements.concat(data)
|
{ videoPlaylistId: playlist.uuid, componentPagination: this.playlistPagination },
|
||||||
|
'video-watch',
|
||||||
|
'filter:api.video-watch.video-playlist-elements.get.params',
|
||||||
|
'filter:api.video-watch.video-playlist-elements.get.result'
|
||||||
|
)
|
||||||
|
|
||||||
|
obs.subscribe(({ total, data: playlistElements }) => {
|
||||||
|
this.playlistElements = this.playlistElements.concat(playlistElements)
|
||||||
this.playlistPagination.totalItems = total
|
this.playlistPagination.totalItems = total
|
||||||
|
|
||||||
const firstAvailableVideo = this.playlistElements.find(e => !!e.video)
|
const firstAvailableVideo = this.playlistElements.find(e => !!e.video)
|
||||||
|
|
|
@ -455,7 +455,13 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
|
||||||
this.zone.run(() => this.theaterEnabled = enabled)
|
this.zone.run(() => this.theaterEnabled = enabled)
|
||||||
})
|
})
|
||||||
|
|
||||||
this.hooks.runAction('action:video-watch.player.loaded', 'video-watch', { player: this.player, videojs, video: this.video })
|
this.hooks.runAction('action:video-watch.player.loaded', 'video-watch', {
|
||||||
|
player: this.player,
|
||||||
|
playlist: this.playlist,
|
||||||
|
playlistPosition: this.playlistPosition,
|
||||||
|
videojs,
|
||||||
|
video: this.video
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -256,12 +256,12 @@ export class VideoPlaylistService {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
getPlaylistVideos (
|
getPlaylistVideos (options: {
|
||||||
videoPlaylistId: number | string,
|
videoPlaylistId: number | string
|
||||||
componentPagination: ComponentPaginationLight
|
componentPagination: ComponentPaginationLight
|
||||||
): Observable<ResultList<VideoPlaylistElement>> {
|
}): Observable<ResultList<VideoPlaylistElement>> {
|
||||||
const path = VideoPlaylistService.BASE_VIDEO_PLAYLIST_URL + videoPlaylistId + '/videos'
|
const path = VideoPlaylistService.BASE_VIDEO_PLAYLIST_URL + options.videoPlaylistId + '/videos'
|
||||||
const pagination = this.restService.componentPaginationToRestPagination(componentPagination)
|
const pagination = this.restService.componentPaginationToRestPagination(options.componentPagination)
|
||||||
|
|
||||||
let params = new HttpParams()
|
let params = new HttpParams()
|
||||||
params = this.restService.addRestGetParams(params, pagination)
|
params = this.restService.addRestGetParams(params, pagination)
|
||||||
|
|
|
@ -26,6 +26,10 @@ export const clientFilterHookObject = {
|
||||||
'filter:api.video-watch.video.get.params': true,
|
'filter:api.video-watch.video.get.params': true,
|
||||||
'filter:api.video-watch.video.get.result': true,
|
'filter:api.video-watch.video.get.result': true,
|
||||||
|
|
||||||
|
// Filter params/result of the function that fetch video playlist elements of the video-watch page
|
||||||
|
'filter:api.video-watch.video-playlist-elements.get.params': true,
|
||||||
|
'filter:api.video-watch.video-playlist-elements.get.result': true,
|
||||||
|
|
||||||
// Filter params/result of the function that fetch the threads of the video-watch page
|
// Filter params/result of the function that fetch the threads of the video-watch page
|
||||||
'filter:api.video-watch.video-threads.list.params': true,
|
'filter:api.video-watch.video-threads.list.params': true,
|
||||||
'filter:api.video-watch.video-threads.list.result': true,
|
'filter:api.video-watch.video-threads.list.result': true,
|
||||||
|
|
Loading…
Reference in New Issue