]>
Commit | Line | Data |
---|---|---|
5196817c | 1 | import { Component, Input, OnInit } from '@angular/core' |
a9bfa85d | 2 | import { ServerService, User, UserService } from '@app/core' |
6ebdd12f | 3 | import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' |
57d65032 | 4 | import { isP2PEnabled } from '@root-helpers/video' |
5196817c | 5 | import { HTMLServerConfig, Video } from '@shared/models' |
6ebdd12f C |
6 | |
7 | @Component({ | |
8 | selector: 'my-privacy-concerns', | |
9 | templateUrl: './privacy-concerns.component.html', | |
10 | styleUrls: [ './privacy-concerns.component.scss' ] | |
11 | }) | |
12 | export class PrivacyConcernsComponent implements OnInit { | |
13 | private static LOCAL_STORAGE_PRIVACY_CONCERN_KEY = 'video-watch-privacy-concern' | |
14 | ||
5196817c C |
15 | @Input() video: Video |
16 | ||
a9bfa85d | 17 | display = false |
6ebdd12f C |
18 | |
19 | private serverConfig: HTMLServerConfig | |
20 | ||
21 | constructor ( | |
a9bfa85d C |
22 | private serverService: ServerService, |
23 | private userService: UserService | |
6ebdd12f C |
24 | ) { } |
25 | ||
98ab5dc8 | 26 | ngOnInit () { |
6ebdd12f | 27 | this.serverConfig = this.serverService.getHTMLConfig() |
98ab5dc8 | 28 | |
a9bfa85d C |
29 | this.userService.getAnonymousOrLoggedUser() |
30 | .subscribe(user => this.updateDisplay(user)) | |
6ebdd12f C |
31 | } |
32 | ||
6ebdd12f C |
33 | acceptedPrivacyConcern () { |
34 | peertubeLocalStorage.setItem(PrivacyConcernsComponent.LOCAL_STORAGE_PRIVACY_CONCERN_KEY, 'true') | |
5196817c | 35 | |
a9bfa85d | 36 | this.display = false |
5196817c C |
37 | } |
38 | ||
a9bfa85d C |
39 | private updateDisplay (user: User) { |
40 | if (isP2PEnabled(this.video, this.serverConfig, user.p2pEnabled) && !this.alreadyAccepted()) { | |
41 | this.display = true | |
42 | } | |
5196817c C |
43 | } |
44 | ||
45 | private alreadyAccepted () { | |
46 | return peertubeLocalStorage.getItem(PrivacyConcernsComponent.LOCAL_STORAGE_PRIVACY_CONCERN_KEY) === 'true' | |
6ebdd12f C |
47 | } |
48 | } |