diff options
Diffstat (limited to 'client/src/app/shared/shared-main/video')
-rw-r--r-- | client/src/app/shared/shared-main/video/video.model.ts | 11 | ||||
-rw-r--r-- | client/src/app/shared/shared-main/video/video.service.ts | 27 |
2 files changed, 27 insertions, 11 deletions
diff --git a/client/src/app/shared/shared-main/video/video.model.ts b/client/src/app/shared/shared-main/video/video.model.ts index 022bb95ad..2e4ab87d7 100644 --- a/client/src/app/shared/shared-main/video/video.model.ts +++ b/client/src/app/shared/shared-main/video/video.model.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { AuthUser } from '@app/core' | 1 | import { AuthUser } from '@app/core' |
2 | import { User } from '@app/core/users/user.model' | 2 | import { User } from '@app/core/users/user.model' |
3 | import { durationToString, getAbsoluteAPIUrl, getAbsoluteEmbedUrl } from '@app/helpers' | 3 | import { durationToString, prepareIcu, getAbsoluteAPIUrl, getAbsoluteEmbedUrl } from '@app/helpers' |
4 | import { Actor } from '@app/shared/shared-main/account/actor.model' | 4 | import { Actor } from '@app/shared/shared-main/account/actor.model' |
5 | import { buildVideoWatchPath } from '@shared/core-utils' | 5 | import { buildVideoWatchPath } from '@shared/core-utils' |
6 | import { peertubeTranslate } from '@shared/core-utils/i18n' | 6 | import { peertubeTranslate } from '@shared/core-utils/i18n' |
@@ -19,6 +19,9 @@ import { | |||
19 | } from '@shared/models' | 19 | } from '@shared/models' |
20 | 20 | ||
21 | export class Video implements VideoServerModel { | 21 | export class Video implements VideoServerModel { |
22 | private static readonly viewsICU = prepareIcu($localize`{views, plural, =0 {No view} =1 {1 view} other {{views} views}}`) | ||
23 | private static readonly viewersICU = prepareIcu($localize`{viewers, plural, =0 {No viewers} =1 {1 viewer} other {{viewers} viewers}}`) | ||
24 | |||
22 | byVideoChannel: string | 25 | byVideoChannel: string |
23 | byAccount: string | 26 | byAccount: string |
24 | 27 | ||
@@ -269,12 +272,10 @@ export class Video implements VideoServerModel { | |||
269 | } | 272 | } |
270 | 273 | ||
271 | getExactNumberOfViews () { | 274 | getExactNumberOfViews () { |
272 | if (this.views < 1000) return '' | ||
273 | |||
274 | if (this.isLive) { | 275 | if (this.isLive) { |
275 | return $localize`${this.views} viewers` | 276 | return Video.viewersICU({ viewers: this.viewers }, $localize`${this.viewers} viewer(s)`) |
276 | } | 277 | } |
277 | 278 | ||
278 | return $localize`${this.views} views` | 279 | return Video.viewsICU({ views: this.views }, $localize`{${this.views} view(s)}`) |
279 | } | 280 | } |
280 | } | 281 | } |
diff --git a/client/src/app/shared/shared-main/video/video.service.ts b/client/src/app/shared/shared-main/video/video.service.ts index 9efa1a24e..4fbc4f7f6 100644 --- a/client/src/app/shared/shared-main/video/video.service.ts +++ b/client/src/app/shared/shared-main/video/video.service.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { SortMeta } from 'primeng/api' | 1 | import { SortMeta } from 'primeng/api' |
2 | import { from, Observable } from 'rxjs' | 2 | import { from, Observable, of } from 'rxjs' |
3 | import { catchError, concatMap, map, switchMap, toArray } from 'rxjs/operators' | 3 | import { catchError, concatMap, map, switchMap, toArray } from 'rxjs/operators' |
4 | import { HttpClient, HttpParams, HttpRequest } from '@angular/common/http' | 4 | import { HttpClient, HttpParams, HttpRequest } from '@angular/common/http' |
5 | import { Injectable } from '@angular/core' | 5 | import { Injectable } from '@angular/core' |
@@ -24,6 +24,7 @@ import { | |||
24 | VideoTranscodingCreate, | 24 | VideoTranscodingCreate, |
25 | VideoUpdate | 25 | VideoUpdate |
26 | } from '@shared/models' | 26 | } from '@shared/models' |
27 | import { VideoSource } from '@shared/models/videos/video-source' | ||
27 | import { environment } from '../../../../environments/environment' | 28 | import { environment } from '../../../../environments/environment' |
28 | import { Account } from '../account/account.model' | 29 | import { Account } from '../account/account.model' |
29 | import { AccountService } from '../account/account.service' | 30 | import { AccountService } from '../account/account.service' |
@@ -323,19 +324,33 @@ export class VideoService { | |||
323 | ) | 324 | ) |
324 | } | 325 | } |
325 | 326 | ||
326 | setVideoLike (id: number) { | 327 | getSource (videoId: number) { |
328 | return this.authHttp | ||
329 | .get<{ source: VideoSource }>(VideoService.BASE_VIDEO_URL + '/' + videoId + '/source') | ||
330 | .pipe( | ||
331 | catchError(err => { | ||
332 | if (err.status === 404) { | ||
333 | return of(undefined) | ||
334 | } | ||
335 | |||
336 | this.restExtractor.handleError(err) | ||
337 | }) | ||
338 | ) | ||
339 | } | ||
340 | |||
341 | setVideoLike (id: string) { | ||
327 | return this.setVideoRate(id, 'like') | 342 | return this.setVideoRate(id, 'like') |
328 | } | 343 | } |
329 | 344 | ||
330 | setVideoDislike (id: number) { | 345 | setVideoDislike (id: string) { |
331 | return this.setVideoRate(id, 'dislike') | 346 | return this.setVideoRate(id, 'dislike') |
332 | } | 347 | } |
333 | 348 | ||
334 | unsetVideoLike (id: number) { | 349 | unsetVideoLike (id: string) { |
335 | return this.setVideoRate(id, 'none') | 350 | return this.setVideoRate(id, 'none') |
336 | } | 351 | } |
337 | 352 | ||
338 | getUserVideoRating (id: number) { | 353 | getUserVideoRating (id: string) { |
339 | const url = UserService.BASE_USERS_URL + 'me/videos/' + id + '/rating' | 354 | const url = UserService.BASE_USERS_URL + 'me/videos/' + id + '/rating' |
340 | 355 | ||
341 | return this.authHttp.get<UserVideoRate>(url) | 356 | return this.authHttp.get<UserVideoRate>(url) |
@@ -451,7 +466,7 @@ export class VideoService { | |||
451 | } | 466 | } |
452 | } | 467 | } |
453 | 468 | ||
454 | private setVideoRate (id: number, rateType: UserVideoRateType) { | 469 | private setVideoRate (id: string, rateType: UserVideoRateType) { |
455 | const url = `${VideoService.BASE_VIDEO_URL}/${id}/rate` | 470 | const url = `${VideoService.BASE_VIDEO_URL}/${id}/rate` |
456 | const body: UserVideoRateUpdate = { | 471 | const body: UserVideoRateUpdate = { |
457 | rating: rateType | 472 | rating: rateType |