]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/videos/+video-watch/comment/video-comment.service.ts
Automatically jump to the highlighted thread
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-watch / comment / video-comment.service.ts
index 14d32b1aa6f1732e2e17a59230d385c1aab8800c..5b9a991a031552f3d50f56c64f8a36ac07ae280d 100644 (file)
@@ -1,18 +1,18 @@
+import { catchError, map } from 'rxjs/operators'
 import { HttpClient, HttpParams } from '@angular/common/http'
 import { Injectable } from '@angular/core'
-import 'rxjs/add/operator/catch'
-import 'rxjs/add/operator/map'
-import { immutableAssign, lineFeedToHtml } from '@app/shared/misc/utils'
-import { Observable } from 'rxjs/Observable'
+import { lineFeedToHtml } from '@app/shared/misc/utils'
+import { Observable } from 'rxjs'
 import { ResultList } from '../../../../../../shared/models'
 import {
-  VideoComment as VideoCommentServerModel, VideoCommentCreate,
+  VideoComment as VideoCommentServerModel,
+  VideoCommentCreate,
   VideoCommentThreadTree
 } from '../../../../../../shared/models/videos/video-comment.model'
 import { environment } from '../../../../environments/environment'
 import { RestExtractor, RestService } from '../../../shared/rest'
 import { ComponentPagination } from '../../../shared/rest/component-pagination.model'
-import { SortField } from '../../../shared/video/sort-field.type'
+import { VideoSortField } from '../../../shared/video/sort-field.type'
 import { VideoComment } from './video-comment.model'
 
 @Injectable()
@@ -30,8 +30,10 @@ export class VideoCommentService {
     const normalizedComment = lineFeedToHtml(comment, 'text')
 
     return this.authHttp.post(url, normalizedComment)
-      .map(data => this.extractVideoComment(data['comment']))
-      .catch(this.restExtractor.handleError)
+               .pipe(
+      map(data => this.extractVideoComment(data['comment'])),
+      catchError(this.restExtractor.handleError)
+               )
   }
 
   addCommentReply (videoId: number | string, inReplyToCommentId: number, comment: VideoCommentCreate) {
@@ -39,14 +41,16 @@ export class VideoCommentService {
     const normalizedComment = lineFeedToHtml(comment, 'text')
 
     return this.authHttp.post(url, normalizedComment)
-      .map(data => this.extractVideoComment(data['comment']))
-      .catch(this.restExtractor.handleError)
+               .pipe(
+                 map(data => this.extractVideoComment(data[ 'comment' ])),
+                 catchError(this.restExtractor.handleError)
+               )
   }
 
   getVideoCommentThreads (
     videoId: number | string,
     componentPagination: ComponentPagination,
-    sort: SortField
+    sort: VideoSortField
   ): Observable<{ comments: VideoComment[], totalComments: number}> {
     const pagination = this.restService.componentPaginationToRestPagination(componentPagination)
 
@@ -55,27 +59,33 @@ export class VideoCommentService {
 
     const url = VideoCommentService.BASE_VIDEO_URL + videoId + '/comment-threads'
     return this.authHttp
-      .get(url, { params })
-      .map(this.extractVideoComments)
-      .catch((res) => this.restExtractor.handleError(res))
+               .get(url, { params })
+               .pipe(
+                 map(this.extractVideoComments),
+                 catchError((res) => this.restExtractor.handleError(res))
+               )
   }
 
   getVideoThreadComments (videoId: number | string, threadId: number): Observable<VideoCommentThreadTree> {
     const url = `${VideoCommentService.BASE_VIDEO_URL + videoId}/comment-threads/${threadId}`
 
     return this.authHttp
-      .get(url)
-      .map(tree => this.extractVideoCommentTree(tree as VideoCommentThreadTree))
-      .catch((res) => this.restExtractor.handleError(res))
+               .get(url)
+               .pipe(
+                 map(tree => this.extractVideoCommentTree(tree as VideoCommentThreadTree)),
+                 catchError((res) => this.restExtractor.handleError(res))
+               )
   }
 
   deleteVideoComment (videoId: number | string, commentId: number) {
     const url = `${VideoCommentService.BASE_VIDEO_URL + videoId}/comments/${commentId}`
 
     return this.authHttp
-      .delete(url)
-      .map(this.restExtractor.extractDataBool)
-      .catch((res) => this.restExtractor.handleError(res))
+               .delete(url)
+               .pipe(
+                 map(this.restExtractor.extractDataBool),
+                 catchError((res) => this.restExtractor.handleError(res))
+               )
   }
 
   private extractVideoComment (videoComment: VideoCommentServerModel) {
@@ -85,7 +95,7 @@ export class VideoCommentService {
   private extractVideoComments (result: ResultList<VideoCommentServerModel>) {
     const videoCommentsJson = result.data
     const totalComments = result.total
-    const comments = []
+    const comments: VideoComment[] = []
 
     for (const videoCommentJson of videoCommentsJson) {
       comments.push(new VideoComment(videoCommentJson))