aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/+video-watch
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-22 15:40:13 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-07-24 10:58:16 +0200
commit93cae47925e4dd68b7d34a41927b2740b4fab1b4 (patch)
treef649ab49fab1886b434e164591990cc99b234466 /client/src/app/videos/+video-watch
parent587568e1cc0e33c023c1ac62dd28fef313285250 (diff)
downloadPeerTube-93cae47925e4dd68b7d34a41927b2740b4fab1b4.tar.gz
PeerTube-93cae47925e4dd68b7d34a41927b2740b4fab1b4.tar.zst
PeerTube-93cae47925e4dd68b7d34a41927b2740b4fab1b4.zip
Add client hooks
Diffstat (limited to 'client/src/app/videos/+video-watch')
-rw-r--r--client/src/app/videos/+video-watch/comment/video-comment.service.ts12
-rw-r--r--client/src/app/videos/+video-watch/comment/video-comments.component.ts55
-rw-r--r--client/src/app/videos/+video-watch/video-watch-playlist.component.ts8
-rw-r--r--client/src/app/videos/+video-watch/video-watch.component.ts16
4 files changed, 68 insertions, 23 deletions
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 {
48 ) 48 )
49 } 49 }
50 50
51 getVideoCommentThreads ( 51 getVideoCommentThreads (parameters: {
52 videoId: number | string, 52 videoId: number | string,
53 componentPagination: ComponentPagination, 53 componentPagination: ComponentPagination,
54 sort: VideoSortField 54 sort: VideoSortField
55 ): Observable<{ comments: VideoComment[], totalComments: number}> { 55 }): Observable<{ comments: VideoComment[], totalComments: number}> {
56 const { videoId, componentPagination, sort } = parameters
57
56 const pagination = this.restService.componentPaginationToRestPagination(componentPagination) 58 const pagination = this.restService.componentPaginationToRestPagination(componentPagination)
57 59
58 let params = new HttpParams() 60 let params = new HttpParams()
@@ -67,7 +69,11 @@ export class VideoCommentService {
67 ) 69 )
68 } 70 }
69 71
70 getVideoThreadComments (videoId: number | string, threadId: number): Observable<VideoCommentThreadTree> { 72 getVideoThreadComments (parameters: {
73 videoId: number | string,
74 threadId: number
75 }): Observable<VideoCommentThreadTree> {
76 const { videoId, threadId } = parameters
71 const url = `${VideoCommentService.BASE_VIDEO_URL + videoId}/comment-threads/${threadId}` 77 const url = `${VideoCommentService.BASE_VIDEO_URL + videoId}/comment-threads/${threadId}`
72 78
73 return this.authHttp 79 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'
12import { VideoCommentService } from './video-comment.service' 12import { VideoCommentService } from './video-comment.service'
13import { I18n } from '@ngx-translate/i18n-polyfill' 13import { I18n } from '@ngx-translate/i18n-polyfill'
14import { Syndication } from '@app/shared/video/syndication.model' 14import { Syndication } from '@app/shared/video/syndication.model'
15import { HooksService } from '@app/core/plugins/hooks.service'
15 16
16@Component({ 17@Component({
17 selector: 'my-video-comments', 18 selector: 'my-video-comments',
@@ -45,7 +46,8 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
45 private confirmService: ConfirmService, 46 private confirmService: ConfirmService,
46 private videoCommentService: VideoCommentService, 47 private videoCommentService: VideoCommentService,
47 private activatedRoute: ActivatedRoute, 48 private activatedRoute: ActivatedRoute,
48 private i18n: I18n 49 private i18n: I18n,
50 private hooks: HooksService
49 ) {} 51 ) {}
50 52
51 ngOnInit () { 53 ngOnInit () {
@@ -73,8 +75,20 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
73 viewReplies (commentId: number, highlightThread = false) { 75 viewReplies (commentId: number, highlightThread = false) {
74 this.threadLoading[commentId] = true 76 this.threadLoading[commentId] = true
75 77
76 this.videoCommentService.getVideoThreadComments(this.video.id, commentId) 78 const params = {
77 .subscribe( 79 videoId: this.video.id,
80 threadId: commentId
81 }
82
83 const obs = this.hooks.wrapObsFun(
84 this.videoCommentService.getVideoThreadComments.bind(this.videoCommentService),
85 params,
86 'video-watch',
87 'filter:api.video-watch.video-thread-replies.list.params',
88 'filter:api.video-watch.video-thread-replies.list.result'
89 )
90
91 obs.subscribe(
78 res => { 92 res => {
79 this.threadComments[commentId] = res 93 this.threadComments[commentId] = res
80 this.threadLoading[commentId] = false 94 this.threadLoading[commentId] = false
@@ -91,16 +105,29 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
91 ) 105 )
92 } 106 }
93 107
94 loadMoreComments () { 108 loadMoreThreads () {
95 this.videoCommentService.getVideoCommentThreads(this.video.id, this.componentPagination, this.sort) 109 const params = {
96 .subscribe( 110 videoId: this.video.id,
97 res => { 111 componentPagination: this.componentPagination,
98 this.comments = this.comments.concat(res.comments) 112 sort: this.sort
99 this.componentPagination.totalItems = res.totalComments 113 }
100 },
101 114
102 err => this.notifier.error(err.message) 115 const obs = this.hooks.wrapObsFun(
103 ) 116 this.videoCommentService.getVideoCommentThreads.bind(this.videoCommentService),
117 params,
118 'video-watch',
119 'filter:api.video-watch.video-threads.list.params',
120 'filter:api.video-watch.video-threads.list.result'
121 )
122
123 obs.subscribe(
124 res => {
125 this.comments = this.comments.concat(res.comments)
126 this.componentPagination.totalItems = res.totalComments
127 },
128
129 err => this.notifier.error(err.message)
130 )
104 } 131 }
105 132
106 onCommentThreadCreated (comment: VideoComment) { 133 onCommentThreadCreated (comment: VideoComment) {
@@ -169,7 +196,7 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
169 this.componentPagination.currentPage++ 196 this.componentPagination.currentPage++
170 197
171 if (hasMoreItems(this.componentPagination)) { 198 if (hasMoreItems(this.componentPagination)) {
172 this.loadMoreComments() 199 this.loadMoreThreads()
173 } 200 }
174 } 201 }
175 202
@@ -197,7 +224,7 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
197 224
198 this.syndicationItems = this.videoCommentService.getVideoCommentsFeeds(this.video.uuid) 225 this.syndicationItems = this.videoCommentService.getVideoCommentsFeeds(this.video.uuid)
199 226
200 this.loadMoreComments() 227 this.loadMoreThreads()
201 } 228 }
202 } 229 }
203 230
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 {
66 66
67 loadPlaylistElements (playlist: VideoPlaylist, redirectToFirst = false) { 67 loadPlaylistElements (playlist: VideoPlaylist, redirectToFirst = false) {
68 this.videoService.getPlaylistVideos(playlist.uuid, this.playlistPagination) 68 this.videoService.getPlaylistVideos(playlist.uuid, this.playlistPagination)
69 .subscribe(({ totalVideos, videos }) => { 69 .subscribe(({ total, data }) => {
70 this.playlistVideos = this.playlistVideos.concat(videos) 70 this.playlistVideos = this.playlistVideos.concat(data)
71 this.playlistPagination.totalItems = totalVideos 71 this.playlistPagination.totalItems = total
72 72
73 if (totalVideos === 0) { 73 if (total === 0) {
74 this.noPlaylistVideos = true 74 this.noPlaylistVideos = true
75 return 75 return
76 } 76 }
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'
33import { VideoWatchPlaylistComponent } from '@app/videos/+video-watch/video-watch-playlist.component' 33import { VideoWatchPlaylistComponent } from '@app/videos/+video-watch/video-watch-playlist.component'
34import { getStoredTheater } from '../../../assets/player/peertube-player-local-storage' 34import { getStoredTheater } from '../../../assets/player/peertube-player-local-storage'
35import { PluginService } from '@app/core/plugins/plugin.service' 35import { PluginService } from '@app/core/plugins/plugin.service'
36import { HooksService } from '@app/core/plugins/hooks.service'
36 37
37@Component({ 38@Component({
38 selector: 'my-video-watch', 39 selector: 'my-video-watch',
@@ -93,6 +94,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
93 private videoCaptionService: VideoCaptionService, 94 private videoCaptionService: VideoCaptionService,
94 private i18n: I18n, 95 private i18n: I18n,
95 private hotkeysService: HotkeysService, 96 private hotkeysService: HotkeysService,
97 private hooks: HooksService,
96 @Inject(LOCALE_ID) private localeId: string 98 @Inject(LOCALE_ID) private localeId: string
97 ) {} 99 ) {}
98 100
@@ -131,7 +133,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
131 133
132 this.theaterEnabled = getStoredTheater() 134 this.theaterEnabled = getStoredTheater()
133 135
134 this.pluginService.runHook('action:video-watch.loaded') 136 this.hooks.runAction('action:video-watch.init')
135 } 137 }
136 138
137 ngOnDestroy () { 139 ngOnDestroy () {
@@ -246,9 +248,17 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
246 248
247 if (this.player) this.player.pause() 249 if (this.player) this.player.pause()
248 250
251 const videoObs = this.hooks.wrapObsFun(
252 this.videoService.getVideo.bind(this.videoService),
253 { videoId },
254 'video-watch',
255 'filter:api.video-watch.video.get.params',
256 'filter:api.video-watch.video.get.result'
257 )
258
249 // Video did change 259 // Video did change
250 forkJoin( 260 forkJoin(
251 this.videoService.getVideo(videoId), 261 videoObs,
252 this.videoCaptionService.listCaptions(videoId) 262 this.videoCaptionService.listCaptions(videoId)
253 ) 263 )
254 .pipe( 264 .pipe(
@@ -486,6 +496,8 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
486 496
487 this.setOpenGraphTags() 497 this.setOpenGraphTags()
488 this.checkUserRating() 498 this.checkUserRating()
499
500 this.hooks.runAction('action:video-watch.video.loaded')
489 } 501 }
490 502
491 private setRating (nextRating: UserVideoRateType) { 503 private setRating (nextRating: UserVideoRateType) {