From 9d6b9d10ef8cbef39e89bc709285abffb0d8caa1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 19 Feb 2021 09:50:13 +0100 Subject: Fix video comments display with deleted comments --- .../comment/video-comment.component.html | 2 +- .../comment/video-comment.component.ts | 9 ++++++-- .../comment/video-comments.component.html | 8 +++---- .../comment/video-comments.component.ts | 10 +++++++-- .../video-comment-thread-tree.model.ts | 1 + .../shared-video-comment/video-comment.service.ts | 25 ++++++++++++++-------- 6 files changed, 37 insertions(+), 18 deletions(-) (limited to 'client') diff --git a/client/src/app/+videos/+video-watch/comment/video-comment.component.html b/client/src/app/+videos/+video-watch/comment/video-comment.component.html index 8847753a5..ba41b6f48 100644 --- a/client/src/app/+videos/+video-watch/comment/video-comment.component.html +++ b/client/src/app/+videos/+video-watch/comment/video-comment.component.html @@ -1,4 +1,4 @@ -
+

- + - 1 Comment - {{ componentPagination.totalItems }} Comments + 1 Comment + {{ totalNotDeletedComments }} Comments Comments

@@ -30,7 +30,7 @@ [textValue]="commentThreadRedraftValue" > -
No comments.
+
No comments.
{ this.comments = this.comments.concat(res.data) - // Client does not display removed comments - this.componentPagination.totalItems = res.total - this.comments.filter(c => c.isDeleted).length + this.componentPagination.totalItems = res.total + this.totalNotDeletedComments = res.totalNotDeletedComments this.onDataSubject.next(res.data) this.hooks.runAction('action:video-watch.video-threads.loaded', 'video-watch', { data: this.componentPagination }) @@ -241,6 +246,7 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy { this.inReplyToCommentId = undefined this.componentPagination.currentPage = 1 this.componentPagination.totalItems = null + this.totalNotDeletedComments = null this.syndicationItems = this.videoCommentService.getVideoCommentsFeeds(this.video.uuid) this.loadMoreThreads() 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' export class VideoCommentThreadTree implements VideoCommentThreadTreeServerModel { comment: VideoComment + hasDisplayedChildren: boolean children: VideoCommentThreadTree[] } 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' import { FeedFormat, ResultList, + ThreadsResultList, VideoComment as VideoCommentServerModel, VideoCommentAdmin, VideoCommentCreate, @@ -76,7 +77,7 @@ export class VideoCommentService { videoId: number | string, componentPagination: ComponentPaginationLight, sort: string - }): Observable> { + }): Observable> { const { videoId, componentPagination, sort } = parameters const pagination = this.restService.componentPaginationToRestPagination(componentPagination) @@ -85,7 +86,7 @@ export class VideoCommentService { params = this.restService.addRestGetParams(params, pagination, sort) const url = VideoCommentService.BASE_VIDEO_URL + videoId + '/comment-threads' - return this.authHttp.get>(url, { params }) + return this.authHttp.get>(url, { params }) .pipe( map(result => this.extractVideoComments(result)), catchError(err => this.restExtractor.handleError(err)) @@ -158,7 +159,7 @@ export class VideoCommentService { return new VideoComment(videoComment) } - private extractVideoComments (result: ResultList) { + private extractVideoComments (result: ThreadsResultList) { const videoCommentsJson = result.data const totalComments = result.total const comments: VideoComment[] = [] @@ -167,16 +168,22 @@ export class VideoCommentService { comments.push(new VideoComment(videoCommentJson)) } - return { data: comments, total: totalComments } + return { data: comments, total: totalComments, totalNotDeletedComments: result.totalNotDeletedComments } } - private extractVideoCommentTree (tree: VideoCommentThreadTreeServerModel) { - if (!tree) return tree as VideoCommentThreadTree + private extractVideoCommentTree (serverTree: VideoCommentThreadTreeServerModel): VideoCommentThreadTree { + if (!serverTree) return null - tree.comment = new VideoComment(tree.comment) - tree.children.forEach(c => this.extractVideoCommentTree(c)) + const tree = { + comment: new VideoComment(serverTree.comment), + children: serverTree.children.map(c => this.extractVideoCommentTree(c)) + } + + const hasDisplayedChildren = tree.children.length === 0 + ? !tree.comment.isDeleted + : tree.children.some(c => c.hasDisplayedChildren) - return tree as VideoCommentThreadTree + return Object.assign(tree, { hasDisplayedChildren }) } private buildParamsFromSearch (search: string, params: HttpParams) { -- cgit v1.2.3