aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-video-comment
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/shared-video-comment')
-rw-r--r--client/src/app/shared/shared-video-comment/video-comment-thread-tree.model.ts1
-rw-r--r--client/src/app/shared/shared-video-comment/video-comment.service.ts25
2 files changed, 17 insertions, 9 deletions
diff --git a/client/src/app/shared/shared-video-comment/video-comment-thread-tree.model.ts b/client/src/app/shared/shared-video-comment/video-comment-thread-tree.model.ts
index 7c2aaeadd..9956c88a6 100644
--- a/client/src/app/shared/shared-video-comment/video-comment-thread-tree.model.ts
+++ b/client/src/app/shared/shared-video-comment/video-comment-thread-tree.model.ts
@@ -3,5 +3,6 @@ import { VideoComment } from './video-comment.model'
3 3
4export class VideoCommentThreadTree implements VideoCommentThreadTreeServerModel { 4export class VideoCommentThreadTree implements VideoCommentThreadTreeServerModel {
5 comment: VideoComment 5 comment: VideoComment
6 hasDisplayedChildren: boolean
6 children: VideoCommentThreadTree[] 7 children: VideoCommentThreadTree[]
7} 8}
diff --git a/client/src/app/shared/shared-video-comment/video-comment.service.ts b/client/src/app/shared/shared-video-comment/video-comment.service.ts
index c107a33ab..0f09778df 100644
--- a/client/src/app/shared/shared-video-comment/video-comment.service.ts
+++ b/client/src/app/shared/shared-video-comment/video-comment.service.ts
@@ -8,6 +8,7 @@ import { objectLineFeedToHtml } from '@app/helpers'
8import { 8import {
9 FeedFormat, 9 FeedFormat,
10 ResultList, 10 ResultList,
11 ThreadsResultList,
11 VideoComment as VideoCommentServerModel, 12 VideoComment as VideoCommentServerModel,
12 VideoCommentAdmin, 13 VideoCommentAdmin,
13 VideoCommentCreate, 14 VideoCommentCreate,
@@ -76,7 +77,7 @@ export class VideoCommentService {
76 videoId: number | string, 77 videoId: number | string,
77 componentPagination: ComponentPaginationLight, 78 componentPagination: ComponentPaginationLight,
78 sort: string 79 sort: string
79 }): Observable<ResultList<VideoComment>> { 80 }): Observable<ThreadsResultList<VideoComment>> {
80 const { videoId, componentPagination, sort } = parameters 81 const { videoId, componentPagination, sort } = parameters
81 82
82 const pagination = this.restService.componentPaginationToRestPagination(componentPagination) 83 const pagination = this.restService.componentPaginationToRestPagination(componentPagination)
@@ -85,7 +86,7 @@ export class VideoCommentService {
85 params = this.restService.addRestGetParams(params, pagination, sort) 86 params = this.restService.addRestGetParams(params, pagination, sort)
86 87
87 const url = VideoCommentService.BASE_VIDEO_URL + videoId + '/comment-threads' 88 const url = VideoCommentService.BASE_VIDEO_URL + videoId + '/comment-threads'
88 return this.authHttp.get<ResultList<VideoComment>>(url, { params }) 89 return this.authHttp.get<ThreadsResultList<VideoComment>>(url, { params })
89 .pipe( 90 .pipe(
90 map(result => this.extractVideoComments(result)), 91 map(result => this.extractVideoComments(result)),
91 catchError(err => this.restExtractor.handleError(err)) 92 catchError(err => this.restExtractor.handleError(err))
@@ -158,7 +159,7 @@ export class VideoCommentService {
158 return new VideoComment(videoComment) 159 return new VideoComment(videoComment)
159 } 160 }
160 161
161 private extractVideoComments (result: ResultList<VideoCommentServerModel>) { 162 private extractVideoComments (result: ThreadsResultList<VideoCommentServerModel>) {
162 const videoCommentsJson = result.data 163 const videoCommentsJson = result.data
163 const totalComments = result.total 164 const totalComments = result.total
164 const comments: VideoComment[] = [] 165 const comments: VideoComment[] = []
@@ -167,16 +168,22 @@ export class VideoCommentService {
167 comments.push(new VideoComment(videoCommentJson)) 168 comments.push(new VideoComment(videoCommentJson))
168 } 169 }
169 170
170 return { data: comments, total: totalComments } 171 return { data: comments, total: totalComments, totalNotDeletedComments: result.totalNotDeletedComments }
171 } 172 }
172 173
173 private extractVideoCommentTree (tree: VideoCommentThreadTreeServerModel) { 174 private extractVideoCommentTree (serverTree: VideoCommentThreadTreeServerModel): VideoCommentThreadTree {
174 if (!tree) return tree as VideoCommentThreadTree 175 if (!serverTree) return null
175 176
176 tree.comment = new VideoComment(tree.comment) 177 const tree = {
177 tree.children.forEach(c => this.extractVideoCommentTree(c)) 178 comment: new VideoComment(serverTree.comment),
179 children: serverTree.children.map(c => this.extractVideoCommentTree(c))
180 }
181
182 const hasDisplayedChildren = tree.children.length === 0
183 ? !tree.comment.isDeleted
184 : tree.children.some(c => c.hasDisplayedChildren)
178 185
179 return tree as VideoCommentThreadTree 186 return Object.assign(tree, { hasDisplayedChildren })
180 } 187 }
181 188
182 private buildParamsFromSearch (search: string, params: HttpParams) { 189 private buildParamsFromSearch (search: string, params: HttpParams) {