aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+videos/+video-watch/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-12-15 15:58:10 +0100
committerChocobozzz <me@florianbigard.com>2021-12-16 10:08:55 +0100
commita9bfa85d2cdf13670aaced740da5b493fbeddfce (patch)
tree3781c9218d4cc7786b6589365c0efbed2151703d /client/src/app/+videos/+video-watch/shared
parentc77fdc605b3ccc1ab6890f889d8200fbe9372949 (diff)
downloadPeerTube-a9bfa85d2cdf13670aaced740da5b493fbeddfce.tar.gz
PeerTube-a9bfa85d2cdf13670aaced740da5b493fbeddfce.tar.zst
PeerTube-a9bfa85d2cdf13670aaced740da5b493fbeddfce.zip
Add ability for admins to set default p2p policy
Diffstat (limited to 'client/src/app/+videos/+video-watch/shared')
-rw-r--r--client/src/app/+videos/+video-watch/shared/information/privacy-concerns.component.ts26
-rw-r--r--client/src/app/+videos/+video-watch/shared/playlist/video-watch-playlist.component.ts39
-rw-r--r--client/src/app/+videos/+video-watch/shared/recommendations/recommended-videos.component.ts27
3 files changed, 30 insertions, 62 deletions
diff --git a/client/src/app/+videos/+video-watch/shared/information/privacy-concerns.component.ts b/client/src/app/+videos/+video-watch/shared/information/privacy-concerns.component.ts
index bbc81d46d..24030df3e 100644
--- a/client/src/app/+videos/+video-watch/shared/information/privacy-concerns.component.ts
+++ b/client/src/app/+videos/+video-watch/shared/information/privacy-concerns.component.ts
@@ -1,9 +1,8 @@
1import { Component, Input, OnInit } from '@angular/core' 1import { Component, Input, OnInit } from '@angular/core'
2import { ServerService } from '@app/core' 2import { ServerService, User, UserService } from '@app/core'
3import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' 3import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
4import { HTMLServerConfig, Video } from '@shared/models' 4import { HTMLServerConfig, Video } from '@shared/models'
5import { getStoredP2PEnabled } from '../../../../../assets/player/peertube-player-local-storage' 5import { isP2PEnabled } from '../../../../../assets/player/utils'
6import { isWebRTCDisabled } from '../../../../../assets/player/utils'
7 6
8@Component({ 7@Component({
9 selector: 'my-privacy-concerns', 8 selector: 'my-privacy-concerns',
@@ -15,33 +14,32 @@ export class PrivacyConcernsComponent implements OnInit {
15 14
16 @Input() video: Video 15 @Input() video: Video
17 16
18 display = true 17 display = false
19 18
20 private serverConfig: HTMLServerConfig 19 private serverConfig: HTMLServerConfig
21 20
22 constructor ( 21 constructor (
23 private serverService: ServerService 22 private serverService: ServerService,
23 private userService: UserService
24 ) { } 24 ) { }
25 25
26 ngOnInit () { 26 ngOnInit () {
27 this.serverConfig = this.serverService.getHTMLConfig() 27 this.serverConfig = this.serverService.getHTMLConfig()
28 28
29 if (isWebRTCDisabled() || this.isTrackerDisabled() || this.isP2PDisabled() || this.alreadyAccepted()) { 29 this.userService.getAnonymousOrLoggedUser()
30 this.display = false 30 .subscribe(user => this.updateDisplay(user))
31 }
32 } 31 }
33 32
34 acceptedPrivacyConcern () { 33 acceptedPrivacyConcern () {
35 peertubeLocalStorage.setItem(PrivacyConcernsComponent.LOCAL_STORAGE_PRIVACY_CONCERN_KEY, 'true') 34 peertubeLocalStorage.setItem(PrivacyConcernsComponent.LOCAL_STORAGE_PRIVACY_CONCERN_KEY, 'true')
36 this.display = false
37 }
38 35
39 private isTrackerDisabled () { 36 this.display = false
40 return this.video.isLocal && this.serverConfig.tracker.enabled === false
41 } 37 }
42 38
43 private isP2PDisabled () { 39 private updateDisplay (user: User) {
44 return getStoredP2PEnabled() === false 40 if (isP2PEnabled(this.video, this.serverConfig, user.p2pEnabled) && !this.alreadyAccepted()) {
41 this.display = true
42 }
45 } 43 }
46 44
47 private alreadyAccepted () { 45 private alreadyAccepted () {
diff --git a/client/src/app/+videos/+video-watch/shared/playlist/video-watch-playlist.component.ts b/client/src/app/+videos/+video-watch/shared/playlist/video-watch-playlist.component.ts
index b2863fed6..fbf9a3687 100644
--- a/client/src/app/+videos/+video-watch/shared/playlist/video-watch-playlist.component.ts
+++ b/client/src/app/+videos/+video-watch/shared/playlist/video-watch-playlist.component.ts
@@ -1,16 +1,9 @@
1import { Component, EventEmitter, Input, Output } from '@angular/core' 1import { Component, EventEmitter, Input, Output } from '@angular/core'
2import { Router } from '@angular/router' 2import { Router } from '@angular/router'
3import { 3import { AuthService, ComponentPagination, HooksService, Notifier, SessionStorageService, UserService } from '@app/core'
4 AuthService,
5 ComponentPagination,
6 HooksService,
7 LocalStorageService,
8 Notifier,
9 SessionStorageService,
10 UserService
11} from '@app/core'
12import { VideoPlaylist, VideoPlaylistElement, VideoPlaylistService } from '@app/shared/shared-video-playlist' 4import { VideoPlaylist, VideoPlaylistElement, VideoPlaylistService } from '@app/shared/shared-video-playlist'
13import { peertubeLocalStorage, peertubeSessionStorage } from '@root-helpers/peertube-web-storage' 5import { peertubeSessionStorage } from '@root-helpers/peertube-web-storage'
6import { getBoolOrDefault } from '@root-helpers/local-storage-utils'
14import { VideoPlaylistPrivacy } from '@shared/models' 7import { VideoPlaylistPrivacy } from '@shared/models'
15 8
16@Component({ 9@Component({
@@ -19,8 +12,7 @@ import { VideoPlaylistPrivacy } from '@shared/models'
19 styleUrls: [ './video-watch-playlist.component.scss' ] 12 styleUrls: [ './video-watch-playlist.component.scss' ]
20}) 13})
21export class VideoWatchPlaylistComponent { 14export class VideoWatchPlaylistComponent {
22 static LOCAL_STORAGE_AUTO_PLAY_NEXT_VIDEO_PLAYLIST = 'auto_play_video_playlist' 15 static SESSION_STORAGE_LOOP_PLAYLIST = 'loop_playlist'
23 static SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO_PLAYLIST = 'loop_playlist'
24 16
25 @Input() playlist: VideoPlaylist 17 @Input() playlist: VideoPlaylist
26 18
@@ -47,19 +39,15 @@ export class VideoWatchPlaylistComponent {
47 private auth: AuthService, 39 private auth: AuthService,
48 private notifier: Notifier, 40 private notifier: Notifier,
49 private videoPlaylist: VideoPlaylistService, 41 private videoPlaylist: VideoPlaylistService,
50 private localStorageService: LocalStorageService,
51 private sessionStorage: SessionStorageService, 42 private sessionStorage: SessionStorageService,
52 private router: Router 43 private router: Router
53 ) { 44 ) {
54 // defaults to true 45 this.userService.getAnonymousOrLoggedUser()
55 this.autoPlayNextVideoPlaylist = this.auth.isLoggedIn() 46 .subscribe(user => this.autoPlayNextVideoPlaylist = user.autoPlayNextVideoPlaylist)
56 ? this.auth.getUser().autoPlayNextVideoPlaylist
57 : this.localStorageService.getItem(VideoWatchPlaylistComponent.LOCAL_STORAGE_AUTO_PLAY_NEXT_VIDEO_PLAYLIST) !== 'false'
58 47
59 this.setAutoPlayNextVideoPlaylistSwitchText() 48 this.setAutoPlayNextVideoPlaylistSwitchText()
60 49
61 // defaults to false 50 this.loopPlaylist = getBoolOrDefault(this.sessionStorage.getItem(VideoWatchPlaylistComponent.SESSION_STORAGE_LOOP_PLAYLIST), false)
62 this.loopPlaylist = this.sessionStorage.getItem(VideoWatchPlaylistComponent.SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO_PLAYLIST) === 'true'
63 this.setLoopPlaylistSwitchText() 51 this.setLoopPlaylistSwitchText()
64 } 52 }
65 53
@@ -201,16 +189,9 @@ export class VideoWatchPlaylistComponent {
201 this.autoPlayNextVideoPlaylist = !this.autoPlayNextVideoPlaylist 189 this.autoPlayNextVideoPlaylist = !this.autoPlayNextVideoPlaylist
202 this.setAutoPlayNextVideoPlaylistSwitchText() 190 this.setAutoPlayNextVideoPlaylistSwitchText()
203 191
204 peertubeLocalStorage.setItem( 192 const details = { autoPlayNextVideoPlaylist: this.autoPlayNextVideoPlaylist }
205 VideoWatchPlaylistComponent.LOCAL_STORAGE_AUTO_PLAY_NEXT_VIDEO_PLAYLIST,
206 this.autoPlayNextVideoPlaylist.toString()
207 )
208 193
209 if (this.auth.isLoggedIn()) { 194 if (this.auth.isLoggedIn()) {
210 const details = {
211 autoPlayNextVideoPlaylist: this.autoPlayNextVideoPlaylist
212 }
213
214 this.userService.updateMyProfile(details) 195 this.userService.updateMyProfile(details)
215 .subscribe({ 196 .subscribe({
216 next: () => { 197 next: () => {
@@ -219,6 +200,8 @@ export class VideoWatchPlaylistComponent {
219 200
220 error: err => this.notifier.error(err.message) 201 error: err => this.notifier.error(err.message)
221 }) 202 })
203 } else {
204 this.userService.updateMyAnonymousProfile(details)
222 } 205 }
223 } 206 }
224 207
@@ -227,7 +210,7 @@ export class VideoWatchPlaylistComponent {
227 this.setLoopPlaylistSwitchText() 210 this.setLoopPlaylistSwitchText()
228 211
229 peertubeSessionStorage.setItem( 212 peertubeSessionStorage.setItem(
230 VideoWatchPlaylistComponent.SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO_PLAYLIST, 213 VideoWatchPlaylistComponent.SESSION_STORAGE_LOOP_PLAYLIST,
231 this.loopPlaylist.toString() 214 this.loopPlaylist.toString()
232 ) 215 )
233 } 216 }
diff --git a/client/src/app/+videos/+video-watch/shared/recommendations/recommended-videos.component.ts b/client/src/app/+videos/+video-watch/shared/recommendations/recommended-videos.component.ts
index dfc296d15..97f742499 100644
--- a/client/src/app/+videos/+video-watch/shared/recommendations/recommended-videos.component.ts
+++ b/client/src/app/+videos/+video-watch/shared/recommendations/recommended-videos.component.ts
@@ -1,10 +1,9 @@
1import { Observable } from 'rxjs' 1import { Observable } from 'rxjs'
2import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core' 2import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core'
3import { AuthService, Notifier, SessionStorageService, User, UserService } from '@app/core' 3import { AuthService, Notifier, User, UserService } from '@app/core'
4import { Video } from '@app/shared/shared-main' 4import { Video } from '@app/shared/shared-main'
5import { MiniatureDisplayOptions } from '@app/shared/shared-video-miniature' 5import { MiniatureDisplayOptions } from '@app/shared/shared-video-miniature'
6import { VideoPlaylist } from '@app/shared/shared-video-playlist' 6import { VideoPlaylist } from '@app/shared/shared-video-playlist'
7import { UserLocalStorageKeys } from '@root-helpers/users'
8import { RecommendationInfo } from './recommendation-info.model' 7import { RecommendationInfo } from './recommendation-info.model'
9import { RecommendedVideosStore } from './recommended-videos.store' 8import { RecommendedVideosStore } from './recommended-videos.store'
10 9
@@ -39,24 +38,14 @@ export class RecommendedVideosComponent implements OnInit, OnChanges {
39 private userService: UserService, 38 private userService: UserService,
40 private authService: AuthService, 39 private authService: AuthService,
41 private notifier: Notifier, 40 private notifier: Notifier,
42 private store: RecommendedVideosStore, 41 private store: RecommendedVideosStore
43 private sessionStorageService: SessionStorageService
44 ) { 42 ) {
45 this.videos$ = this.store.recommendations$ 43 this.videos$ = this.store.recommendations$
46 this.hasVideos$ = this.store.hasRecommendations$ 44 this.hasVideos$ = this.store.hasRecommendations$
47 this.videos$.subscribe(videos => this.gotRecommendations.emit(videos)) 45 this.videos$.subscribe(videos => this.gotRecommendations.emit(videos))
48 46
49 if (this.authService.isLoggedIn()) { 47 this.userService.getAnonymousOrLoggedUser()
50 this.autoPlayNextVideo = this.authService.getUser().autoPlayNextVideo 48 .subscribe(user => this.autoPlayNextVideo = user.autoPlayNextVideo)
51 } else {
52 this.autoPlayNextVideo = this.sessionStorageService.getItem(UserLocalStorageKeys.SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO) === 'true'
53
54 this.sessionStorageService.watch([ UserLocalStorageKeys.SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO ]).subscribe(
55 () => {
56 this.autoPlayNextVideo = this.sessionStorageService.getItem(UserLocalStorageKeys.SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO) === 'true'
57 }
58 )
59 }
60 49
61 this.autoPlayNextVideoTooltip = $localize`When active, the next video is automatically played after the current one.` 50 this.autoPlayNextVideoTooltip = $localize`When active, the next video is automatically played after the current one.`
62 } 51 }
@@ -77,13 +66,9 @@ export class RecommendedVideosComponent implements OnInit, OnChanges {
77 } 66 }
78 67
79 switchAutoPlayNextVideo () { 68 switchAutoPlayNextVideo () {
80 this.sessionStorageService.setItem(UserLocalStorageKeys.SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO, this.autoPlayNextVideo.toString()) 69 const details = { autoPlayNextVideo: this.autoPlayNextVideo }
81 70
82 if (this.authService.isLoggedIn()) { 71 if (this.authService.isLoggedIn()) {
83 const details = {
84 autoPlayNextVideo: this.autoPlayNextVideo
85 }
86
87 this.userService.updateMyProfile(details) 72 this.userService.updateMyProfile(details)
88 .subscribe({ 73 .subscribe({
89 next: () => { 74 next: () => {
@@ -92,6 +77,8 @@ export class RecommendedVideosComponent implements OnInit, OnChanges {
92 77
93 error: err => this.notifier.error(err.message) 78 error: err => this.notifier.error(err.message)
94 }) 79 })
80 } else {
81 this.userService.updateMyAnonymousProfile(details)
95 } 82 }
96 } 83 }
97} 84}