diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-22 15:40:13 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-07-24 10:58:16 +0200 |
commit | 93cae47925e4dd68b7d34a41927b2740b4fab1b4 (patch) | |
tree | f649ab49fab1886b434e164591990cc99b234466 /client/src/app/videos/+video-watch/comment | |
parent | 587568e1cc0e33c023c1ac62dd28fef313285250 (diff) | |
download | PeerTube-93cae47925e4dd68b7d34a41927b2740b4fab1b4.tar.gz PeerTube-93cae47925e4dd68b7d34a41927b2740b4fab1b4.tar.zst PeerTube-93cae47925e4dd68b7d34a41927b2740b4fab1b4.zip |
Add client hooks
Diffstat (limited to 'client/src/app/videos/+video-watch/comment')
-rw-r--r-- | client/src/app/videos/+video-watch/comment/video-comment.service.ts | 12 | ||||
-rw-r--r-- | client/src/app/videos/+video-watch/comment/video-comments.component.ts | 55 |
2 files changed, 50 insertions, 17 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' | |||
12 | import { VideoCommentService } from './video-comment.service' | 12 | import { VideoCommentService } from './video-comment.service' |
13 | import { I18n } from '@ngx-translate/i18n-polyfill' | 13 | import { I18n } from '@ngx-translate/i18n-polyfill' |
14 | import { Syndication } from '@app/shared/video/syndication.model' | 14 | import { Syndication } from '@app/shared/video/syndication.model' |
15 | import { 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 | ||