X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fmodal%2Finstance-config-warning-modal.component.ts;h=23c2c777e98b96c19bb23eeab1bded6a0d8160ca;hb=997a30150241b90dd833433dbc1e49b988c2b575;hp=5cc9207cd1f3dc7095cceb73d2dfb40d75d47c53;hpb=43d0ea7f4b88d52097172cc0c1831edd7e492503;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/modal/instance-config-warning-modal.component.ts b/client/src/app/modal/instance-config-warning-modal.component.ts index 5cc9207cd..23c2c777e 100644 --- a/client/src/app/modal/instance-config-warning-modal.component.ts +++ b/client/src/app/modal/instance-config-warning-modal.component.ts @@ -1,7 +1,10 @@ +import { Location } from '@angular/common' import { Component, ElementRef, ViewChild } from '@angular/core' -import { Notifier } from '@app/core' -import { I18n } from '@ngx-translate/i18n-polyfill' +import { Notifier, User, UserService } from '@app/core' import { NgbModal } from '@ng-bootstrap/ng-bootstrap' +import { logger } from '@root-helpers/logger' +import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' +import { About, ServerConfig } from '@shared/models/server' @Component({ selector: 'my-instance-config-warning-modal', @@ -11,13 +14,60 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap' export class InstanceConfigWarningModalComponent { @ViewChild('modal', { static: true }) modal: ElementRef + 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, - private i18n: I18n + private notifier: Notifier ) { } - show () { - this.modalService.open(this.modal) + 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 }) + + ref.result.finally(() => { + if (this.stopDisplayModal === true) this.doNotOpenAgain() + }) + } + + isDefaultShortDescription (description: string) { + return description === 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.' + } + + private doNotOpenAgain () { + peertubeLocalStorage.setItem(this.LOCAL_STORAGE_KEYS.NO_INSTANCE_CONFIG_WARNING_MODAL, 'true') + + this.userService.updateMyProfile({ noInstanceConfigWarningModal: true }) + .subscribe({ + next: () => logger.info('We will not open the instance config warning modal again.'), + + error: err => this.notifier.error(err.message) + }) } }