]>
Commit | Line | Data |
---|---|---|
9929fbd6 | 1 | import { Location } from '@angular/common' |
43d0ea7f | 2 | import { Component, ElementRef, ViewChild } from '@angular/core' |
8f581725 | 3 | import { Notifier, User, UserService } from '@app/core' |
43d0ea7f | 4 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' |
9929fbd6 | 5 | import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' |
8f581725 | 6 | import { About, ServerConfig } from '@shared/models/server' |
43d0ea7f C |
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 | ||
589d9f55 C |
16 | stopDisplayModal = false |
17 | about: About | |
18 | ||
9929fbd6 C |
19 | private LOCAL_STORAGE_KEYS = { |
20 | NO_INSTANCE_CONFIG_WARNING_MODAL: 'no_instance_config_warning_modal' | |
21 | } | |
22 | ||
43d0ea7f | 23 | constructor ( |
589d9f55 | 24 | private userService: UserService, |
9929fbd6 | 25 | private location: Location, |
43d0ea7f | 26 | private modalService: NgbModal, |
589d9f55 | 27 | private notifier: Notifier |
43d0ea7f C |
28 | ) { } |
29 | ||
8f581725 C |
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 | |
9929fbd6 | 39 | |
8f581725 C |
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) { | |
9929fbd6 C |
47 | if (this.location.path().startsWith('/admin/config/edit-custom')) return |
48 | ||
589d9f55 C |
49 | this.about = about |
50 | ||
24e7916c | 51 | const ref = this.modalService.open(this.modal, { centered: true }) |
589d9f55 C |
52 | |
53 | ref.result.finally(() => { | |
54 | if (this.stopDisplayModal === true) this.doNotOpenAgain() | |
55 | }) | |
56 | } | |
57 | ||
592c735c | 58 | isDefaultShortDescription (description: string) { |
51de2c7f | 59 | return description === 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.' |
592c735c C |
60 | } |
61 | ||
589d9f55 | 62 | private doNotOpenAgain () { |
9929fbd6 C |
63 | peertubeLocalStorage.setItem(this.LOCAL_STORAGE_KEYS.NO_INSTANCE_CONFIG_WARNING_MODAL, 'true') |
64 | ||
589d9f55 | 65 | this.userService.updateMyProfile({ noInstanceConfigWarningModal: true }) |
1378c0d3 C |
66 | .subscribe({ |
67 | next: () => console.log('We will not open the instance config warning modal again.'), | |
589d9f55 | 68 | |
1378c0d3 C |
69 | error: err => this.notifier.error(err.message) |
70 | }) | |
43d0ea7f C |
71 | } |
72 | } |