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/video-comments.component.ts | |
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/video-comments.component.ts')
-rw-r--r-- | client/src/app/videos/+video-watch/comment/video-comments.component.ts | 55 |
1 files changed, 41 insertions, 14 deletions
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 | ||