From 93cae47925e4dd68b7d34a41927b2740b4fab1b4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 22 Jul 2019 15:40:13 +0200 Subject: Add client hooks --- .../+video-watch/comment/video-comment.service.ts | 12 +++-- .../comment/video-comments.component.ts | 55 ++++++++++++++++------ .../+video-watch/video-watch-playlist.component.ts | 8 ++-- .../videos/+video-watch/video-watch.component.ts | 16 ++++++- 4 files changed, 68 insertions(+), 23 deletions(-) (limited to 'client/src/app/videos/+video-watch') diff --git a/client/src/app/videos/+video-watch/comment/video-comment.service.ts b/client/src/app/videos/+video-watch/comment/video-comment.service.ts index b8e5878c5..eb608a1a3 100644 --- a/client/src/app/videos/+video-watch/comment/video-comment.service.ts +++ b/client/src/app/videos/+video-watch/comment/video-comment.service.ts @@ -48,11 +48,13 @@ export class VideoCommentService { ) } - getVideoCommentThreads ( + getVideoCommentThreads (parameters: { videoId: number | string, componentPagination: ComponentPagination, sort: VideoSortField - ): Observable<{ comments: VideoComment[], totalComments: number}> { + }): Observable<{ comments: VideoComment[], totalComments: number}> { + const { videoId, componentPagination, sort } = parameters + const pagination = this.restService.componentPaginationToRestPagination(componentPagination) let params = new HttpParams() @@ -67,7 +69,11 @@ export class VideoCommentService { ) } - getVideoThreadComments (videoId: number | string, threadId: number): Observable { + getVideoThreadComments (parameters: { + videoId: number | string, + threadId: number + }): Observable { + const { videoId, threadId } = parameters const url = `${VideoCommentService.BASE_VIDEO_URL + videoId}/comment-threads/${threadId}` return this.authHttp diff --git a/client/src/app/videos/+video-watch/comment/video-comments.component.ts b/client/src/app/videos/+video-watch/comment/video-comments.component.ts index 3acddbe6a..3c1a0986c 100644 --- a/client/src/app/videos/+video-watch/comment/video-comments.component.ts +++ b/client/src/app/videos/+video-watch/comment/video-comments.component.ts @@ -12,6 +12,7 @@ import { VideoComment } from './video-comment.model' import { VideoCommentService } from './video-comment.service' import { I18n } from '@ngx-translate/i18n-polyfill' import { Syndication } from '@app/shared/video/syndication.model' +import { HooksService } from '@app/core/plugins/hooks.service' @Component({ selector: 'my-video-comments', @@ -45,7 +46,8 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy { private confirmService: ConfirmService, private videoCommentService: VideoCommentService, private activatedRoute: ActivatedRoute, - private i18n: I18n + private i18n: I18n, + private hooks: HooksService ) {} ngOnInit () { @@ -73,8 +75,20 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy { viewReplies (commentId: number, highlightThread = false) { this.threadLoading[commentId] = true - this.videoCommentService.getVideoThreadComments(this.video.id, commentId) - .subscribe( + const params = { + videoId: this.video.id, + threadId: commentId + } + + const obs = this.hooks.wrapObsFun( + this.videoCommentService.getVideoThreadComments.bind(this.videoCommentService), + params, + 'video-watch', + 'filter:api.video-watch.video-thread-replies.list.params', + 'filter:api.video-watch.video-thread-replies.list.result' + ) + + obs.subscribe( res => { this.threadComments[commentId] = res this.threadLoading[commentId] = false @@ -91,16 +105,29 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy { ) } - loadMoreComments () { - this.videoCommentService.getVideoCommentThreads(this.video.id, this.componentPagination, this.sort) - .subscribe( - res => { - this.comments = this.comments.concat(res.comments) - this.componentPagination.totalItems = res.totalComments - }, + loadMoreThreads () { + const params = { + videoId: this.video.id, + componentPagination: this.componentPagination, + sort: this.sort + } - err => this.notifier.error(err.message) - ) + const obs = this.hooks.wrapObsFun( + this.videoCommentService.getVideoCommentThreads.bind(this.videoCommentService), + params, + 'video-watch', + 'filter:api.video-watch.video-threads.list.params', + 'filter:api.video-watch.video-threads.list.result' + ) + + obs.subscribe( + res => { + this.comments = this.comments.concat(res.comments) + this.componentPagination.totalItems = res.totalComments + }, + + err => this.notifier.error(err.message) + ) } onCommentThreadCreated (comment: VideoComment) { @@ -169,7 +196,7 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy { this.componentPagination.currentPage++ if (hasMoreItems(this.componentPagination)) { - this.loadMoreComments() + this.loadMoreThreads() } } @@ -197,7 +224,7 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy { this.syndicationItems = this.videoCommentService.getVideoCommentsFeeds(this.video.uuid) - this.loadMoreComments() + this.loadMoreThreads() } } 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 bccdaf7b2..2fb0cb0e5 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 @@ -66,11 +66,11 @@ export class VideoWatchPlaylistComponent { loadPlaylistElements (playlist: VideoPlaylist, redirectToFirst = false) { this.videoService.getPlaylistVideos(playlist.uuid, this.playlistPagination) - .subscribe(({ totalVideos, videos }) => { - this.playlistVideos = this.playlistVideos.concat(videos) - this.playlistPagination.totalItems = totalVideos + .subscribe(({ total, data }) => { + this.playlistVideos = this.playlistVideos.concat(data) + this.playlistPagination.totalItems = total - if (totalVideos === 0) { + if (total === 0) { this.noPlaylistVideos = true return } 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 6d8bb4b3f..eed2ec048 100644 --- a/client/src/app/videos/+video-watch/video-watch.component.ts +++ b/client/src/app/videos/+video-watch/video-watch.component.ts @@ -33,6 +33,7 @@ import { isWebRTCDisabled, timeToInt } from '../../../assets/player/utils' import { VideoWatchPlaylistComponent } from '@app/videos/+video-watch/video-watch-playlist.component' import { getStoredTheater } from '../../../assets/player/peertube-player-local-storage' import { PluginService } from '@app/core/plugins/plugin.service' +import { HooksService } from '@app/core/plugins/hooks.service' @Component({ selector: 'my-video-watch', @@ -93,6 +94,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { private videoCaptionService: VideoCaptionService, private i18n: I18n, private hotkeysService: HotkeysService, + private hooks: HooksService, @Inject(LOCALE_ID) private localeId: string ) {} @@ -131,7 +133,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { this.theaterEnabled = getStoredTheater() - this.pluginService.runHook('action:video-watch.loaded') + this.hooks.runAction('action:video-watch.init') } ngOnDestroy () { @@ -246,9 +248,17 @@ export class VideoWatchComponent implements OnInit, OnDestroy { if (this.player) this.player.pause() + const videoObs = this.hooks.wrapObsFun( + this.videoService.getVideo.bind(this.videoService), + { videoId }, + 'video-watch', + 'filter:api.video-watch.video.get.params', + 'filter:api.video-watch.video.get.result' + ) + // Video did change forkJoin( - this.videoService.getVideo(videoId), + videoObs, this.videoCaptionService.listCaptions(videoId) ) .pipe( @@ -486,6 +496,8 @@ export class VideoWatchComponent implements OnInit, OnDestroy { this.setOpenGraphTags() this.checkUserRating() + + this.hooks.runAction('action:video-watch.video.loaded') } private setRating (nextRating: UserVideoRateType) { -- cgit v1.2.3