]>
Commit | Line | Data |
---|---|---|
1 | import { Component, Input, OnInit } from '@angular/core' | |
2 | import { ServerService, User, UserService } from '@app/core' | |
3 | import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' | |
4 | import { HTMLServerConfig, Video } from '@shared/models' | |
5 | import { isP2PEnabled } from '../../../../../assets/player/utils' | |
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 | ||
15 | @Input() video: Video | |
16 | ||
17 | display = false | |
18 | ||
19 | private serverConfig: HTMLServerConfig | |
20 | ||
21 | constructor ( | |
22 | private serverService: ServerService, | |
23 | private userService: UserService | |
24 | ) { } | |
25 | ||
26 | ngOnInit () { | |
27 | this.serverConfig = this.serverService.getHTMLConfig() | |
28 | ||
29 | this.userService.getAnonymousOrLoggedUser() | |
30 | .subscribe(user => this.updateDisplay(user)) | |
31 | } | |
32 | ||
33 | acceptedPrivacyConcern () { | |
34 | peertubeLocalStorage.setItem(PrivacyConcernsComponent.LOCAL_STORAGE_PRIVACY_CONCERN_KEY, 'true') | |
35 | ||
36 | this.display = false | |
37 | } | |
38 | ||
39 | private updateDisplay (user: User) { | |
40 | if (isP2PEnabled(this.video, this.serverConfig, user.p2pEnabled) && !this.alreadyAccepted()) { | |
41 | this.display = true | |
42 | } | |
43 | } | |
44 | ||
45 | private alreadyAccepted () { | |
46 | return peertubeLocalStorage.getItem(PrivacyConcernsComponent.LOCAL_STORAGE_PRIVACY_CONCERN_KEY) === 'true' | |
47 | } | |
48 | } |