Verified Commit 91c74503 authored by Chocobozzz's avatar Chocobozzz
Browse files

Prefer using a filter for playlist elements hook

parent 9f743888
......@@ -155,7 +155,7 @@ export class MyVideoPlaylistElementsComponent implements OnInit, OnDestroy {
}
private loadElements () {
this.videoPlaylistService.getPlaylistVideos(this.videoPlaylistId, this.pagination)
this.videoPlaylistService.getPlaylistVideos({ videoPlaylistId: this.videoPlaylistId, componentPagination: this.pagination })
.subscribe(({ total, data }) => {
this.playlistElements = this.playlistElements.concat(data)
this.pagination.totalItems = total
......
......@@ -96,36 +96,38 @@ export class VideoWatchPlaylistComponent {
}
loadPlaylistElements (playlist: VideoPlaylist, redirectToFirst = false, position?: number) {
this.videoPlaylist.getPlaylistVideos(playlist.uuid, this.playlistPagination)
.subscribe(({ total, data: playlistElements }) => {
this.playlistElements = this.playlistElements.concat(playlistElements)
this.playlistPagination.totalItems = total
const firstAvailableVideo = this.playlistElements.find(e => !!e.video)
if (!firstAvailableVideo) {
this.noPlaylistVideos = true
return
}
if (position) this.updatePlaylistIndex(position)
if (redirectToFirst) {
const extras = {
queryParams: {
start: firstAvailableVideo.startTimestamp,
stop: firstAvailableVideo.stopTimestamp,
playlistPosition: firstAvailableVideo.position
},
replaceUrl: true
}
this.router.navigate([], extras)
}
this.hooks.runAction('action:video-watch-playlist.elements.loaded', 'video-watch', {
playlist: this.playlist,
playlistElements
})
})
const obs = this.hooks.wrapObsFun(
this.videoPlaylist.getPlaylistVideos.bind(this.videoPlaylist),
{ 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
const firstAvailableVideo = this.playlistElements.find(e => !!e.video)
if (!firstAvailableVideo) {
this.noPlaylistVideos = true
return
}
if (position) this.updatePlaylistIndex(position)
if (redirectToFirst) {
const extras = {
queryParams: {
start: firstAvailableVideo.startTimestamp,
stop: firstAvailableVideo.stopTimestamp,
playlistPosition: firstAvailableVideo.position
},
replaceUrl: true
}
this.router.navigate([], extras)
}
})
}
updatePlaylistIndex (position: number) {
......
......@@ -256,12 +256,12 @@ export class VideoPlaylistService {
)
}
getPlaylistVideos (
videoPlaylistId: number | string,
getPlaylistVideos (options: {
videoPlaylistId: number | string
componentPagination: ComponentPaginationLight
): Observable<ResultList<VideoPlaylistElement>> {
const path = VideoPlaylistService.BASE_VIDEO_PLAYLIST_URL + videoPlaylistId + '/videos'
const pagination = this.restService.componentPaginationToRestPagination(componentPagination)
}): Observable<ResultList<VideoPlaylistElement>> {
const path = VideoPlaylistService.BASE_VIDEO_PLAYLIST_URL + options.videoPlaylistId + '/videos'
const pagination = this.restService.componentPaginationToRestPagination(options.componentPagination)
let params = new HttpParams()
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.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:api.video-watch.video-threads.list.params': true,
'filter:api.video-watch.video-threads.list.result': true,
......@@ -81,8 +85,6 @@ export const clientActionHookObject = {
'action:video-watch.video-threads.loaded': true,
// Fired when a user click on 'View x replies' and they're loaded
'action:video-watch.video-thread-replies.loaded': true,
// Fired when video watch playlist elements are loaded
'action:video-watch-playlist.elements.loaded': true,
// Fired when the video edit page (upload, URL/torrent import, update) is being initialized
'action:video-edit.init': true,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment