X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fshared-video-comment%2Fvideo-comment.service.ts;h=c5aeb3c12e86ec24e6df9b46b29d172e1adb3f21;hb=8cbc40b2fe9d36ef0505b9441276ca561342e9e9;hp=81c65aa3863e53413d7b812ca1c86ad448684097;hpb=ec903c010ecc54ec2acad0bf2cf10e7fbf6a0fa2;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 81c65aa38..c5aeb3c12 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,13 +1,16 @@ -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, RestService } from '@app/core' +import { ComponentPaginationLight, RestExtractor, RestPagination, RestService } from '@app/core' import { objectLineFeedToHtml } from '@app/helpers' import { FeedFormat, ResultList, + ThreadsResultList, VideoComment as VideoCommentServerModel, + VideoCommentAdmin, VideoCommentCreate, VideoCommentThreadTree as VideoCommentThreadTreeServerModel } from '@shared/models' @@ -17,8 +20,9 @@ import { VideoComment } from './video-comment.model' @Injectable() export class VideoCommentService { + static BASE_FEEDS_URL = environment.apiUrl + '/feeds/video-comments.' + private static BASE_VIDEO_URL = environment.apiUrl + '/api/v1/videos/' - private static BASE_FEEDS_URL = environment.apiUrl + '/feeds/video-comments.' constructor ( private authHttp: HttpClient, @@ -48,11 +52,32 @@ export class VideoCommentService { ) } + getAdminVideoComments (options: { + pagination: RestPagination, + sort: SortMeta, + search?: string + }): Observable> { + const { pagination, sort, search } = options + const url = VideoCommentService.BASE_VIDEO_URL + 'comments' + + let params = new HttpParams() + params = this.restService.addRestGetParams(params, pagination, sort) + + if (search) { + params = this.buildParamsFromSearch(search, params) + } + + return this.authHttp.get>(url, { params }) + .pipe( + catchError(res => this.restExtractor.handleError(res)) + ) + } + getVideoCommentThreads (parameters: { videoId: number | string, componentPagination: ComponentPaginationLight, sort: string - }): Observable> { + }): Observable> { const { videoId, componentPagination, sort } = parameters const pagination = this.restService.componentPaginationToRestPagination(componentPagination) @@ -61,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)) @@ -94,6 +119,14 @@ export class VideoCommentService { ) } + deleteVideoComments (comments: { videoId: number | string, commentId: number }[]) { + return from(comments) + .pipe( + concatMap(c => this.deleteVideoComment(c.videoId, c.commentId)), + toArray() + ) + } + getVideoCommentsFeeds (videoUUID?: string) { const feeds = [ { @@ -126,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[] = [] @@ -135,15 +168,35 @@ 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 + + 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 Object.assign(tree, { hasDisplayedChildren }) + } + + private buildParamsFromSearch (search: string, params: HttpParams) { + const filters = this.restService.parseQueryStringFilter(search, { + isLocal: { + prefix: 'local:', + isBoolean: true + }, - tree.comment = new VideoComment(tree.comment) - tree.children.forEach(c => this.extractVideoCommentTree(c)) + searchAccount: { prefix: 'account:' }, + searchVideo: { prefix: 'video:' } + }) - return tree as VideoCommentThreadTree + return this.restService.addObjectParams(params, filters) } }