aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/video-watch
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-04-04 21:37:03 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-04-04 21:37:03 +0200
commit92fb909c9b4a92a00b0d0da7629e6fb003de281b (patch)
tree8119c6720d5dec0474983501843f1e699fde150a /client/src/app/videos/video-watch
parent1d49e1e27d63db1dfc9a7fd28c9902f488831a89 (diff)
downloadPeerTube-92fb909c9b4a92a00b0d0da7629e6fb003de281b.tar.gz
PeerTube-92fb909c9b4a92a00b0d0da7629e6fb003de281b.tar.zst
PeerTube-92fb909c9b4a92a00b0d0da7629e6fb003de281b.zip
Client: Handle NSFW video
Diffstat (limited to 'client/src/app/videos/video-watch')
-rw-r--r--client/src/app/videos/video-watch/video-watch.component.ts44
-rw-r--r--client/src/app/videos/video-watch/webtorrent.service.ts4
2 files changed, 36 insertions, 12 deletions
diff --git a/client/src/app/videos/video-watch/video-watch.component.ts b/client/src/app/videos/video-watch/video-watch.component.ts
index 5678f6df8..37ed70a99 100644
--- a/client/src/app/videos/video-watch/video-watch.component.ts
+++ b/client/src/app/videos/video-watch/video-watch.component.ts
@@ -1,12 +1,13 @@
1import { Component, ElementRef, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core'; 1import { Component, ElementRef, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core';
2import { ActivatedRoute } from '@angular/router'; 2import { ActivatedRoute, Router } from '@angular/router';
3import { Observable } from 'rxjs/Observable';
3import { Subscription } from 'rxjs/Subscription'; 4import { Subscription } from 'rxjs/Subscription';
4 5
5import * as videojs from 'video.js'; 6import * as videojs from 'video.js';
6import { MetaService } from '@nglibs/meta'; 7import { MetaService } from '@nglibs/meta';
7import { NotificationsService } from 'angular2-notifications'; 8import { NotificationsService } from 'angular2-notifications';
8 9
9import { AuthService } from '../../core'; 10import { AuthService, ConfirmService } from '../../core';
10import { VideoMagnetComponent } from './video-magnet.component'; 11import { VideoMagnetComponent } from './video-magnet.component';
11import { VideoShareComponent } from './video-share.component'; 12import { VideoShareComponent } from './video-share.component';
12import { VideoReportComponent } from './video-report.component'; 13import { VideoReportComponent } from './video-report.component';
@@ -47,7 +48,9 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
47 private elementRef: ElementRef, 48 private elementRef: ElementRef,
48 private ngZone: NgZone, 49 private ngZone: NgZone,
49 private route: ActivatedRoute, 50 private route: ActivatedRoute,
51 private router: Router,
50 private videoService: VideoService, 52 private videoService: VideoService,
53 private confirmService: ConfirmService,
51 private metaService: MetaService, 54 private metaService: MetaService,
52 private webTorrentService: WebTorrentService, 55 private webTorrentService: WebTorrentService,
53 private authService: AuthService, 56 private authService: AuthService,
@@ -58,15 +61,9 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
58 this.paramsSub = this.route.params.subscribe(routeParams => { 61 this.paramsSub = this.route.params.subscribe(routeParams => {
59 let id = routeParams['id']; 62 let id = routeParams['id'];
60 this.videoService.getVideo(id).subscribe( 63 this.videoService.getVideo(id).subscribe(
61 video => { 64 video => this.onVideoFetched(video),
62 this.video = video; 65
63 this.setOpenGraphTags(); 66 error => this.videoNotFound = true
64 this.loadVideo();
65 this.checkUserRating();
66 },
67 error => {
68 this.videoNotFound = true;
69 }
70 ); 67 );
71 }); 68 });
72 69
@@ -92,7 +89,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
92 window.clearInterval(this.torrentInfosInterval); 89 window.clearInterval(this.torrentInfosInterval);
93 window.clearTimeout(this.errorTimer); 90 window.clearTimeout(this.errorTimer);
94 91
95 if (this.video !== null) { 92 if (this.video !== null && this.webTorrentService.has(this.video.magnetUri)) {
96 this.webTorrentService.remove(this.video.magnetUri); 93 this.webTorrentService.remove(this.video.magnetUri);
97 } 94 }
98 95
@@ -206,6 +203,29 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
206 ); 203 );
207 } 204 }
208 205
206 private onVideoFetched(video: Video) {
207 this.video = video;
208
209 let observable;
210 if (this.video.isVideoNSFWForUser(this.authService.getUser())) {
211 observable = this.confirmService.confirm('This video is not safe for work. Are you sure you want to watch it?', 'NSFW');
212 } else {
213 observable = Observable.of(true);
214 }
215
216 observable.subscribe(
217 res => {
218 if (res === false) {
219 return this.router.navigate([ '/videos/list' ]);
220 }
221
222 this.setOpenGraphTags();
223 this.loadVideo();
224 this.checkUserRating();
225 }
226 );
227 }
228
209 private updateVideoRating(oldRating: RateType, newRating: RateType) { 229 private updateVideoRating(oldRating: RateType, newRating: RateType) {
210 let likesToIncrement = 0; 230 let likesToIncrement = 0;
211 let dislikesToIncrement = 0; 231 let dislikesToIncrement = 0;
diff --git a/client/src/app/videos/video-watch/webtorrent.service.ts b/client/src/app/videos/video-watch/webtorrent.service.ts
index 0192167ee..630a5c469 100644
--- a/client/src/app/videos/video-watch/webtorrent.service.ts
+++ b/client/src/app/videos/video-watch/webtorrent.service.ts
@@ -26,4 +26,8 @@ export class WebTorrentService {
26 remove(magnetUri: string) { 26 remove(magnetUri: string) {
27 return this.client.remove(magnetUri); 27 return this.client.remove(magnetUri);
28 } 28 }
29
30 has(magnetUri: string) {
31 return this.client.get(magnetUri) !== null;
32 }
29} 33}