]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/modal/instance-config-warning-modal.component.ts
Merge branch 'release/4.2.0' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / modal / instance-config-warning-modal.component.ts
1 import { Location } from '@angular/common'
2 import { Component, ElementRef, ViewChild } from '@angular/core'
3 import { Notifier, User, UserService } from '@app/core'
4 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
5 import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
6 import { About, ServerConfig } from '@shared/models/server'
7
8 @Component({
9 selector: 'my-instance-config-warning-modal',
10 templateUrl: './instance-config-warning-modal.component.html',
11 styleUrls: [ './instance-config-warning-modal.component.scss' ]
12 })
13 export class InstanceConfigWarningModalComponent {
14 @ViewChild('modal', { static: true }) modal: ElementRef
15
16 stopDisplayModal = false
17 about: About
18
19 private LOCAL_STORAGE_KEYS = {
20 NO_INSTANCE_CONFIG_WARNING_MODAL: 'no_instance_config_warning_modal'
21 }
22
23 constructor (
24 private userService: UserService,
25 private location: Location,
26 private modalService: NgbModal,
27 private notifier: Notifier
28 ) { }
29
30 shouldOpenByUser (user: User) {
31 if (user.noInstanceConfigWarningModal === true) return false
32 if (peertubeLocalStorage.getItem(this.LOCAL_STORAGE_KEYS.NO_INSTANCE_CONFIG_WARNING_MODAL) === 'true') return false
33
34 return true
35 }
36
37 shouldOpen (serverConfig: ServerConfig, about: About) {
38 if (!serverConfig.signup.allowed) return false
39
40 return serverConfig.instance.name.toLowerCase() === 'peertube' ||
41 !about.instance.terms ||
42 !about.instance.administrator ||
43 !about.instance.maintenanceLifetime
44 }
45
46 show (about: About) {
47 if (this.location.path().startsWith('/admin/config/edit-custom')) return
48
49 this.about = about
50
51 const ref = this.modalService.open(this.modal, { centered: true })
52
53 ref.result.finally(() => {
54 if (this.stopDisplayModal === true) this.doNotOpenAgain()
55 })
56 }
57
58 isDefaultShortDescription (description: string) {
59 return description === 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.'
60 }
61
62 private doNotOpenAgain () {
63 peertubeLocalStorage.setItem(this.LOCAL_STORAGE_KEYS.NO_INSTANCE_CONFIG_WARNING_MODAL, 'true')
64
65 this.userService.updateMyProfile({ noInstanceConfigWarningModal: true })
66 .subscribe({
67 next: () => console.log('We will not open the instance config warning modal again.'),
68
69 error: err => this.notifier.error(err.message)
70 })
71 }
72 }