X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fvideos%2F%2Bvideo-watch%2Fcomment%2Fvideo-comment.service.ts;h=921447d5be264e3369273e9d6cd03b94464ef3c7;hb=c199c427d4ae586339822320f20f512a7a19dc3f;hp=5b9a991a031552f3d50f56c64f8a36ac07ae280d;hpb=db400f447a9f7aae1c56fa25396e93069744483f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/videos/+video-watch/comment/video-comment.service.ts b/client/src/app/videos/+video-watch/comment/video-comment.service.ts index 5b9a991a0..921447d5b 100644 --- a/client/src/app/videos/+video-watch/comment/video-comment.service.ts +++ b/client/src/app/videos/+video-watch/comment/video-comment.service.ts @@ -3,7 +3,7 @@ import { HttpClient, HttpParams } from '@angular/common/http' import { Injectable } from '@angular/core' import { lineFeedToHtml } from '@app/shared/misc/utils' import { Observable } from 'rxjs' -import { ResultList } from '../../../../../../shared/models' +import { ResultList, FeedFormat } from '../../../../../../shared/models' import { VideoComment as VideoCommentServerModel, VideoCommentCreate, @@ -18,6 +18,7 @@ import { VideoComment } from './video-comment.model' @Injectable() export class VideoCommentService { private static BASE_VIDEO_URL = environment.apiUrl + '/api/v1/videos/' + private static BASE_FEEDS_URL = environment.apiUrl + '/feeds/video-comments.' constructor ( private authHttp: HttpClient, @@ -29,10 +30,10 @@ export class VideoCommentService { const url = VideoCommentService.BASE_VIDEO_URL + videoId + '/comment-threads' const normalizedComment = lineFeedToHtml(comment, 'text') - return this.authHttp.post(url, normalizedComment) + return this.authHttp.post<{ comment: VideoCommentServerModel }>(url, normalizedComment) .pipe( - map(data => this.extractVideoComment(data['comment'])), - catchError(this.restExtractor.handleError) + map(data => this.extractVideoComment(data.comment)), + catchError(err => this.restExtractor.handleError(err)) ) } @@ -40,10 +41,10 @@ export class VideoCommentService { const url = VideoCommentService.BASE_VIDEO_URL + videoId + '/comments/' + inReplyToCommentId const normalizedComment = lineFeedToHtml(comment, 'text') - return this.authHttp.post(url, normalizedComment) + return this.authHttp.post<{ comment: VideoCommentServerModel }>(url, normalizedComment) .pipe( - map(data => this.extractVideoComment(data[ 'comment' ])), - catchError(this.restExtractor.handleError) + map(data => this.extractVideoComment(data.comment)), + catchError(err => this.restExtractor.handleError(err)) ) } @@ -62,7 +63,7 @@ export class VideoCommentService { .get(url, { params }) .pipe( map(this.extractVideoComments), - catchError((res) => this.restExtractor.handleError(res)) + catchError(err => this.restExtractor.handleError(err)) ) } @@ -73,7 +74,7 @@ export class VideoCommentService { .get(url) .pipe( map(tree => this.extractVideoCommentTree(tree as VideoCommentThreadTree)), - catchError((res) => this.restExtractor.handleError(res)) + catchError(err => this.restExtractor.handleError(err)) ) } @@ -84,10 +85,38 @@ export class VideoCommentService { .delete(url) .pipe( map(this.restExtractor.extractDataBool), - catchError((res) => this.restExtractor.handleError(res)) + catchError(err => this.restExtractor.handleError(err)) ) } + getVideoCommentsFeeds (videoUUID?: string) { + const feeds = [ + { + format: FeedFormat.RSS, + label: 'rss 2.0', + url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.RSS.toLowerCase() + }, + { + format: FeedFormat.ATOM, + label: 'atom 1.0', + url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.ATOM.toLowerCase() + }, + { + format: FeedFormat.JSON, + label: 'json 1.0', + url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.JSON.toLowerCase() + } + ] + + if (videoUUID !== undefined) { + for (const feed of feeds) { + feed.url += '?videoId=' + videoUUID + } + } + + return feeds + } + private extractVideoComment (videoComment: VideoCommentServerModel) { return new VideoComment(videoComment) }