]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/modal/instance-config-warning-modal.component.ts
Added filter to sort videos by name (alphabetical order)
[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 { logger } from '@root-helpers/logger'
6 import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
7 import { About, ServerConfig } from '@shared/models/server'
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
17 stopDisplayModal = false
18 about: About
19
20 private LOCAL_STORAGE_KEYS = {
21 NO_INSTANCE_CONFIG_WARNING_MODAL: 'no_instance_config_warning_modal'
22 }
23
24 constructor (
25 private userService: UserService,
26 private location: Location,
27 private modalService: NgbModal,
28 private notifier: Notifier
29 ) { }
30
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
40
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) {
48 if (this.location.path().startsWith('/admin/config/edit-custom')) return
49
50 this.about = about
51
52 const ref = this.modalService.open(this.modal, { centered: true })
53
54 ref.result.finally(() => {
55 if (this.stopDisplayModal === true) this.doNotOpenAgain()
56 })
57 }
58
59 isDefaultShortDescription (description: string) {
60 return description === 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.'
61 }
62
63 private doNotOpenAgain () {
64 peertubeLocalStorage.setItem(this.LOCAL_STORAGE_KEYS.NO_INSTANCE_CONFIG_WARNING_MODAL, 'true')
65
66 this.userService.updateMyProfile({ noInstanceConfigWarningModal: true })
67 .subscribe({
68 next: () => logger.info('We will not open the instance config warning modal again.'),
69
70 error: err => this.notifier.error(err.message)
71 })
72 }
73 }