]>
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' |
42b40636 | 5 | import { logger } from '@root-helpers/logger' |
9929fbd6 | 6 | import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' |
8f581725 | 7 | import { About, ServerConfig } from '@shared/models/server' |
43d0ea7f C |
8 | |
9 | @Component({ | |
10 | selector: 'my-instance-config-warning-modal', | |
11 | templateUrl: './instance-config-warning-modal.component.html', | |
12 | styleUrls: [ './instance-config-warning-modal.component.scss' ] | |
13 | }) | |
14 | export class InstanceConfigWarningModalComponent { | |
15 | @ViewChild('modal', { static: true }) modal: ElementRef | |
16 | ||
589d9f55 C |
17 | stopDisplayModal = false |
18 | about: About | |
19 | ||
9929fbd6 C |
20 | private LOCAL_STORAGE_KEYS = { |
21 | NO_INSTANCE_CONFIG_WARNING_MODAL: 'no_instance_config_warning_modal' | |
22 | } | |
23 | ||
43d0ea7f | 24 | constructor ( |
589d9f55 | 25 | private userService: UserService, |
9929fbd6 | 26 | private location: Location, |
43d0ea7f | 27 | private modalService: NgbModal, |
589d9f55 | 28 | private notifier: Notifier |
43d0ea7f C |
29 | ) { } |
30 | ||
8f581725 C |
31 | shouldOpenByUser (user: User) { |
32 | if (user.noInstanceConfigWarningModal === true) return false | |
33 | if (peertubeLocalStorage.getItem(this.LOCAL_STORAGE_KEYS.NO_INSTANCE_CONFIG_WARNING_MODAL) === 'true') return false | |
34 | ||
35 | return true | |
36 | } | |
37 | ||
38 | shouldOpen (serverConfig: ServerConfig, about: About) { | |
39 | if (!serverConfig.signup.allowed) return false | |
9929fbd6 | 40 | |
8f581725 C |
41 | return serverConfig.instance.name.toLowerCase() === 'peertube' || |
42 | !about.instance.terms || | |
43 | !about.instance.administrator || | |
44 | !about.instance.maintenanceLifetime | |
45 | } | |
46 | ||
47 | show (about: About) { | |
9929fbd6 C |
48 | if (this.location.path().startsWith('/admin/config/edit-custom')) return |
49 | ||
589d9f55 C |
50 | this.about = about |
51 | ||
24e7916c | 52 | const ref = this.modalService.open(this.modal, { centered: true }) |
589d9f55 C |
53 | |
54 | ref.result.finally(() => { | |
55 | if (this.stopDisplayModal === true) this.doNotOpenAgain() | |
56 | }) | |
57 | } | |
58 | ||
592c735c | 59 | isDefaultShortDescription (description: string) { |
51de2c7f | 60 | return description === 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.' |
592c735c C |
61 | } |
62 | ||
589d9f55 | 63 | private doNotOpenAgain () { |
9929fbd6 C |
64 | peertubeLocalStorage.setItem(this.LOCAL_STORAGE_KEYS.NO_INSTANCE_CONFIG_WARNING_MODAL, 'true') |
65 | ||
589d9f55 | 66 | this.userService.updateMyProfile({ noInstanceConfigWarningModal: true }) |
1378c0d3 | 67 | .subscribe({ |
42b40636 | 68 | next: () => logger.info('We will not open the instance config warning modal again.'), |
589d9f55 | 69 | |
1378c0d3 C |
70 | error: err => this.notifier.error(err.message) |
71 | }) | |
43d0ea7f C |
72 | } |
73 | } |