X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fshared-video-comment%2Fvideo-comment.service.ts;h=fd1cae7f89c17b46e2d2a62106699d761bba4037;hb=51353d9a035fb6b81f903a8b5f391292841649fd;hp=1ab996a7647cb260986abd08086c79ca3977d204;hpb=19149d45b8f68569535f7188ef25e09e3d62c8b4;p=github%2FChocobozzz%2FPeerTube.git 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 1ab996a76..fd1cae7f8 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 @@ -1,5 +1,6 @@ -import { Observable } from 'rxjs' -import { catchError, map } from 'rxjs/operators' +import { SortMeta } from 'primeng/api' +import { from, Observable } from 'rxjs' +import { catchError, concatMap, map, toArray } from 'rxjs/operators' import { HttpClient, HttpParams } from '@angular/common/http' import { Injectable } from '@angular/core' import { ComponentPaginationLight, RestExtractor, RestPagination, RestService } from '@app/core' @@ -7,6 +8,8 @@ import { objectLineFeedToHtml } from '@app/helpers' import { FeedFormat, ResultList, + ThreadsResultList, + Video, VideoComment as VideoCommentServerModel, VideoCommentAdmin, VideoCommentCreate, @@ -15,7 +18,6 @@ import { import { environment } from '../../../environments/environment' import { VideoCommentThreadTree } from './video-comment-thread-tree.model' import { VideoComment } from './video-comment.model' -import { SortMeta } from 'primeng/api' @Injectable() export class VideoCommentService { @@ -35,8 +37,8 @@ export class VideoCommentService { return this.authHttp.post<{ comment: VideoCommentServerModel }>(url, normalizedComment) .pipe( - map(data => this.extractVideoComment(data.comment)), - catchError(err => this.restExtractor.handleError(err)) + map(data => this.extractVideoComment(data.comment)), + catchError(err => this.restExtractor.handleError(err)) ) } @@ -52,8 +54,8 @@ export class VideoCommentService { } getAdminVideoComments (options: { - pagination: RestPagination, - sort: SortMeta, + pagination: RestPagination + sort: SortMeta search?: string }): Observable> { const { pagination, sort, search } = options @@ -73,19 +75,19 @@ export class VideoCommentService { } getVideoCommentThreads (parameters: { - videoId: number | string, - componentPagination: ComponentPaginationLight, + videoId: number | string + componentPagination: ComponentPaginationLight sort: string - }): Observable> { + }): Observable> { const { videoId, componentPagination, sort } = parameters - const pagination = this.restService.componentPaginationToRestPagination(componentPagination) + const pagination = this.restService.componentToRestPagination(componentPagination) let params = new HttpParams() 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)) @@ -93,7 +95,7 @@ export class VideoCommentService { } getVideoThreadComments (parameters: { - videoId: number | string, + videoId: number | string threadId: number }): Observable { const { videoId, threadId } = parameters @@ -118,7 +120,15 @@ export class VideoCommentService { ) } - getVideoCommentsFeeds (videoUUID?: string) { + deleteVideoComments (comments: { videoId: number | string, commentId: number }[]) { + return from(comments) + .pipe( + concatMap(c => this.deleteVideoComment(c.videoId, c.commentId)), + toArray() + ) + } + + getVideoCommentsFeeds (video: Pick) { const feeds = [ { format: FeedFormat.RSS, @@ -137,9 +147,9 @@ export class VideoCommentService { } ] - if (videoUUID !== undefined) { + if (video !== undefined) { for (const feed of feeds) { - feed.url += '?videoId=' + videoUUID + feed.url += '?videoId=' + video.uuid } } @@ -150,7 +160,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[] = [] @@ -159,29 +169,29 @@ 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)) + } - return tree as VideoCommentThreadTree + const hasDisplayedChildren = tree.children.length === 0 + ? !tree.comment.isDeleted + : tree.children.some(c => c.hasDisplayedChildren) + + return Object.assign(tree, { hasDisplayedChildren }) } private buildParamsFromSearch (search: string, params: HttpParams) { const filters = this.restService.parseQueryStringFilter(search, { isLocal: { prefix: 'local:', - isBoolean: true, - handler: v => { - if (v === 'true') return v - if (v === 'false') return v - - return undefined - } + isBoolean: true }, searchAccount: { prefix: 'account:' },