1 import { Component, ElementRef, ViewChild } from '@angular/core'
2 import { Notifier, ServerService, User, UserService } from '@app/core'
3 import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
4 import { logger } from '@root-helpers/logger'
5 import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
8 selector: 'my-account-setup-warning-modal',
9 templateUrl: './account-setup-warning-modal.component.html',
10 styleUrls: [ './account-setup-warning-modal.component.scss' ]
12 export class AccountSetupWarningModalComponent {
13 @ViewChild('modal', { static: true }) modal: ElementRef
15 stopDisplayModal = false
20 private LOCAL_STORAGE_KEYS = {
21 NO_ACCOUNT_SETUP_WARNING_MODAL: 'no_account_setup_warning_modal'
25 private userService: UserService,
26 private modalService: NgbModal,
27 private notifier: Notifier,
28 private serverService: ServerService
32 return this.serverService.getHTMLConfig().instance.name
35 hasAccountAvatar (user: User) {
36 return user.account.avatars.length !== 0
39 hasAccountDescription (user: User) {
40 return !!user.account.description
43 shouldOpen (user: User) {
44 if (user.noAccountSetupWarningModal === true) return false
45 if (peertubeLocalStorage.getItem(this.LOCAL_STORAGE_KEYS.NO_ACCOUNT_SETUP_WARNING_MODAL) === 'true') return false
47 if (this.hasAccountAvatar(user) && this.hasAccountDescription(user)) return false
48 if (this.userService.hasSignupInThisSession()) return false
58 this.ref = this.modalService.open(this.modal, {
65 this.ref.result.finally(() => {
66 if (this.stopDisplayModal === true) this.doNotOpenAgain()
70 private doNotOpenAgain () {
71 peertubeLocalStorage.setItem(this.LOCAL_STORAGE_KEYS.NO_ACCOUNT_SETUP_WARNING_MODAL, 'true')
73 this.userService.updateMyProfile({ noAccountSetupWarningModal: true })
75 next: () => logger.info('We will not open the account setup modal again.'),
77 error: err => this.notifier.error(err.message)