+import { Location } from '@angular/common'
import { Component, ElementRef, ViewChild } from '@angular/core'
-import { Notifier, UserService } from '@app/core'
+import { Notifier, User, UserService } from '@app/core'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
-import { About } from '@shared/models/server'
+import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
+import { About, ServerConfig } from '@shared/models/server'
@Component({
selector: 'my-instance-config-warning-modal',
stopDisplayModal = false
about: About
+ private LOCAL_STORAGE_KEYS = {
+ NO_INSTANCE_CONFIG_WARNING_MODAL: 'no_instance_config_warning_modal'
+ }
+
constructor (
private userService: UserService,
+ private location: Location,
private modalService: NgbModal,
private notifier: Notifier
) { }
+ shouldOpenByUser (user: User) {
+ if (user.noInstanceConfigWarningModal === true) return false
+ if (peertubeLocalStorage.getItem(this.LOCAL_STORAGE_KEYS.NO_INSTANCE_CONFIG_WARNING_MODAL) === 'true') return false
+
+ return true
+ }
+
+ shouldOpen (serverConfig: ServerConfig, about: About) {
+ if (!serverConfig.signup.allowed) return false
+
+ return serverConfig.instance.name.toLowerCase() === 'peertube' ||
+ !about.instance.terms ||
+ !about.instance.administrator ||
+ !about.instance.maintenanceLifetime
+ }
+
show (about: About) {
+ if (this.location.path().startsWith('/admin/config/edit-custom')) return
+
this.about = about
const ref = this.modalService.open(this.modal, { centered: true })
}
private doNotOpenAgain () {
+ peertubeLocalStorage.setItem(this.LOCAL_STORAGE_KEYS.NO_INSTANCE_CONFIG_WARNING_MODAL, 'true')
+
this.userService.updateMyProfile({ noInstanceConfigWarningModal: true })
- .subscribe(
- () => console.log('We will not open the instance config warning modal again.'),
+ .subscribe({
+ next: () => console.log('We will not open the instance config warning modal again.'),
- err => this.notifier.error(err.message)
- )
+ error: err => this.notifier.error(err.message)
+ })
}
}