X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fvideo-blacklist%2Fvideo-blacklist.service.ts;h=d65da85fe307c0a95b7cc6a7212bc13209f5bec6;hb=366b21f13f75b33f9d64744d7564e7cddf5b1ae8;hp=14c8b5dc06252f54fff7a0647f14af61fd861f7d;hpb=61bbc7277501692d1520a421dff5af5d38ba6cf4;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/shared/video-blacklist/video-blacklist.service.ts b/client/src/app/shared/video-blacklist/video-blacklist.service.ts index 14c8b5dc0..d65da85fe 100644 --- a/client/src/app/shared/video-blacklist/video-blacklist.service.ts +++ b/client/src/app/shared/video-blacklist/video-blacklist.service.ts @@ -1,12 +1,13 @@ +import { catchError, map, concatMap, toArray } from 'rxjs/operators' import { HttpClient, HttpParams } from '@angular/common/http' import { Injectable } from '@angular/core' import { SortMeta } from 'primeng/components/common/sortmeta' -import 'rxjs/add/operator/catch' -import 'rxjs/add/operator/map' -import { Observable } from 'rxjs/Observable' -import { BlacklistedVideo, ResultList } from '../../../../../shared' +import { from as observableFrom, Observable } from 'rxjs' +import { VideoBlacklist, VideoBlacklistType, ResultList } from '../../../../../shared' +import { Video } from '../video/video.model' import { environment } from '../../../environments/environment' import { RestExtractor, RestPagination, RestService } from '../rest' +import { ComponentPagination } from '../rest/component-pagination.model' @Injectable() export class VideoBlacklistService { @@ -18,24 +19,65 @@ export class VideoBlacklistService { private restExtractor: RestExtractor ) {} - listBlacklist (pagination: RestPagination, sort: SortMeta): Observable> { + listBlacklist (pagination: RestPagination, sort: SortMeta, type?: VideoBlacklistType): Observable> { let params = new HttpParams() params = this.restService.addRestGetParams(params, pagination, sort) - return this.authHttp.get>(VideoBlacklistService.BASE_VIDEOS_URL + 'blacklist', { params }) - .map(res => this.restExtractor.convertResultListDateToHuman(res)) - .catch(res => this.restExtractor.handleError(res)) + if (type) { + params = params.set('type', type.toString()) + } + + return this.authHttp.get>(VideoBlacklistService.BASE_VIDEOS_URL + 'blacklist', { params }) + .pipe( + map(res => this.restExtractor.convertResultListDateToHuman(res)), + catchError(res => this.restExtractor.handleError(res)) + ) + } + + getAutoBlacklistedAsVideoList (videoPagination: ComponentPagination): Observable> { + const pagination = this.restService.componentPaginationToRestPagination(videoPagination) + + // prioritize first created since waiting longest + const AUTO_BLACKLIST_SORT = 'createdAt' + + let params = new HttpParams() + params = this.restService.addRestGetParams(params, pagination, AUTO_BLACKLIST_SORT) + + params = params.set('type', VideoBlacklistType.AUTO_BEFORE_PUBLISHED.toString()) + + return this.authHttp.get>(VideoBlacklistService.BASE_VIDEOS_URL + 'blacklist', { params }) + .pipe( + map(res => { + return { + total: res.total, + data: res.data.map(videoBlacklist => new Video(videoBlacklist.video)) + } + }), + catchError(res => this.restExtractor.handleError(res)) + ) } - removeVideoFromBlacklist (videoId: number) { - return this.authHttp.delete(VideoBlacklistService.BASE_VIDEOS_URL + videoId + '/blacklist') - .map(this.restExtractor.extractDataBool) - .catch(res => this.restExtractor.handleError(res)) + removeVideoFromBlacklist (videoIdArgs: number | number[]) { + const videoIds = Array.isArray(videoIdArgs) ? videoIdArgs : [ videoIdArgs ] + + return observableFrom(videoIds) + .pipe( + concatMap(id => this.authHttp.delete(VideoBlacklistService.BASE_VIDEOS_URL + id + '/blacklist')), + toArray(), + catchError(err => this.restExtractor.handleError(err)) + ) } - blacklistVideo (videoId: number) { - return this.authHttp.post(VideoBlacklistService.BASE_VIDEOS_URL + videoId + '/blacklist', {}) - .map(this.restExtractor.extractDataBool) - .catch(res => this.restExtractor.handleError(res)) + blacklistVideo (videoId: number, reason: string, unfederate: boolean) { + const body = { + unfederate, + reason + } + + return this.authHttp.post(VideoBlacklistService.BASE_VIDEOS_URL + videoId + '/blacklist', body) + .pipe( + map(this.restExtractor.extractDataBool), + catchError(res => this.restExtractor.handleError(res)) + ) } }