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'
9 selector: 'my-instance-config-warning-modal',
10 templateUrl: './instance-config-warning-modal.component.html',
11 styleUrls: [ './instance-config-warning-modal.component.scss' ]
13 export class InstanceConfigWarningModalComponent {
14 @ViewChild('modal', { static: true }) modal: ElementRef
16 stopDisplayModal = false
19 private LOCAL_STORAGE_KEYS = {
20 NO_INSTANCE_CONFIG_WARNING_MODAL: 'no_instance_config_warning_modal'
24 private userService: UserService,
25 private location: Location,
26 private modalService: NgbModal,
27 private notifier: Notifier
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
37 shouldOpen (serverConfig: ServerConfig, about: About) {
38 if (!serverConfig.signup.allowed) return false
40 return serverConfig.instance.name.toLowerCase() === 'peertube' ||
41 !about.instance.terms ||
42 !about.instance.administrator ||
43 !about.instance.maintenanceLifetime
47 if (this.location.path().startsWith('/admin/config/edit-custom')) return
51 const ref = this.modalService.open(this.modal, { centered: true })
53 ref.result.finally(() => {
54 if (this.stopDisplayModal === true) this.doNotOpenAgain()
58 isDefaultShortDescription (description: string) {
59 return description === 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.'
62 private doNotOpenAgain () {
63 peertubeLocalStorage.setItem(this.LOCAL_STORAGE_KEYS.NO_INSTANCE_CONFIG_WARNING_MODAL, 'true')
65 this.userService.updateMyProfile({ noInstanceConfigWarningModal: true })
67 next: () => console.log('We will not open the instance config warning modal again.'),
69 error: err => this.notifier.error(err.message)