aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-video-comment/video-comment.service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/shared-video-comment/video-comment.service.ts')
-rw-r--r--client/src/app/shared/shared-video-comment/video-comment.service.ts48
1 files changed, 46 insertions, 2 deletions
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..1ab996a76 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
@@ -2,23 +2,26 @@ import { Observable } from 'rxjs'
2import { catchError, map } from 'rxjs/operators' 2import { catchError, map } from 'rxjs/operators'
3import { HttpClient, HttpParams } from '@angular/common/http' 3import { HttpClient, HttpParams } from '@angular/common/http'
4import { Injectable } from '@angular/core' 4import { Injectable } from '@angular/core'
5import { ComponentPaginationLight, RestExtractor, RestService } from '@app/core' 5import { ComponentPaginationLight, RestExtractor, RestPagination, RestService } from '@app/core'
6import { objectLineFeedToHtml } from '@app/helpers' 6import { objectLineFeedToHtml } from '@app/helpers'
7import { 7import {
8 FeedFormat, 8 FeedFormat,
9 ResultList, 9 ResultList,
10 VideoComment as VideoCommentServerModel, 10 VideoComment as VideoCommentServerModel,
11 VideoCommentAdmin,
11 VideoCommentCreate, 12 VideoCommentCreate,
12 VideoCommentThreadTree as VideoCommentThreadTreeServerModel 13 VideoCommentThreadTree as VideoCommentThreadTreeServerModel
13} from '@shared/models' 14} from '@shared/models'
14import { environment } from '../../../environments/environment' 15import { environment } from '../../../environments/environment'
15import { VideoCommentThreadTree } from './video-comment-thread-tree.model' 16import { VideoCommentThreadTree } from './video-comment-thread-tree.model'
16import { VideoComment } from './video-comment.model' 17import { VideoComment } from './video-comment.model'
18import { SortMeta } from 'primeng/api'
17 19
18@Injectable() 20@Injectable()
19export class VideoCommentService { 21export class VideoCommentService {
22 static BASE_FEEDS_URL = environment.apiUrl + '/feeds/video-comments.'
23
20 private static BASE_VIDEO_URL = environment.apiUrl + '/api/v1/videos/' 24 private static BASE_VIDEO_URL = environment.apiUrl + '/api/v1/videos/'
21 private static BASE_FEEDS_URL = environment.apiUrl + '/feeds/video-comments.'
22 25
23 constructor ( 26 constructor (
24 private authHttp: HttpClient, 27 private authHttp: HttpClient,
@@ -48,6 +51,27 @@ export class VideoCommentService {
48 ) 51 )
49 } 52 }
50 53
54 getAdminVideoComments (options: {
55 pagination: RestPagination,
56 sort: SortMeta,
57 search?: string
58 }): Observable<ResultList<VideoCommentAdmin>> {
59 const { pagination, sort, search } = options
60 const url = VideoCommentService.BASE_VIDEO_URL + 'comments'
61
62 let params = new HttpParams()
63 params = this.restService.addRestGetParams(params, pagination, sort)
64
65 if (search) {
66 params = this.buildParamsFromSearch(search, params)
67 }
68
69 return this.authHttp.get<ResultList<VideoCommentAdmin>>(url, { params })
70 .pipe(
71 catchError(res => this.restExtractor.handleError(res))
72 )
73 }
74
51 getVideoCommentThreads (parameters: { 75 getVideoCommentThreads (parameters: {
52 videoId: number | string, 76 videoId: number | string,
53 componentPagination: ComponentPaginationLight, 77 componentPagination: ComponentPaginationLight,
@@ -146,4 +170,24 @@ export class VideoCommentService {
146 170
147 return tree as VideoCommentThreadTree 171 return tree as VideoCommentThreadTree
148 } 172 }
173
174 private buildParamsFromSearch (search: string, params: HttpParams) {
175 const filters = this.restService.parseQueryStringFilter(search, {
176 isLocal: {
177 prefix: 'local:',
178 isBoolean: true,
179 handler: v => {
180 if (v === 'true') return v
181 if (v === 'false') return v
182
183 return undefined
184 }
185 },
186
187 searchAccount: { prefix: 'account:' },
188 searchVideo: { prefix: 'video:' }
189 })
190
191 return this.restService.addObjectParams(params, filters)
192 }
149} 193}