X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fvideo-caption%2Fvideo-caption.service.ts;h=6bfe6743573453af7ff73cce3f9340e858b56054;hb=366b21f13f75b33f9d64744d7564e7cddf5b1ae8;hp=e835981dd2d912c3d66f5a52c5dfc8ce0586fdaf;hpb=0f7fedc39857ebc0eb29182c1588a92b9adfb75a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/shared/video-caption/video-caption.service.ts b/client/src/app/shared/video-caption/video-caption.service.ts index e835981dd..6bfe67435 100644 --- a/client/src/app/shared/video-caption/video-caption.service.ts +++ b/client/src/app/shared/video-caption/video-caption.service.ts @@ -1,24 +1,43 @@ -import { catchError, map } from 'rxjs/operators' +import { catchError, map, switchMap } from 'rxjs/operators' import { HttpClient } from '@angular/common/http' import { Injectable } from '@angular/core' -import { forkJoin, Observable, of } from 'rxjs' -import { ResultList } from '../../../../../shared' -import { RestExtractor, RestService } from '../rest' -import { VideoCaption } from '../../../../../shared/models/videos/video-caption.model' +import { Observable, of } from 'rxjs' +import { peertubeTranslate, ResultList } from '../../../../../shared' +import { RestExtractor } from '../rest' import { VideoService } from '@app/shared/video/video.service' -import { objectToFormData } from '@app/shared/misc/utils' +import { objectToFormData, sortBy } from '@app/shared/misc/utils' import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model' +import { VideoCaption } from '../../../../../shared/models/videos/caption/video-caption.model' +import { ServerService } from '@app/core' @Injectable() export class VideoCaptionService { constructor ( private authHttp: HttpClient, - private restService: RestService, + private serverService: ServerService, private restExtractor: RestExtractor ) {} listCaptions (videoId: number | string): Observable> { return this.authHttp.get>(VideoService.BASE_VIDEO_URL + videoId + '/captions') + .pipe( + switchMap(captionsResult => { + return this.serverService.getServerLocale() + .pipe(map(translations => ({ captionsResult, translations }))) + }), + map(({ captionsResult, translations }) => { + for (const c of captionsResult.data) { + c.language.label = peertubeTranslate(c.language.label, translations) + } + + return captionsResult + }), + map(captionsResult => { + sortBy(captionsResult.data, 'language', 'label') + + return captionsResult + }) + ) .pipe(catchError(res => this.restExtractor.handleError(res))) } @@ -42,22 +61,16 @@ export class VideoCaptionService { } updateCaptions (videoId: number | string, videoCaptions: VideoCaptionEdit[]) { - const observables: Observable[] = [] + let obs = of(true) for (const videoCaption of videoCaptions) { if (videoCaption.action === 'CREATE') { - observables.push( - this.addCaption(videoId, videoCaption.language.id, videoCaption.captionfile) - ) + obs = obs.pipe(switchMap(() => this.addCaption(videoId, videoCaption.language.id, videoCaption.captionfile))) } else if (videoCaption.action === 'REMOVE') { - observables.push( - this.removeCaption(videoId, videoCaption.language.id) - ) + obs = obs.pipe(switchMap(() => this.removeCaption(videoId, videoCaption.language.id))) } } - if (observables.length === 0) return of(true) - - return forkJoin(observables) + return obs } }